I'm looking for a LaTeX package which helps drawing automata problems. I googled and found A package for drawing automata and graphs (Version 0.4). But I'm not sure is this package a standard one, or there are some better alternatives. Any suggestion?
[Tex/LaTex] Which package can be used to draw automata
automatadiagramspackages
Related Solutions
Personally, I favour algpseudocode
from the algorithmicx
(note the trailing x
!) package. With a bit of setup, this can be harnessed to create beautiful pseudocode.
This was produced by the following code:
\begin{algorithm}
\caption{Counting mismatches between two packed \DNA{} strings
\label{alg:packed-dna-hamming}}
\begin{algorithmic}[1]
\Require{$x$ and $y$ are packed \DNA{} strings of equal length $n$}
\Statex
\Function{Distance}{$x, y$}
\Let{$z$}{$x \oplus y$} \Comment{$\oplus$: bitwise exclusive-or}
\Let{$\delta$}{$0$}
\For{$i \gets 1 \textrm{ to } n$}
\If{$z_i \neq 0$}
\Let{$\delta$}{$\delta + 1$}
\EndIf
\EndFor
\State \Return{$\delta$}
\EndFunction
\end{algorithmic}
\end{algorithm}
And used the following setup (this is just an example to replicate the above; you can of course use your own setup):
\usepackage{fontspec}
\setmainfont{Hoefler Text}
\newcommand*\DNA{\textsc{dna}}
\newcommand*\Let[2]{\State #1 $\gets$ #2}
\algrenewcommand\alglinenumber[1]{
{\sf\footnotesize\addfontfeatures{Colour=888888,Numbers=Monospaced}#1}}
\algrenewcommand\algorithmicrequire{\textbf{Precondition:}}
\algrenewcommand\algorithmicensure{\textbf{Postcondition:}}
To get the end
-less pseudocodes, I included the package as follows:
\usepackage[noend]{algpseudocode}
The above pseudo code is nested inside an algorithm
float environment. This environment isn’t part of algorithmicx
. Instead, you need to load the package algorithm
to get it. To produce a list of all algorithms, you can use
\listofalgorithms
For further information, see the section “The algorithm
Environment” in the documentation of the algorithms
package. But I want to stress again that (except for the float environment) the algorithmicx
package is superior to algorithms
.
You can draw such diagrams with TikZ (tikz
package plus libraries) or PS-Tricks (pstricks
and other pst-
packages). I personally would recommend TikZ.
Here is how I would draw these diagrams:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\sffamily
\textbf{Circular buffer:}
\begin{tikzpicture}[>=latex,font=\sffamily,semithick,scale=1.75]
\fill [green!25] (0,0) -- (67.5:1) arc [end angle=-22.5, start angle=67.5, radius=1] -- cycle;
\draw [thick] (0,0) circle (1);
\foreach \angle in {90,67.5,...,-67.5}
\draw (\angle:1) -- (\angle-180:1);
\node [circle,thick,fill=white,draw=black,align=center,minimum size=3cm] at (0,0) {FIFO as a\\Circulate Buffer};
\draw [<-] (56.25:1) -- (56.25:1.25) -- +(.333,0)
node [right,inner xsep=.333cm] (Head) {Head (extract)};
\draw [<-] (-33.75:1) -- (-33.75:1.25) -- +(.333,0)
node [right,inner xsep=.333cm] (Tail) {Tail (insert)};
\draw [->,shorten >=5pt,shorten <=5pt] (Tail.west) to [bend right]
node [midway,sloped,above,allow upside down] {\footnotesize 4\,bytes in FIFO}
(Head.west);
\end{tikzpicture}
\bigskip
\bigskip
\textbf{Linear buffer:}
\par
\bigskip
\begin{tikzpicture}[>=latex,font=\sffamily,every node/.style={minimum width=1cm,minimum height=1.5em,outer sep=0pt,draw=black,fill=blue!40,semithick}]
\node at (0,0) (A) {};
\node [anchor=west] at (A.east) (B) {};
\node [anchor=west] at (B.east) (C) {1};
\node [anchor=west] at (C.east) (D) {2};
\node [anchor=west] at (D.east) (E) {3};
\node [anchor=west] at (E.east) (F) {};
\node [anchor=west] at (F.east) (G) {};
\draw [->,shorten >=2pt,shorten <=2pt,semithick] (G.south) -- +(0,-1em) -| (A);
\end{tikzpicture}
\end{document}
Best Answer
TiKZ has a whole library for drawing automata: