从箭头到节点的连接留下空隙

从箭头到节点的连接留下空隙

这是我第一次在这里发帖,所以我希望我没有弄乱。:)

我的问题,我似乎找不到一个例子:我试图画一条线,从箭头指向一个节点。考虑到我是 tikz 的初学者,所以我在 MWE 中的代码可能不够“优雅”。

问题:画出的线与箭头不相连,总是有间隙或分离。如何消除这种情况?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[node distance=30mm and 35 mm]
\tikzstyle{arrow} = [thick,->]
 \tikzset{stepbox/.style = {rectangle,fill=yellow!20, draw, rounded corners, minimum width=60mm, minimum height=2em, }}
 \tikzset{instructions/.style = {rectangle,draw, minimum width=40mm, minimum height=4em, }}

% boxes for steps
\node[stepbox] (S1) {step  1};
\node[stepbox,below=of S1] (S2) {step 2};

% top aside
\node[instructions,right=of S1,align=left] (todo1) {Things to do};
\draw (S1) -- (todo1) ;

\draw[arrow] (S1) edge[out=-90, in=90, looseness=1.1] node[auto] (Arrow1) {} (S2) ;

\node[instructions,right=of Arrow1,align=left] (Aufg1) {wait: 2h - 4h\\28°C\\total: 2.0 - 4.0};
\draw (Arrow1) -- (Aufg1) ;

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

造成间隙的原因是您将箭头上的连接点定义为节点,而节点的宽度不为零。您应该使用坐标来代替它。除此之外,我建议:

  • 用于直线使用语法\draw (<coordinate 1>) -- (<coordinate 2>);
  • 对于单位使用siunitx

我会按照以下方式绘制你的图像:

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}
\usepackage{siunitx}

\begin{document}
    \begin{tikzpicture}[
 node distance = 30mm and 35 mm,
  arrow/.style = {thick,-Straight Barb},
stepbox/.style = {draw, rounded corners, fill=yellow!20, 
                  minimum width=60mm, minimum height=2em},
instructions/.style = {draw, minimum width=40mm, minimum height=4em, align=left}
                        ]
% boxes for steps
\node[stepbox] (S1) {step  1};
\node[stepbox,below=of S1] (S2) {step 2};
\draw[arrow] (S1) -- coordinate[auto] (Arrow1) (S2); % <--- 
% top aside
\node[instructions,right=of S1] (todo1) {Things to do};
\draw (S1) -- (todo1) ;
\node[instructions,right=of Arrow1] (Aufg1) {wait: \SIrange{2}{4}{h}\\
                                                   \SI{28}{\celsius}\\
                                             total: 2.0 - 4.0};
\draw (Arrow1) -- (Aufg1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

附录: 看来你喜欢以下图像:

在此处输入图片描述

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}
\usepackage{siunitx}
\sisetup{locale = DE,
         range-phrase={ -- }}

\begin{document}
    \begin{tikzpicture}[
 node distance = 30mm and 5 mm,
  arrow/.style = {thick,-Straight Barb},
stepbox/.style = {draw, rounded corners, fill=yellow!20, 
                  minimum width=60mm, minimum height=2em},
instructions/.style = {draw, minimum width=40mm, minimum height=4em, align=left}
                        ]
% boxes for steps
\node[stepbox] (S1) {step  1};
\node[stepbox,below=of S1] (S2) {step 2};
\draw[arrow] (S1) -- coordinate[auto] (Arrow1) (S2);
% top aside
\node[instructions,right=of S1] (todo1) {Things to do};
\draw (S1) -- (todo1) ;
\node[instructions,right=of Arrow1 -| S1.east] (Aufg1) 
        {wait: \SIrange{2}{4}{h}\\
         \SI{28}{\celsius}\\
         total: \numrange{2.0}{4.0}};
\draw (Arrow1) -- (Aufg1);
\end{tikzpicture}
\end{document}

编辑: 该包的使用siunitx现在已本地化为德语。

答案2

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}[node distance=30mm and 35 mm]
        \tikzstyle{arrow} = [thick,->]
        \tikzset{stepbox/.style = {rectangle,fill=yellow!20, draw, rounded corners, minimum width=60mm, minimum height=2em, }}
        \tikzset{instructions/.style = {rectangle,draw, minimum width=40mm, minimum height=4em, }}
        
        % boxes for steps
        \node[stepbox] (S1) {step  1};
        \node[stepbox,below=of S1] (S2) {step 2};
        
        % top aside
        \node[instructions,right=of S1,align=left] (todo1) {Things to do};
        \draw (S1) -- (todo1) ;
        
        \draw[arrow] (S1) -- (S2)node[right,midway,xshift=2in, instructions,align=left] (Aufg1) {wait: 2h - 4h\\28°C\\total: 2.0 - 4.0} ;
        \draw(S1)|-(Aufg1);

        
    \end{tikzpicture}
\end{document}

相关内容