3

I want to connect two nodes with that are not aligned either in X or Y dimension, node 2 is to the lower right of node 1 (for the sake of the argument). The line should start from node 1, goes to the right horizontally until it's above node 2, then I want it to make a U turn and connect to node 2 from the right.

The following code produces kind of what I want:

\documentclass[12pt]{standalone}
\usepackage{amssymb,amsfonts,amsmath}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric}
\usetikzlibrary{scopes}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}


\tikzset{copy/.style={circle,inner sep=0pt,fill=black,minimum
    size=5pt} }

\def\tnboxsize{6mm}

\tikzset{box/.style={rectangle,draw=black,fill=none, minimum
    width=\tnboxsize, minimum height=\tnboxsize,
    shape border uses incircle}}

\tikzset{blank/.style={rectangle,inner
    sep=0pt,draw=none,fill=none,minimum size=0pt} }

\tikzset{blankbig/.style={rectangle,inner sep=0pt,draw=none,fill=none,minimum
    size=\tnboxsize} }


\begin{document}
    \begin{tikzpicture}[thick]
      \node[blank] (out1) {};
      \node[blank] (out2) [below=0.5 of out1] {};
      \node[blank] (out3) [below=0.5 of out2] {};

      \node[blank] (anchorout) at ($(out1)!0.5!(out2)$) {};
      \node[copy] (copy) [right=0.6 of anchorout] {};
      \node[box] (c) [right=of out3] {$C$};

      \draw [-] (out1) -- (copy);
      \draw [-] (out2) -- (copy);
      \draw [-] (out3) -- (c);
      \draw [-] (copy) -- +(0.75,0) .. controls +(0.7,0) and +(0.7,0) .. (c);
\end{tikzpicture}

\end{document}

Like this:

Good

However, to do this, I had to manually adjust the numbers for the controlling points in \draw [-] (copy) -- +(0.75,0) .. controls +(0.7,0) and +(0.7,0) .. (c).

For example, when these numbers are messed up, the picture looks like this:

enter image description here

Is there a way to enforce the behavior like in the first picture without manually adjusting the positions of the control points?

3
  • 2
    Did rounded corners and -| solve your problem? For example: \draw[rounded corners=8] (copy) -| ($(c)+(.7,0)$) -- (c); (You might want to try other value for the rounded corners)
    – Vinzza
    Nov 12 '18 at 12:02
  • In case of a curve my proposal is somethimg like: \draw [-] (copy) to[in=90,out=0] ([shift={(1,0)}]$(c)!0.5!(copy)$) to[in=0,out=270](c); but @Vinzza's suggestion is probably easier
    – koleygr
    Nov 12 '18 at 12:06
  • @Vinzza it seems like a good option, actually! I was thinking of something similar but didn't know how to use this ($(c)+(.7,0)$) notation properly Nov 12 '18 at 12:21
3

some how similar to propositions in above comments, however also address some off-topic issues:

\documentclass[12pt, tikz, margin=3mm]{standalone}
\usepackage{amssymb,amsfonts,amsmath}

\usetikzlibrary{calc,
                decorations.pathreplacing,
                positioning,
                shapes.geometric, scopes}
\tikzset{
 copy/.style = {circle,inner sep=0pt,fill=black,minimum size=5pt},
  box/.style = {rectangle,draw=black,fill=none, 
                minimum width=\tnboxsize, minimum height=\tnboxsize,
                shape border uses incircle},
blank/.style = {rectangle,inner sep=0pt, draw=none,fill=none, minimum size=0pt}, % <--- not needed, rather use coordinate 
blankbig/.style = {rectangle,inner sep=0pt,draw=none,fill=none, minimum size=\tnboxsize} 
        }
\def\tnboxsize{6mm}


\begin{document}
    \begin{tikzpicture}[thick,
    node distance = 5mm and 6mm  % <--- added
                        ]
    \coordinate                 (out1);
    \coordinate[below=of out1]  (out2);
    \coordinate[below=of out2]  (out3);

    \node[copy] (copy)  [right=of $(out1)!0.5!(out2)$]  {}; % <--- removed one coordinate
    \node[box]  (c)     [right=of out3 -| copy]         {$C$};

    \draw   (out1) -- (copy)  % <--- slightly shorter code
            (out2) -- (copy) 
            (out3) -- (c) 
            (copy.east) -- (copy -| c.east) % <--- auxiliary coordinate 

                        .. controls +(0.5,0) and +(0.5,0) .. (c.east);
\end{tikzpicture}

\end{document}

enter image description here

3

You can do the following (just changing tour last \draw command):

  1. draw from copy to the point that has copy y-coord and the east point of c as x-coord:

    (copy) -- (copy -| c.east)
    
  2. and then go to c.east using a curve starting with angle 0, arriving at angle 0, and looseness 2 (that should be half a circle, more or less):

    to [out=0, in=0, looseness=2]
    

Like that:

 \draw (copy) -- (copy -| c.east) 
      to[out=0, in=0, looseness=2] (c.east);

You get:

enter image description here

Full MWE:

\documentclass[12pt]{standalone}
\usepackage{amssymb,amsfonts,amsmath}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric}
\usetikzlibrary{scopes}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}


\tikzset{copy/.style={circle,inner sep=0pt,fill=black,minimum
    size=5pt} }

\def\tnboxsize{6mm}

\tikzset{box/.style={rectangle,draw=black,fill=none, minimum
    width=\tnboxsize, minimum height=\tnboxsize,
    shape border uses incircle}}

\tikzset{blank/.style={rectangle,inner
    sep=0pt,draw=none,fill=none,minimum size=0pt} }

\tikzset{blankbig/.style={rectangle,inner sep=0pt,draw=none,fill=none,minimum
    size=\tnboxsize} }


\begin{document}
    \begin{tikzpicture}[thick]
      \node[blank] (out1) {};
      \node[blank] (out2) [below=0.5 of out1] {};
      \node[blank] (out3) [below=0.5 of out2] {};

      \node[blank] (anchorout) at ($(out1)!0.5!(out2)$) {};
      \node[copy] (copy) [right=0.6 of anchorout] {};
      \node[box] (c) [right=of out3] {$C$};

      \draw [-] (out1) -- (copy);
      \draw [-] (out2) -- (copy);
      \draw [-] (out3) -- (c);
      %
      \draw (copy) -- (copy -| c.east)
          to[out=0, in=0, looseness=2] (c.east);
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.