在 Tikz 中将箭头格式化并对齐为标签

在 Tikz 中将箭头格式化并对齐为标签

我正在尝试重现以下 TiZ 图:

图表重现

我设法创建了节点和箭头,但不明白如何在节点下方绘制箭头。

这是我目前使用以下代码得到的结果(针对左侧的图表):

\begin{tikzpicture}[align = center, node distance = 9em, auto, thick]
    \node [circlenode] (a) {$a$};
    \node [circlenode, xshift=+2cm] (b) {$b$};
    \node [circlenode, xshift=+4cm] (c) {$c$};

    \draw [->] (a) edge [] node {} node[] {} (b);
    \draw [->] (b) edge [] node {} node[] {} (c);
\end{tikzpicture}

到目前为止的图表

这些箭头是插入标签中还是使用新\draw宏?

答案1

您可以使用calc图书馆。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta}
\begin{document}
\begin{tikzpicture}[align = center, node distance = 9em, auto, thick,>=latex,
circlenode/.style={circle,draw,text width=1em}] % https://tex.stackexchange.com/a/327060/121799
    \node [circlenode] (a) {$a$};
    \node [circlenode, xshift=+2cm] (b) {$b$};
    \node [circlenode, xshift=+4cm] (c) {$c$};

    \draw [->] (a) edge [] node {} node[] {} (b);
    \draw [->] (b) edge [] node {} node[] {} (c);
    \draw [->|] ($(a.south east)+(1em,-1em)$) -- ($(b.south west)+(-1em,-1em)$);
    \draw [|<-] ($(b.south east)+(1em,-1em)$) -- ($(c.south west)+(-1em,-1em)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以将箭头与节点的锚点对齐,然后向上或向下移动箭头的起点和终点:

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}[minimum width=5mm]
 \node [circle,draw,label=above:{$X$}] (a) {};
 \node [circle,draw,label=above:{$Y$},xshift=+15mm] (b) {};
 \node [circle,draw,label=above:{$Z$},xshift=+30mm] (c) {};

 \draw [->] (a) -- (b);
 \draw [->] (b) -- (c);

 \draw [->|] ([xshift=2mm,yshift=-3mm]a.east) -- ([xshift=-2mm,yshift=-3mm]b.west);
 \draw [|<-] ([xshift=2mm,yshift=-3mm]b.east) -- ([xshift=-2mm,yshift=-3mm]c.west);
 
 \draw [->] ([yshift=-4mm]b.west) -- ([yshift=-4mm]b.east);
 \draw [<-] ([yshift=-5mm]b.west) -- ([yshift=-5mm]b.east);
\end{tikzpicture}

\end{document}

相关内容