我如何添加更多箭头?

我如何添加更多箭头?

我有这个代码:

\documentclass[tikz,14pt,border=10pt]{standalone}
\usepackage{verbatim}
\usetikzlibrary{er}
\usetikzlibrary{decorations}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.misc}

\tikzstyle{int}=[draw, fill=blue!20, minimum size=3em]
\tikzstyle{init} = [pin edge={to-,thin,black}]

\begin{document}
\begin{figure}[t]
\centering
\begin{tikzpicture}[scale=3]

%Blocks
\draw (0,1.5) node(inputNode)[shape=rectangle,minimum
width = 5, minimum height = 3] {$(f_{id},X_h)$};
\draw (1.5,1.5) node(LUT)[draw,shape=rectangle,minimum
width = 50, minimum height = 100,fill=black!10,thick] {LUT};
\draw (3.0,1.5) node(outputNode)[shape=rectangle,minimum 
width = 5, minimum height = 3] {$y$};

%Arcs
\draw[>=latex,->,thick] (inputNode.east) -- (LUT.west);
\draw[>=latex,->,thick] (LUT.east) -- (outputNode.west);

\end{tikzpicture}
\caption{Architecture block diagram.}
\label{fig:arch}
\end{figure}
\end{document}

编译并运行。我想知道如何在框右侧添加更多水平箭头,但高度不同。有什么线索吗?

答案1

Torbjørn T. 链接的答案对于几组线来说没问题。如果您需要更多组平行线,这里有一个带有特殊修饰的解决方案:

选项:

amplitude用作最外层线条之间的距离。这是用于许多装饰的选项。其默认值为 2.5pt。因此应设置它。

parallels number是平行线的数量。默认值为 2。

parallels arrow startparallels arrow end用于定义开始和结束的箭头。默认值:无箭头。

线与线之间的距离为amplitude/ ( parallels number- 1 )。

代码:

\documentclass[tikz,14pt,border=10pt]{standalone}
\usepackage{verbatim}
\usetikzlibrary{er}
\usetikzlibrary{decorations}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.misc}

\tikzstyle{int}=[draw, fill=blue!20, minimum size=3em]
\tikzstyle{init} = [pin edge={to-,thin,black}]

\pgfkeys{%
    /pgf/decoration/.cd,
    parallels number/.store in=\pgfparallelsnumber,
    parallels arrow start/.store in=\pgfparallelsarrowstart,
    parallels arrow end/.store in=\pgfparallelsarrowend,
    parallels number=2,
    parallels arrow start={},
    parallels arrow end={},
}

\pgfdeclaredecoration{parallels}{parallels}
{
  \state{parallels}[width=+\pgfdecoratedremainingdistance,next state=final]
  {
    \pgfsetlinewidth{\pgflinewidth}% take over outside line width
    \pgfsetarrowsstart{\pgfparallelsarrowstart}
    \pgfsetarrowsend{\pgfparallelsarrowend}
    \pgfmathsetmacro{\plnum}{\pgfparallelsnumber-1}
    \pgfmathsetmacro{\plampratiostep}{1/\plnum}
    \foreach \ply in {0,...,\plnum}{%
      \pgfmathsetmacro{\plamplituderatio}{0.5-\ply*\plampratiostep}
      {
        \pgftransformyshift{\plamplituderatio\pgfdecorationsegmentamplitude}
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{\pgfdecoratedremainingdistance}{0pt}}
        \pgfusepath{stroke}% needed here, to draw the arrow heads
      }
    }
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
  }
}

\begin{document}
\begin{tikzpicture}[scale=3]

%Blocks
\draw (0,1.5) node(inputNode)[shape=rectangle,minimum
width = 5, minimum height = 3] {$(f_{id},X_h)$};
\draw (1.5,1.5) node(LUT)[draw,shape=rectangle,minimum
width = 50, minimum height = 100,fill=black!10,thick] {LUT};
\draw (3.0,1.5) node(outputNode)[shape=rectangle,minimum 
width = 5, minimum height = 3] {$y$};

\draw[thick,decorate,decoration={parallels,parallels number=8,amplitude=1.4cm,parallels arrow end=latex}] (inputNode.east) -- (LUT.west);
\draw[thick,decorate,decoration={parallels,parallels number=3,amplitude=0.4cm,parallels arrow end=latex}] (LUT.east) -- (outputNode.west);

%testing
\begin{scope}[decoration={parallels,parallels number=3,amplitude=0.4cm,parallels arrow end=latex}]
\draw[thick,decorate] (1  ,-0.5) -- (0.5, 0);
\draw[thick,decorate] (1.5,-0.5) -- (1.5, 0);
\draw[thick,decorate] (2  ,-0.5) -- (2.5, 0);
\draw[thick,decorate] (2  ,-1  ) -- (2.5,-1);
\draw[thick,decorate] (2  ,-1.5) -- (2.5,-2);
\draw[thick,decorate] (1.5,-1.5) -- (1.5,-2);
\draw[thick,decorate] (1  ,-1.5) -- (0.5,-2);
\draw[thick,decorate] (1  ,-1  ) -- (0.5,-1);
\end{scope}

\end{tikzpicture}
\end{document}

结果(图片下方有几个箭头用于测试):

在此处输入图片描述

编辑:标记线条

备注:以前的版本不支持颜色,我在这里添加了。由于我不知道如何获取外部颜色,我添加了一个选项parallels color,如果线条应该是黑色(默认)以外的其他颜色,则必须使用该选项。

现在进行标记:

标签的设置方式与普通线几乎相同。但必须将它们偏移一半幅度才能正确定位。例如,可以使用以下方法为所有线设置一个标签

\draw[decorate,decoration={parallels,amplitude=0.4cm,}]
    (0,1) -- node[above,yshift=0.2cm]{label above} (2,1);

如果需要为每行设置一个标签,首先必须设置较大的幅度,以便行与行之间有足够的空间来显示文本。然后可以使用多个标签。例如

\draw[decorate,decoration={parallels,amplitude=1cm,}]
    (0,1) -- node[above,yshift=0.5cm]{label above line 1}
             node[above,yshift=-0.5cm]{label above line 2} (2,1);

以下是一个例子:

\documentclass[tikz,14pt,border=10pt]{standalone}
\usetikzlibrary{decorations}
\usetikzlibrary{arrows}

\pgfkeys{%
    /pgf/decoration/.cd,
    parallels number/.store in=\pgfparallelsnumber,
    parallels arrow start/.store in=\pgfparallelsarrowstart,
    parallels arrow end/.store in=\pgfparallelsarrowend,
    parallels color/.code={\colorlet{parallelscolor}{#1}},
    parallels number=2,
    parallels arrow start={},
    parallels arrow end={},
    parallels color={black}
}

\pgfdeclaredecoration{parallels}{initial}
{
  \state{initial}[width=+\pgfdecoratedremainingdistance,next state=final]
  {
    \pgfsetlinewidth{\pgflinewidth} % take over outside line width
    \pgfsetcolor{parallelscolor}
    \pgfsetarrowsstart{\pgfparallelsarrowstart}
    \pgfsetarrowsend{\pgfparallelsarrowend}
    \pgfmathsetmacro{\plnum}{\pgfparallelsnumber-1}
    \pgfmathsetmacro{\plampratiostep}{1/\plnum}
    \foreach \ply in {0,...,\plnum}{%
      \pgfmathsetmacro{\plamplituderatio}{0.5-\ply*\plampratiostep}
      {
        \pgftransformyshift{\plamplituderatio\pgfdecorationsegmentamplitude}
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{\pgfdecoratedremainingdistance}{0pt}}
        \pgfusepath{stroke}% needed here, to draw the arrow heads
      }
    }
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
  }
}

\begin{document}
\begin{tikzpicture}[scale=3]
\draw[blue,thick,decorate,decoration={parallels,parallels number=8,amplitude=1.4cm,parallels arrow end=latex,parallels color=blue}]
    (0,1) -- node[above,yshift=0.7cm]{label above} (2,1);
\draw[green,thick,decorate,decoration={parallels,parallels number=3,amplitude=0.4cm,parallels arrow end=latex,parallels color=green}]
    (0,0.5) -- node[below,yshift=-0.2cm]{label below} (2,0.5);
\draw[magenta,thick,decorate,decoration={parallels,parallels number=3,amplitude=1.2cm,parallels arrow end=latex,,parallels color=magenta}]
    (0,-0.3) -- node[above,yshift=0.6cm]{label 1 above}
                node[above]{label 2 above}
                node[above,yshift=-0.6cm]{label 3 above} (2,-0.3);
\draw[cyan,thick,decorate,decoration={parallels,parallels number=4,amplitude=1.8cm,parallels arrow end=latex,,parallels color=cyan}]
    (0,-1.2) -- node[below,yshift=0.9cm]{label 1 below}
                node[below,yshift=0.3cm]{label 2 below}
                node[below,yshift=-0.3cm]{label 3 below}
                node[below,yshift=-0.9cm]{label 4 below} (2,-1.2);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容