3

Is it possible to align the dash strokes from two paths which are on top of each other?

In the figure below, the section of the path directly underneath node c has a slightly denser dash length due to the two paths on top of each other. Is there a way to avoid this please?

enter image description here


\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \node[draw] at (-1,-1) (a) {a} ;
  \node[draw] at (0,-1) (b) {b} ;
  \node[draw, anchor=south] at (1,0) (c) {c} ;
  \draw[dashed, ->] (c.south) |- (b.east) ;
  \draw[dashed, <-] (a.south) -- +(270:3mm) -| (c.south); 
\end{tikzpicture}
\end{document}

If I increase the vertical adjustment from node a to +(270:10mm) this looks better, but of course the adjustment is to large.

2 Answers2

4

enter image description here

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \node[draw] at (-1,-1) (a) {a} ;
  \node[draw] at (0,-1) (b) {b} ;
  \node[draw, anchor=south] at (1,0) (c) {c} ;
  \draw[dashed, ->] (c.south) |-coordinate(aux) (b.east) ;
  \draw[dashed, <-] (a.south) -- +(270:3mm) -| (aux); 
\end{tikzpicture}
\end{document}
js bibra
  • 21,280
  • 1
    ah, cool. So interpreting your code: a dummy node is added so that each path is only drawn once? – user2957945 Feb 22 '21 at 14:17
  • 1
    at the point where the line turns left for the node b -- at that point – js bibra Feb 22 '21 at 14:19
  • 1
    great, thank you – user2957945 Feb 22 '21 at 14:22
  • 1
    There's no need for auxiliar node: `\draw[dashed, ->] (c) |- ([yshift=-3mm]a.south)--(a); \draw[dashed, <-] (b) -- (b-|c); – Ignasi Feb 22 '21 at 14:51
  • 1
    @Ignasi It's worth posting that as an alternative answer. The two versions have different dash patterns on the vertical so this is a situation where a small difference in code can produce a visible difference, and then it's very useful to be able to see both versions clearly as separate answers rather than one being buried in comments. (To be clear, I'm not saying that one is better than the other, just that they are different.) – Andrew Stacey Feb 22 '21 at 15:21
  • @AndrewStacey I've added the answer. Thank you for suggesting it. – Ignasi Feb 22 '21 at 15:30
3

Following code, shows an alternative construction with an alternative result. In this case, the line between nodes c and a is drawn first, and the line between this path and node b is drawn later. There is no auxiliary node and no part of this path is drawn twice.

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \node[draw] at (-1,-1) (a) {a} ;
  \node[draw] at (0,-1) (b) {b} ;
  \node[draw, anchor=south] at (1,0) (c) {c} ;
  \draw[dashed, ->] (c) |- ([yshift=-3mm]a.south)--(a); 
  \draw[dashed, <-] (b) -- (b-|c);
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588
  • Thanks Ignasi; do I understand correctly that ([yshift=-3mm]a.south) knida sorta takes the place of a dummy node? – user2957945 Feb 22 '21 at 15:43
  • 1
    @user2957945 It's not a node because it has no name and other attributes. It's just a way of defining a coordinate. In this case it's the coordinate which is 3mm below the coordinate corresponding to the anchor a.south. – Ignasi Feb 22 '21 at 16:13
  • got it (i think) thanks for the details Ignasi. – user2957945 Feb 22 '21 at 16:53
  • @user2957945 another example of shift have a look -- https://tex.stackexchange.com/a/584420/197451 – js bibra Feb 23 '21 at 00:08