Tikzpicture:居中过渡的标签

Tikzpicture:居中过渡的标签

请问我怎样才能使过渡标签居中?

\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}

答案1

快速破解:明确设置锚点

\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}

在此处输入图片描述

答案2

使用quotesTiZ 库:

\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}

chains好吧,还采用了positioning节点放置、arrows.meta箭头样式以及我认为改进的图像设计:

在此处输入图片描述

相关内容