4

I have the following code for a generating a diagram. How do I make the resulting PDF as large as the figure only like IPE does?

\documentclass[landscape]{article}
\usepackage{standalone}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage{graphicx}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}

\begin{document}

\begin{figure}
\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=3 cm,scale=1,transform shape,line width=0.25mm]  
\node[initial,state,fill=green!20,initial text={},line width=0.25mm] (A)    {$q_{000}$};
\node[state,accepting,fill=red!20,line width=0.25mm]         (B) [right of=A]     {$q_{100}$};
\node[state,fill=blue!20,line width=0.25mm]         (C) [right of=B]   {$q_{010}$};
\node[state,accepting,fill=red!20,line width=0.25mm]         (D) [right of=C]   {$q_{110}$};

\node[state,fill=blue!20,line width=0.25mm]   (E) [below of=A]    {$q_{001}$};
\node[state,accepting,fill=red!20,line width=0.25mm]   (F) [right of=E]  {$q_{101}$};
\node[state,fill=blue!20,line width=0.25mm]         (G) [right of=F]     {$q_{011}$};
\node[state,accepting,fill=red!20,line width=0.25mm]    (H) [right of=G]   {$q_{111}$};

\path[->,black] (A) edge [loop above]   node [align=center]  {$ 0$} (A)
(B) edge [above] node [align=center] {$0$} (A)
(C) edge [above] node [align=center] {$0$} (B)
(D) edge [ above, bend right ] node [align=center] {$0$} (B)

(A) edge [ left ] node [align=center] {$1$} (E)
(B) edge [ above ] node [align=center,xshift=-5] {$1$} (E)
(E) edge [ bend left = 6, above ] node [align=center] {$0$} (C)

(C) edge [ bend right = 10, above] node [align=center,xshift=-8,yshift=-5] {$1$} (F)
(F) edge [ bend right = 10, below ] node [align=center,xshift=8,yshift=5] {$0$} (C)

(F) edge [  ] node [align=center] {$1$} (G)
(G) edge [  ] node [align=center] {$1$} (H)
(H) edge [loop right]   node [align=center]  {$ 1$} (H)
(H) edge [ right ] node [align=center] {$0$} (D)
(G) edge [ below ] node [align=center,xshift=5] {$0$} (D)
(D) edge [ bend left = 5,above] node [align=center,yshift=3] {$1$} (F)
(E) edge [ below, bend right  ] node [align=center] {$1$} (G);
\end{tikzpicture}
\end{figure}

\end{document}

Updated working code. Thanks for the help!

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}

\begin{document}

\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=3 cm,scale=1,transform shape,line width=0.25mm]  
\node[initial,state,fill=green!20,initial text={},line width=0.25mm] (A)    {$q_{000}$};
\node[state,accepting,fill=red!20,line width=0.25mm]         (B) [right of=A]     {$q_{100}$};
\node[state,fill=blue!20,line width=0.25mm]         (C) [right of=B]   {$q_{010}$};
\node[state,accepting,fill=red!20,line width=0.25mm]         (D) [right of=C]   {$q_{110}$};

\node[state,fill=blue!20,line width=0.25mm]   (E) [below of=A]    {$q_{001}$};
\node[state,accepting,fill=red!20,line width=0.25mm]   (F) [right of=E]  {$q_{101}$};
\node[state,fill=blue!20,line width=0.25mm]         (G) [right of=F]     {$q_{011}$};
\node[state,accepting,fill=red!20,line width=0.25mm]    (H) [right of=G]   {$q_{111}$};

\path[->,black] (A) edge [loop above]   node [align=center]  {$ 0$} (A)
(B) edge [above] node [align=center] {$0$} (A)
(C) edge [above] node [align=center] {$0$} (B)
(D) edge [ above, bend right ] node [align=center] {$0$} (B)

(A) edge [ left ] node [align=center] {$1$} (E)
(B) edge [ above ] node [align=center,xshift=-5] {$1$} (E)
(E) edge [ bend left = 6, above ] node [align=center] {$0$} (C)

(C) edge [ bend right = 10, above] node [align=center,xshift=-8,yshift=-5] {$1$} (F)
(F) edge [ bend right = 10, below ] node [align=center,xshift=8,yshift=5] {$0$} (C)

