9

I am drawing some block diagrams with TikZ. Sometimes, I need to combine several blocks together to form one large group by adding a border around the corresponding blocks. However, there are some arrows which cross the border, as shown in this picture.

Block diagram without gaps

The arrow "to ALC loop" and the arrow just below it looks ugly. What I would like to do is the following (note the small gaps around the arrows where they cross the thick border):

enter image description here

How is that possible with TikZ? The arrows are just ordinary arrows drawn with the \draw[->] (from) -- (to); macro, and the thick border is also just an ordinary line.

2
  • See double option in section "15.3.4 Graphic Parameters: Double Lines and Bordered Lines", p.169, pgfmanual (v3.0.1a). Commented Jan 28, 2017 at 14:57
  • @Paul Gaborit - the disadvantage of the solution from your tip is that the shorten option can't be used as an input, because it is already applied in the problem solution: link -that is your solution here. Nevertheless your idea covers the case of overlapping arrow tip and external box border (in the picture in question).
    – forrest
    Commented Jan 28, 2017 at 15:15

2 Answers 2

13

Using @AboAmmar MWE, preaction can be used in the simple case:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[> = latex]
\node [draw, thick, minimum size=5em] (rec) {};
\node [draw] (div) {$\div$};

\draw [preaction={draw, line width=3pt, white}][<->] (div) -- ++(5em,0);

\end{tikzpicture}

\end{document}

EDIT: there is some problem nevertheless - arrow tip changes path bending dependently on the size of this arrow tip. So the idea is not good solution. enter image description here

\documentclass[border=2pt]{standalone}
\usepackage{tikz}

\tikzset{
    outlined arrow/.style={
        preaction={{}-{},draw,line width=3pt,yellow}
    }
}

\begin{document}    
\begin{tikzpicture}[> = latex]
\node [draw,thick,minimum size=5em] (rec) {};
\node [draw] (div) {$\div$};

\draw [outlined arrow][<->] (div) -- ++(5em,0);
\draw [outlined arrow][<->,shorten <=2pt] (div) .. controls +(-90:15mm) and +(180:15mm) .. ++(5em,-5em);

\end{tikzpicture}
\end{document}

EDIT 2: In the above case black arrow bent line goes not in the middle of yellow line - dependently on the arrow size. I found that @cfr response (arrow tip size independent on the line width) can be useful a bit here. The code below works only when the arrow tip setup my arrow is passed through optional argument.

enter image description here

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[
    outlined arrow/.style={preaction={double=yellow,double distance=2pt,draw=red}},
    my arrow/.style={>={LaTeX[length=2mm]}},
    yscale=0.6
]
\node [draw,thick,minimum size=5em] (rec) {};
\node [draw] (div) {$\div$};

\draw [outlined arrow][<->,my arrow] (div) -- ++(5em,0);
\draw [outlined arrow][<->,shorten <=2pt,my arrow]
      (div) .. controls +(-90:15mm) and +(180:15mm) .. ++(5em,-5em);

\end{tikzpicture}
\end{document}

I considered also the use of @Qrrbrbirlbel solution (save a path and call it for stroking), but shorten option didn't work. Also @Paul Gaborit solution (surrounded arrow) excludes shorten option (?).

1
  • this is perfect!
    – T. Pluess
    Commented Jan 28, 2017 at 20:15
10

These gaps at line crossings can be achieved with a thick white-colored line drawn the same way as your crossing line. Here is an example:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[> = latex]
\node [draw, thick, minimum size=5em] (rec) {};
\node [draw] (div) {$\div$};

\draw [<->, line width=3pt, white](div) -- ++(5em,0);
\draw [<->] (div) -- ++(5em,0);

\end{tikzpicture}

\end{document}

enter image description here

1
  • 1
    Thank you. I already had that idea too, but it has the disadvantage that the corresponding arrows have to be drawn twice. I wonder whether there is an 'automatic' way?
    – T. Pluess
    Commented Jan 28, 2017 at 14:10

You must log in to answer this question.

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