对于每个节点我想画箭头'->'

对于每个节点我想画箭头'->'

我想为每条路径绘制“->”。

实际上我尝试添加每个节点选项和“->”,但这不起作用。

我知道 \draw[->] (t1)--(t2); \draw[->] (t2)--(t3); ... 会起作用。

但我想知道简单的解决方案。

有什么简单的解决办法吗?

在此处输入图片描述

\begin{figure} \begin{tikzpicture}[auto, block/.style = {rectangle, draw}]
\matrix[every node/.style = block, column sep=4mm, row sep=6mm]{    
        \node (t1) {host}; & & \node (t11) {host}; \\
        \node (t2) {ICMP}; & & \node (t10) {ICMP}; \\
        \node (t3) {ICMP}; & & \node (t9) {ICMP}; \\ 
        \node (t4) {host}; & & \node (t8) {host}; \\ 
        \node (t5) {ICMP}; & \node (t6) {dd}; & \node (t7) {ICMP}; \\ 
    }; 
    \path[draw, every node, ->] (t1)--(t2)--(t3)->(t4)->(t5)->(t6)->(t7)->(t8)->(t9)->(t10);
    \end{tikzpicture} \end{figure}

答案1

路径被视为单个对象,因此段本身不能有箭头。但您可以轻松地在循环中绘制路径,然后每个段都可以有自己的箭头:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[auto, block/.style = {rectangle, draw}]
\matrix[every node/.style = block, column sep=4mm, row sep=6mm]{    
        \node (t1) {host}; & & \node (t11) {host}; \\
        \node (t2) {ICMP}; & & \node (t10) {ICMP}; \\
        \node (t3) {ICMP}; & & \node (t9) {ICMP}; \\ 
        \node (t4) {host}; & & \node (t8) {host}; \\ 
        \node (t5) {ICMP}; & \node (t6) {dd}; & \node (t7) {ICMP}; \\ 
    };
    \foreach \x [remember=\x as \lastx (initially 1)] in {2,...,11}{
    \path[draw, ->] (t\lastx)--(t\x);
    }
    \end{tikzpicture}
\end{document}

代码输出

相关内容