4

first post here, so I hope I'm not making a mess. :)

My question, for which I can't seem to find an example: I am trying to draw a line, originating at an arrow to a node. Consider me a beginner at tikz, so my code in the MWE may not be "elegant".

The problem: the line that is drawn does not connect to the arrow, there is always a gap or separation. How to get rid of that?

\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}

enter image description here

6
  • 1
    \draw[arrow] (S1) edge[out=-90, in=90, looseness=1.1] coordinate[auto] (Arrow1) (S2) ;
    – user237299
    Mar 16, 2021 at 3:47
  • cool! that is the solution!
    – hazefire
    Mar 16, 2021 at 3:53
  • A further question, I forgot before... How to the nodes on the right horizontally aligned so they are one above the other?
    – hazefire
    Mar 16, 2021 at 4:06
  • 1
    \node[instructions,align=left] (Aufg) at (todo11|-Arrow1){wait: 2h - 4h\\28°C\\total: 2.0 - 4.0}; \draw (Aufg1) -- (Arrow1);
    – user237299
    Mar 16, 2021 at 4:12
  • great! That works! Thanks again for that!
    – hazefire
    Mar 16, 2021 at 4:35

2 Answers 2

4

The gap is caused because you define the connection point on the arrow as a node, which has not zero width. Instead of it, you should use a coordinate. Besides this I recommend:

  • for straight-line use syntax \draw (<coordinate 1>) -- (<coordinate 2>);
  • for units use the siunitx package

I would draw your image on the following way:

\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}

enter image description here

Addendum: It seems that you like to have the following image:

enter image description here

\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}

Edit: Use of the siunitx package is now localized to German language.

8
  • Zarko, thanks! That looks nicer than my solution :) The fact that an arrow has a certain width, explains my wrong expectations. Question: Why do you highlight (?) the line with "% <--- "? I would modify the "\node[instructions,right=of Arrow1] (Aufg1) {wait: ...." to "\node[instructions] (Aufg1) at (todo1|-Arrow1) {wait:" so I get the right asides on top of each other.
    – hazefire
    Mar 16, 2021 at 7:35
  • @hazefire, not arrow, node ;-) Minimal width of empty node is equal to 2inner sep which default size is 3pt. I highlight this code line because there is the main change, which sole your problem. In the real document just remove it.
    – Zarko
    Mar 16, 2021 at 7:37
  • @hazefire, I don't understand the second part of your comment. You like to have right boxes above each other?
    – Zarko
    Mar 16, 2021 at 7:43
  • 1
    @hazefire, instead of saying "thank you" hgere is habit to up-vode answer (by clicking on the up-triangle at top left side of answer) and if it solve your problem on the best way, you can accept it (by clicking on the check mark) :-)
    – Zarko
    Mar 16, 2021 at 9:14
  • 1
    @hazefire, you can define localization for siunitx, I would did this before, if I know, that you are German :-). Now the second example is corrected.
    – Zarko
    Mar 16, 2021 at 11:06
2

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .