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.

1
  • welcome -- please have a look athe answer below
    – js bibra
    Feb 22, 2021 at 14:16

2 Answers 2

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}
6
  • 1
    ah, cool. So interpreting your code: a dummy node is added so that each path is only drawn once? Feb 22, 2021 at 14:17
  • 1
    at the point where the line turns left for the node b -- at that point
    – js bibra
    Feb 22, 2021 at 14:19
  • 1
    great, thank you Feb 22, 2021 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, 2021 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.) Feb 22, 2021 at 15:21
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

4
  • Thanks Ignasi; do I understand correctly that ([yshift=-3mm]a.south) knida sorta takes the place of a dummy node? Feb 22, 2021 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, 2021 at 16:13
  • got it (i think) thanks for the details Ignasi. Feb 22, 2021 at 16:53
  • @user2957945 another example of shift have a look -- tex.stackexchange.com/a/584420/197451
    – js bibra
    Feb 23, 2021 at 0:08

You must log in to answer this question.

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