2

How could I center the transitions' labels please?

\documentclass[12pt]{book}
\usepackage[french]{babel}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{arrows.meta,arrows,chains,automata,shapes,matrix,positioning,scopes,calc}

\begin{document}
    \begin{figure}
        \begin{tikzpicture}[>=Stealth, shorten >=1pt, auto, node distance=5cm]
            \node[state](1){\emph{Code source}};
            \node[state](2)[right of=1]{\emph{Analyseur lexical}};
            \node[state](3)[right of=2]{\emph{Analyseur syntaxique}};
            \path[->] (1) edge node {\emph{Lexèmes}} (2);
            \path[->] (2) edge [bend left] node {\emph{Jetons}} (3);
            \path[->] (3) edge [bend left] node {\emph{Requête\\de jetons}} (2);
        \end{tikzpicture}
        \label{fig:relationLexemesJetons}
    \end{figure}
\end{document}

2 Answers 2

4

Quick hack: explicitly set an anchor

\documentclass[12pt]{book}
\usepackage[french]{babel}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{arrows.meta,arrows,chains,automata,shapes,matrix,positioning,scopes,calc}

\begin{document}
    \begin{figure}
        \begin{tikzpicture}[>=Stealth, shorten >=1pt, auto, node distance=5cm]
            \node[state](1){\emph{Code source}};
            \node[state](2)[right of=1]{\emph{Analyseur lexical}};
            \node[state](3)[right of=2]{\emph{Analyseur syntaxique}};
            \path[->] (1) edge node {\emph{Lexèmes}} (2);
            \path[->] (2) edge [bend left] node[anchor=south] {\emph{Jetons}} (3);
            \path[->] (3) edge [bend left] node[anchor=north,align=center,text width=2cm] {\emph{Requête de jetons}} (2);
        \end{tikzpicture}
        \label{fig:relationLexemesJetons}
    \end{figure}
\end{document}

enter image description here

2

With use of the quotes TikZ library:

\documentclass[12pt]{book}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                positioning,
                quotes}

\begin{document}
    \begin{figure}[ht]
    \centering
    \begin{tikzpicture}[
node distance = 22mm,
  start chain = going right,
     C/.style = {circle, draw, font=\itshape, text width=5em, align=center,
                 on chain},
every edge/.style = {draw, -Stealth, semithick},
every edge quotes/.style = {auto, font=\small\itshape, align=center}
                        ]
\node[C](1) {Code source};
\node[C](2) {Analyseur lexical};
\node[C](3) {Analyseur syntaxique};
%
\draw   (1) edge["Lexèmes"]                         (2)
        (2) edge[bend left, "Jetons"]               (3)
        (3) edge[bend left, "Requête\\ de jeton"]   (2);
        \end{tikzpicture}
\caption{Referencing work correctly if \texttt{label} is placed after caption.}
\label{fig:relationLexemesJetons}
    \end{figure}
\end{document}

Well, employed are also chains and positioning for nodes placement, and arrows.meta for arrows styles and in my opinion improved image design:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .