1

I have three trees in latex , I have this construction :

enter image description here

with his code :

\documentclass[openright,a4paper,11pt,french]{report}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[shorten >=1pt, node distance=2cm, on grid, auto,thick,initial text=]
   \node[state, initial,minimum size=3ex]            (0)                          {0};
   \node[state,minimum size=3ex]                     (1)   [above right =of 0]    {1};
   \node[state,minimum size=3ex]                     (2)   [right =of 0]          {2};
   \node[state,accepting,minimum size=3ex]           (3)   [right =of 2]          {3/0};



  \path[->]      (0)  edge         node           {a:a / 1.61}   (1)
                 (0)  edge        node           {b:b/ 0.22}   (2)
                  (1)  edge       node           {a:b/ 0}   (2)
                 (2)  edge [loop below]  node         {b:a/ 0.69}   ()
                 (2)  edge               node           {b:a/ 0.69}   (3);

\end{tikzpicture}   

\begin{tikzpicture}[shorten >=1pt, node distance=2cm, on grid, auto,thick,initial text=,minimum size=0pt]
   \node[state, initial ,minimum size=3ex]            (0)                          {0};
   \node[state,minimum size=3ex]                     (1)   [right =of 0]          {1};
   \node[state,accepting,minimum size=3ex]           (2)   [right =of 1]          {2/0};




  \path[->]      (0)  edge     [loop above]   node           {a:a / 1.2}   ()
                 (0)  edge      [bend left]   node           {a:b/ 2.3}   (1)
                 (0)  edge      [bend right]   node           {b:a/ 0.51}   (1)
                 (1)  edge      [loop below]  node         {b:b/ 0.92}   ()
                 (1)  edge                    node           {a:a/ 0.51}   (2);

\end{tikzpicture}  


\begin{tikzpicture}[shorten >=1pt, node distance=2cm, on grid, auto,thick,initial text=,minimum size=0pt]
   \node[state, initial,minimum size=3ex]            (0)                          {0};
   \node[state,minimum size=3ex]                     (1)   [above right =of 0]    {1};
   \node[state,minimum size=3ex]                     (2)   [right =of 0]          {4};
   \node[state,minimum size=3ex]                     (3)   [right =of 2]          {2};
   \node[state,minimum size=3ex,accepting]           (4)   [right =of 3]          {3/0};


\begin{scope}[every node/.style={scale=.7}]
  \path[->]      (0)  edge        node           {a:a / 2.81}   (1)
                 (0)  edge        node           {a:b / 3.91}   (2)
                 (0)  edge     [bend right]   node           {b:a / 0.73}   (3)
                (1)  edge        node           {a:a / 0.51}   (3)
                (2)  edge        node           {a:b / 0.92}   (3)
                (3)  edge       node          {b:a / 1.2}   (4);


  \end{scope}


\end{tikzpicture}   

\end{document}

but I want to represent 2 like this and the third before?

enter image description here

lockstep
  • 250,273
Chouria Ali
  • 1,303

2 Answers2

1

The result of tikzpicture environment is a box. You can use something like \vbox,\hboxor something in the spirit of LaTeX : minipage

\documentclass[openright,a4paper,11pt,french]{report}
\usepackage{tikz}
\usetikzlibrary{positioning,automata}
\begin{document}

\begin{minipage}{7cm}
    \begin{tikzpicture}[shorten >=1pt, node distance=2cm, on grid, auto,thick,initial text=]
       \node[state, initial,minimum size=3ex]            (0)                          {0};
       \node[state,minimum size=3ex]                     (1)   [above right =of 0]    {1};
       \node[state,minimum size=3ex]                     (2)   [right =of 0]          {2};
       \node[state,accepting,minimum size=3ex]           (3)   [right =of 2]          {3/0};

      \path[->]      (0)  edge               node           {a:a / 1.61}   (1)
                     (0)  edge               node           {b:b/ 0.22}   (2)
                     (1)  edge               node           {a:b/ 0}   (2)
                     (2)  edge [loop below]  node         {b:a/ 0.69}   ()
                     (2)  edge               node           {b:a/ 0.69}   (3);

    \end{tikzpicture}   

    \begin{tikzpicture}[shorten >=1pt, node distance=2cm, on grid, auto,thick,initial text=,minimum size=0pt]
       \node[state, initial ,minimum size=3ex]            (0)                          {0};
       \node[state,minimum size=3ex]                     (1)   [right =of 0]          {1};
       \node[state,accepting,minimum size=3ex]           (2)   [right =of 1]          {2/0};

      \path[->]      (0)  edge      [loop above]   node           {a:a / 1.2}   ()
                     (0)  edge      [bend left]    node           {a:b/ 2.3}   (1)
                     (0)  edge      [bend right]   node           {b:a/ 0.51}   (1)
                     (1)  edge      [loop below]   node         {b:b/ 0.92}   ()
                     (1)  edge                     node           {a:a/ 0.51}   (2);

    \end{tikzpicture}
\end{minipage}
\begin{minipage}{7cm}
    \begin{tikzpicture}[shorten >=1pt, node distance=2cm, on grid, auto,thick,initial text=,minimum size=0pt]
       \node[state, initial,minimum size=3ex]            (0)                          {0};
       \node[state,minimum size=3ex]                     (1)   [above right =of 0]    {1};
       \node[state,minimum size=3ex]                     (2)   [right =of 0]          {4};
       \node[state,minimum size=3ex]                     (3)   [right =of 2]          {2};
       \node[state,minimum size=3ex,accepting]           (4)   [right =of 3]          {3/0};

    \begin{scope}[every node/.style={scale=.7}]
      \path[->]      (0)  edge        node           {a:a / 2.81}   (1)
                     (0)  edge        node           {a:b / 3.91}   (2)
                     (0)  edge     [bend right]   node           {b:a / 0.73}   (3)
                     (1)  edge        node           {a:a / 0.51}   (3)
                     (2)  edge        node           {a:b / 0.92}   (3)
                     (3)  edge        node          {b:a / 1.2}   (4);


      \end{scope}
    \end{tikzpicture}
\end{minipage}
\end{document}    

enter image description here

Alain Matthes
  • 95,075
1

If your question is just about positioning the figures, you could use minipages to get them where you want. The output on the left imitates your example, with blank lines in between the tikzpictures. As is the case in normal text, blank lines are treated as a new paragraph. On the right is the output obtained by wrapping them in a minipage to get them where you want:

enter image description here enter image description here

Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture} \draw [fill=yellow] (0,0) rectangle (2,2); \end{tikzpicture}

\begin{tikzpicture} \draw [fill=brown] (0,0) circle (1cm); \end{tikzpicture}

\begin{tikzpicture} \draw [fill=cyan] (0,0) -- (2,0) -- (1,2) -- cycle; \end{tikzpicture}

\bigskip\hrule\bigskip

\begin{minipage}{0.45\linewidth} \begin{tikzpicture} \draw [fill=yellow] (0,0) rectangle (2,2); \end{tikzpicture}

\begin{tikzpicture}% Need blank line above
    \draw [fill=brown] (0,0) circle (1cm);
\end{tikzpicture}   

\end{minipage} % No blank line here \begin{minipage}{0.45\linewidth} \begin{tikzpicture} \draw [fill=cyan] (0,0) -- (2,0) -- (1,2) -- cycle; \end{tikzpicture}
\end{minipage} \end{document}

Peter Grill
  • 223,288