Skip to content

Instantly share code, notes, and snippets.

@tetsuok
Last active December 15, 2015 12:29
Show Gist options
  • Select an option

  • Save tetsuok/5260899 to your computer and use it in GitHub Desktop.

Select an option

Save tetsuok/5260899 to your computer and use it in GitHub Desktop.
Macros for drawing charts in NLP
% Copyright (c) 2013, Tetsuo Kiso. All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
%
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in the
% documentation and/or other materials provided with the distribution.
%
% * Neither the name of Tetsuo Kiso nor the names of its contributors
% may be used to endorse or promote products derived from this software
% without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
% A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
% OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
% LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
% DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
% THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\documentclass{beamer}
\usepackage{palatino}
\usefonttheme{structurebold}
\setbeamertemplate{navigation symbols}{}
\usepackage{ifthen}
\usepackage{calc}
\usepackage{tikz}
\newcounter{myrangex}
\def\internalinitchart#1#2{
\foreach \x in {0, ..., #1} {
\coordinate [label=below:\x] (\x) at (\x * 2,0);
}
\foreach \x in {0, ..., #2} {
\draw (\x, \x + 1) -- (2 * \x + 1, 0);
\draw (#1 + 1 + \x, #1 - \x) -- (2 * \x + 1, 0);
}
\draw (#1, #1+1) -- (2 * #1, 1);
\draw (#1, #1+1) -- (0, 1);
}
\def\drawchart#1{
\setcounter{myrangex}{#1-1}
\internalinitchart{#1}{\themyrangex}
}
\def\chartcoordinate#1#2{
\node at (#1+#2, #2-#1) {#1,#2};
}
\def\chartentry#1#2#3{
\node at (#1+#2, #2-#1) {\small #3};
}
\def\fillchartcell#1#2{
\filldraw [green!60, draw=black] (#1+#2-1, #2-#1) -- (#1+#2, #2-#1 + 1) -- (#1 + #2 + 1, #2-#1) -- (#1+#2, #2-#1-1) -- (#1 + #2 - 1, #2-#1);
% \node [rectangle,fill=red!50, draw=black,rotate=45, inner sep=20pt] at (#1+#2, #2-#1) {};
}
\title{Macros for Drawing Charts in \\Natural Language Processing}
\author{Tetsuo Kiso}
\date{\today}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}[fragile]{Basics}
\begin{verbatim*}
\drawchart{5};
\end{verbatim*}
\begin{tikzpicture}
\drawchart{5};
\end{tikzpicture}
\end{frame}
\begin{frame}[fragile]{Bigger Charts}
\begin{verbatim*}
\drawchart{30};
\end{verbatim*}
\begin{center}
\begin{tikzpicture}[scale=0.15]
\drawchart{30};
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[fragile]{Specifying coordinates}
\begin{verbatim*}
\chartcoordinate{0}{5};
\end{verbatim*}%
\begin{tikzpicture}
\drawchart{5};
\foreach \x in {0, ..., 5} {
\foreach \y in {1, ..., 5} {
\ifthenelse{\x < \y}{
\chartcoordinate{\x}{\y};
}
}
}
\end{tikzpicture}
\end{frame}
\begin{frame}[fragile]{Filling chart cells}
\begin{verbatim*}
\chartcoordinate{0}{5};
\end{verbatim*}
\begin{tikzpicture}
\drawchart{5};
\fillchartcell{0}{5};
\chartcoordinate{0}{5};
\end{tikzpicture}
\end{frame}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment