tikz:自动锚点

tikz:自动锚点

您能看到标签“prodotti”吗?

\documentclass{article}
\usepackage{float}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
 
% Sum shape
\node[] (enter) at (0,0){alimentazione};
 
\node [draw,
    fill=SeaGreen!50,
    minimum width=3cm,
    minimum height=1.6cm,
    rounded corners=0.5mm,
    right=1cm of enter,
]  (system) {unità di separazione};

\draw[-stealth] (enter.east) -- ++(1,0);
\node[above=1em of system.east] (a) {};
\draw[-stealth] (a.center) -- ++(1,0) node (b) {};
\node[below=1em of system.east] (c) {};
\draw[-stealth] (c.center) -- ++(1,0) node (d) {};
\node[below=2em of system.south] (separator_agent) {agente separante};
\draw[-stealth] (separator_agent.north) -- (system.south) {};
\node[] (e) at (b.east) {prodotti}; % <--- this
\end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

有没有办法将标签直接锚定到箭头的末端,而不必“手动”计算位置xshift

答案1

您需要指定节点的锚点。

\documentclass{article}
\usepackage{float}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
  \begin{figure}[H]
    \centering
    \begin{tikzpicture}
    
    % Sum shape
    \node (enter) at (0,0) {alimentazione};
    
    \node [draw,
      fill=SeaGreen!50,
      minimum width=3cm,
      minimum height=1.6cm,
      rounded corners=0.5mm,
      right=1cm of enter,
    ]  (system) {unità di separazione};
    
    \draw[-stealth] (enter.east) -- ++(1,0);
    \node[above=1em of system.east] (a) {};
    \draw[-stealth] (a.center) -- ++(1,0) node (b) {};
    \node[below=1em of system.east] (c) {};
    \draw[-stealth] (c.center) -- ++(1,0) node (d) {};
    \node[below=2em of system.south] (separator_agent) {agente separante};
    \draw[-stealth] (separator_agent.north) -- (system.south) {};
    \node[anchor=west] (e) at (b.east) {prodotti}; % <--- this
    \end{tikzpicture}
  \end{figure}
\end{document}

在此处输入图片描述

正如@SebGlav 指出的那样,您可以编写代码right而不是anchor=west在节点的可选参数中。

答案2

我建议使用更简单的代码,不使用positioning。只需\draw从节点发出所有箭头system即可。标签节点可以同时创建。

在此处输入图片描述

\documentclass{article}
\usepackage{float}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
%\usetikzlibrary{positioning}
\begin{document}
\begin{figure}[H]
\centering

\begin{tikzpicture}
\node [draw,
    fill=SeaGreen!50,
    minimum width=3cm,
    minimum height=1.6cm,
    rounded corners=0.5mm
] (system) {unita di separazione};

\draw[stealth-] (system.west) --++(-1,0)node[left]{alimentazione};
\draw[stealth-] (system.south) --++(0,-1)node[below]{agente separante};
\draw[-stealth] ([yshift=-4mm]system.east) --++(1,0);
\draw[-stealth] ([yshift=4mm]system.east) --++(1,0)node[right]{prodotti};
\end{tikzpicture}

\end{figure}
\end{document}

相关内容