(F) edge [  ] node [align=center] {$1$} (G)
(G) edge [  ] node [align=center] {$1$} (H)
(H) edge [loop right]   node [align=center]  {$ 1$} (H)
(H) edge [ right ] node [align=center] {$0$} (D)
(G) edge [ below ] node [align=center,xshift=5] {$0$} (D)
(D) edge [ bend left = 5,above] node [align=center,yshift=3] {$1$} (F)
(E) edge [ below, bend right  ] node [align=center] {$1$} (G);
\end{tikzpicture}

\end{document}
aghost
  • 155

1 Answers1

4

Remove the figure environment, remove \usepackage{standalone} and change to \documentclass{standalone}.

Unrelated comments.

  • Note that while it still works, the arrows library is considered deprecated in favor of arrows.meta. This does have a different syntax though, see the manual.

  • Using the of= syntax is deprecated in favor of loading the positioning library and saying =of, see Difference between "right of=" and "right=of" in PGF/TikZ

  • \usepackage{tikz} will also load pgf (unsurprisingly) and also graphicx, so loading the latter two packages is redundant. You're not using the features of any of the ams packages in this figure, so they can be removed as well.

  • All the align=center doesn't really do anything in this case.

  • Personally I would use e.g. above left instead of xshift and/or yshift.

  • For cases where you have many elements with the same options, adding a style makes things both neater and easier to change.

Complete code

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,automata,positioning}
\begin{document}
\begin{tikzpicture}[
   >={Stealth[round]},shorten >=1pt,
   auto,node distance=2.5cm,
   transform shape,line width=0.25mm,
   StartNode/.style={initial,state,fill=green!20,initial text={},line width=0.25mm},
   TheRedOnes/.style={state,accepting,fill=red!20,line width=0.25mm},
   TheBlueOnes/.style={state,fill=blue!20,line width=0.25mm}
   ]  
\node[StartNode]   (A)                {$q_{000}$};
\node[TheRedOnes]  (B) [right=of A]   {$q_{100}$};
\node[TheBlueOnes] (C) [right=of B]   {$q_{010}$};
\node[TheRedOnes]  (D) [right=of C]   {$q_{110}$};

\node[TheBlueOnes] (E) [below=of A] {$q_{001}$}; \node[TheRedOnes] (F) [right=of E] {$q_{101}$}; \node[TheBlueOnes] (G) [right=of F] {$q_{011}$}; \node[TheRedOnes] (H) [right=of G] {$q_{111}$};

\path[->,black] (A) edge [loop above] node {$ 0$} (A) (B) edge [above] node {$0$} (A) (C) edge [above] node {$0$} (B) (D) edge [ above, bend right ] node {$0$} (B)

(A) edge node [left] {$1$} (E) (B) edge node [above left] {$1$} (E) (E) edge [ bend left = 6 ] node [above] {$0$} (C)

(C) edge [ bend right = 10] node [left=3pt] {$1$} (F) (F) edge [ bend right = 10] node [right=3pt] {$0$} (C)

(F) edge node {$1$} (G) (G) edge node {$1$} (H) (H) edge [loop right] node {$ 1$} (H) (H) edge node [ right ] {$0$} (D) (G) edge node [below right] {$0$} (D) (D) edge [ bend left = 5 ] node [above] {$1$} (F) (E) edge [ bend right ] node [below] {$1$} (G); \end{tikzpicture} \end{document}

Torbjørn T.
  • 206,688
  • Can also drop pgf, graphicx and probably some more as they are loaded anyway. – cfr Oct 27 '15 at 22:34
  • @cfr Didn't think about graphicx, but good point. Am editing my answer at the moment, so will include that. – Torbjørn T. Oct 27 '15 at 22:35
  • Thank you. Just a had trouble to install it in Ubuntu 15.04. :) Finally succeeded by extracting the ZIP file into texmf directory in the home folder.

    ZIP file URL: https://www.ctan.org/pkg/standalone?lang=en

    – aghost Oct 27 '15 at 22:47
  • @AnirbanGhosh If you have the standalone package you should have the standalone class as well, they are part of the same bundle. – Torbjørn T. Oct 27 '15 at 22:52
  • 1
    @AnirbanGhosh As you can see I added a suggestion for changes to the code in my answer. – Torbjørn T. Oct 27 '15 at 22:55
  • @Torbjørn T. Strangely it is not working in my system. I do not know why. If use standalone in documentclass, compilation fails. – aghost Oct 27 '15 at 23:25