0

I guess this is kind of a long shot. The MWE below produces the following output:

enter image description here

I would like to replace the wire with a 'hollow' one that makes the insides of the nodes appear as one contiguous area, so that it looks more like this mockup:

enter image description here

The important thing is I don't just want to draw this one picture. This is part of a library I'm writing, so I really want to make a command that says "draw a hollow wire from this coordinate to this other coordinate." The coordinates will always be placed on a vertical edge of a shape, as they are in the example.

Something like this would be even better, if there's a way to do it seamlessly:

enter image description here

Here's the MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture} \node[draw,rounded corners=0.5mm] (a) at (0,0) {$A$}; \node[draw,rounded corners=0.5mm] (b) at (1.5,0.5) {$B$}; \coordinate (a out) at ([yshift=-1mm]a.east); \coordinate (b in) at ([yshift=-1mm]b.west); \draw (a out) to[out=0,in=180] (b in); \end{tikzpicture}

\end{document}

N. Virgo
  • 4,289
  • 2
  • 26
  • 41

2 Answers2

2

You can use the double option and then lengthen the wire by the line thickness (which is to use shorten with a negative value).

enter image description here

Here is the code:

\documentclass{article}
\usepackage{tikz}
\tikzset{connector/.style={double, double distance=1mm, shorten <=-\pgflinewidth, shorten >=-\pgflinewidth}}

\begin{document}

\begin{tikzpicture} \node[draw,rounded corners=0.5mm] (a) at (0,0) {$A$}; \node[draw,rounded corners=0.5mm] (b) at (1.5,0.5) {$B$}; \coordinate (a out) at ([yshift=-1mm]a.east); \coordinate (b in) at ([yshift=-1mm]b.west); \draw[connector] (a out) to[out=0,in=180] (b in); \end{tikzpicture}

\end{document}

The thin gray line at the connection point is an artifact of the double construction. Eliminating it is not easy, but you can cover it up if you know that the connection points will all be along vertical lines by drawing a short white line over it:

enter image description here

Here is the code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{
    connector/.style={
        double, double distance=1mm, shorten <=-\pgflinewidth, shorten >=-\pgflinewidth,
        postaction=decorate, decoration={show path construction, 
            curveto code={
                \draw[line width=1mm, white]([xshift=.2mm]\tikzinputsegmentlast)--++(.01,0);
                \draw[line width=1mm, white]([xshift=-.2mm]\tikzinputsegmentfirst)--++(-.01,0);
            }
            lineto code={
                \draw[line width=1mm, white]([xshift=.2mm]\tikzinputsegmentlast)--++(.01,0);
                \draw[line width=1mm, white]([xshift=-.2mm]\tikzinputsegmentfirst)--++(-.01,0);
            }
        }
    }
}

\begin{document}

\begin{tikzpicture} \node[draw,rounded corners=0.5mm] (a) at (0,0) {$A$}; \node[draw,rounded corners=0.5mm] (b) at (1.5,0.5) {$B$}; \coordinate (a out) at ([yshift=-1mm]a.east); \coordinate (b in) at ([yshift=-1mm]b.west); \draw[connector] (a out) to[out=0,in=180] (b in); \end{tikzpicture}

\end{document}

Sandy G
  • 42,558
  • That's great! But as in your image, I'm not quite getting a seamless join between the inside of the wire and the inside of the nodes - there's a very thin grey/black line separating them. I tried changing -\pgflinewidth to -\pgflinewidth-0.01mm, but that didn't make it go away. – N. Virgo Mar 24 '23 at 02:23
  • 1
    @N.Virgo: I updated my answer. – Sandy G Mar 24 '23 at 03:00
  • Thank you! I also wrote a self-answer with another way to fix the end points. – N. Virgo Mar 24 '23 at 03:02
1

This is a self-answer to complement Sandy G's answer. That answer is great but it inherits a problem with /tikz/double, which is that the ends of a double line aren't quite seamless, so you see very thin black lines separating the inside of the wire from the inside of the nodes.

One solution is to 'fake' the doubling by drawing a black wire and then a white one. Then the white wire can be slightly longer, avoiding the visible seams. Here is some code that does this:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture} \node[draw,rounded corners=0.5mm] (a) at (0,0) {$A$}; \node[draw,rounded corners=0.5mm] (b) at (1.5,0.5) {$B$}; \coordinate (a out) at ([yshift=-1mm]a.east); \coordinate (b in) at ([yshift=-1mm]b.west); \draw[line width=1mm + 0.3mm,shorten <=-0.15mm,shorten >=-0.15mm] (a out) to[out=0,in=180] (b in); \draw[white,line width=1mm,shorten <=-0.17mm,shorten >=-0.17mm] (a out) to[out=0,in=180] (b in); \end{tikzpicture}

\end{document}

enter image description here

This code has a bunch of hard coded numbers, which I don't really like, but I'm not enough of a tikz wizard to avoid them.

In principle it should be possible to do it using a style with a preaction as in the answers here, but I couldn't get that to work.

As a bonus, here's the second thing I asked for, using the same idea together with a background layer:

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}

\begin{tikzpicture} \node[draw,rounded corners=0.5mm,fill=white] (a) at (0,0) {$A$}; \node[draw,rounded corners=0.5mm,fill=white] (b) at (1.5,0.5) {$B$}; \coordinate (a out) at ([yshift=1mm] a.south east); \coordinate (b in) at ([yshift=1mm] b.south west); \draw[white,line width=2mm-0.3mm,shorten <=-0.5mm,shorten >=-0.5mm] (a out) to[out=0,in=180] (b in); \begin{scope}[on background layer] \draw[line width=2mm,shorten <=-0.5mm,shorten >=-0.5mm] (a out) to[out=0,in=180] (b in); \end{scope} \end{tikzpicture}

\end{document}

N. Virgo
  • 4,289
  • 2
  • 26
  • 41