9

I want to draw two automaton figures next to each other; however I can't put them in one \begin{} \end{} tag because the node distance can be changed, further the distance between two pictures is also different. A minimal example would be greatly appreciated. Thank you.

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
    \node[state,initial]    (q_0)                   {$q_0$}; 
    \node[state,accepting]  (q_1)   [right=of q_0]  {$q_1$}; 
    \node[state]            (q_2)   [right=of q_1]  {$q_2$}; 

    \path[->]
    (q_0) edge                  node {a}            (q_1)
    (q_1) edge                  node {$\lambda$}    (q_2)
    (q_2) edge  [bend right]    node {$\lambda$}    (q_0)
    ; %end path 
\end{tikzpicture}

3 Answers 3

11

If the two pictures can stay on one line, it's nothing more than

\begin{tikzpicture}
<code for the first picture>
\end{tikzpicture}
\begin{tikzpicture}
<code for the second picture>
\end{tikzpicture}

They will be aligned at their bottom.

2
  • Thank you for your solution. However I found another solution for this particular problem in the TikZ manual. They used \scope nested inside the \begin{tikzpicture} texample.net/tikz/examples/nodetutorial
    – roxrook
    Jul 24, 2011 at 20:31
  • 2
    @Chan Yes but in this case, you don't draw two tkizpictures but only one. The rule that everyone should know is that the result of an environment tikzpicture is a box whose height is the height of the box and the depth is null. This is why we can align the boxes at their bottom. It is possible to change the depth of this box with the option baseline. Then it is easy to align boxes. Jun 18, 2012 at 15:26
9

You could use a minipage:

\noindent
\begin{minipage}{.5\textwidth}
\centering
\begin{tikzpicture}
     <code for the first picture>
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\begin{tikzpicture}
<code for the second picture>
\end{tikzpicture}
\end{minipage}

Or else a subfloat (using the subfig package):

\begin{figure}
\subfloat[first caption here]
{
\begin{tikzpicture}
     <code for the first picture>
\end{tikzpicture}
}
\subfloat[second caption here]
{
\begin{tikzpicture}
     <code for the second picture>
\end{tikzpicture}
}
\end{figure}
2
  • You can just type 0.5\textwidth. Jul 24, 2011 at 21:28
  • I've added some code without which the result would not have worked.
    – egreg
    Jul 24, 2011 at 21:30
5

This is my solution based on the following example from TikZ tutorial http://www.texample.net/tikz/examples/nodetutorial/

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
    \begin{scope}
        \node[state,initial]    (q_1)                           {$q_1$}; 
        \node[state,accepting]  (q_2)   [right=of q_1]          {$q_2$}; 
        \node[state]            (q_3)   [below right=of q_1]    {$q_3$}; 

        \path[->]
        (q_1) edge  [bend left]     node {a}            (q_2)
        (q_1) edge  [loop above]    node {b}            (q_1)
        (q_2) edge  [bend left]     node {a,b}          (q_3)
        (q_3) edge  [bend left]     node {a}            (q_2)
        (q_3) edge  [bend left]     node {b}            (q_1)
        ;
    \end{scope}

    \begin{scope}[xshift=10cm]
        \node[state,initial]    (q_1)                           {$q_1$}; 
        \node[state,accepting]  (q_2)   [right=of q_1]          {$q_2$}; 
        \node[state]            (q_3)   [below right=of q_1]    {$q_3$}; 

        \path[->]
        (q_1) edge  [bend left]     node {a}            (q_2)
        (q_1) edge  [loop above]    node {b}            (q_1)
        (q_2) edge  [bend left]     node {a,b}          (q_3)
        (q_3) edge  [bend left]     node {a}            (q_2)
        (q_3) edge  [bend left]     node {b}            (q_1)
        ;
    \end{scope}
\end{tikzpicture}
4
  • 3
    Doesn't your question explicitly state that you don't want this kind of solution?
    – Caramdir
    Jul 24, 2011 at 21:27
  • @Caramdir: The distance between two pictures is xshift which is different than the node distance so this is what I wanted. Did I misunderstand you somewhere?
    – roxrook
    Jul 24, 2011 at 21:32
  • No, I (and seemingly the other people who answered) misinterpreted your question. Without the second part of your first sentence (which is rather confusing) the scope/shift solution would have been given sooner.
    – Caramdir
    Jul 24, 2011 at 21:37
  • 1
    Then, I really apologize for misinterpret my question because my initial thought was influenced by the node distance parameter.
    – roxrook
    Jul 24, 2011 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.