5

I have this code:

% !TeX encoding = UTF-8


\documentclass[utf8]{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}

\newcommand{\multilinks}[3]{\foreach \noeud in {#1} {\draw[<-, rounded corners] (#2.west) -| ++(-#3em,0em) |- (\noeud.east);}}

\begin{document}
    \begin{figure}[htp]
        \centering
        \tikzset{
            basic/.style={draw, rounded corners=2pt, thick, text width=8em, align=flush center, node distance=2em},
        }
        \begin{tikzpicture}[]
            \matrix[row sep=2em, column sep=4em, every node/.style={basic}] {
                \node(n1){Text}; & \node(n3){another text}; \\
                \node(n2){one thing}; & \node(n4){again text}; \\
            };
            \multilinks{n1,n2}{n3}{3}
            \multilinks{n1}{n4}{1}
        \end{tikzpicture}
    \end{figure}

\end{document}

It gives me this result:

As you can see, a curve is weird. How can I fix it?

Here's the result I want:

6

A slight change in the definition of \multilinks and the list #1 in the first \multilinks:

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix,positioning}

\newcommand{\multilinks}[3]{
    \foreach \noeud in {#1} {
        \draw[<-, rounded corners] (#2.west) -- ++(-#3 em,0em) |- (\noeud.east);
    }
}

\begin{document}
\tikzset{
    basic/.style={
        draw, 
        rounded corners=2pt, 
        thick, 
        text width=8em, 
        align=flush center, 
        node distance=2em
    }
}
\begin{tikzpicture}[]
\fontsize{8}{9} \selectfont
\matrix[row sep=2em, column sep=4em, every node/.style={basic}] {
    \node(n1){Text}; & \node(n3){another text}; \\
    \node(n2){one thing}; & \node(n4){again text}; \\
};
\multilinks{n2}{n3}{3}
\multilinks{n1}{n4}{1}
\end{tikzpicture}

\end{document}

enter image description here


Edit

In case you want to keep the original way, the definition of \multilinks is a bit more complicated:

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix,positioning}

\newcommand{\multilinks}[3]{
    \begin{scope}[x=1em,y=1em]
    \newdimen\xend
    \newdimen\yend  
    \path (#2.west);
    \pgfgetlastxy{\xend}{\yend}
    \foreach \i in {#1} {
        \newdimen\xstart
        \newdimen\ystart 
        \path (\i.east);
        \pgfgetlastxy{\xstart}{\ystart}
        \coordinate (1) at ({\xend-#3 em},\ystart);
        \coordinate (2) at ({\xend-#3 em},\yend);
        \ifdim\ystart=\yend
            \draw[->] (\i.east)--(#2.west);
        \else
            \draw[->,rounded corners] (\i.east)--(1)--(2)--(#2.west);
        \fi
    }
    \end{scope}
}

\begin{document}
\tikzset{
    basic/.style={
        draw, 
        rounded corners=2pt, 
        thick, 
        text width=8em, 
        align=flush center, 
        node distance=2em
    }
}
\begin{tikzpicture}[]
\fontsize{8}{9} \selectfont
\matrix[row sep=2em, column sep=4em, every node/.style={basic}] {
    \node(n1){Text}; & \node(n3){another text}; \\
    \node(n2){one thing}; & \node(n4){again text}; \\
};
\multilinks{n1,n2}{n3}{3}
\multilinks{n1}{n4}{1}
\end{tikzpicture}

\end{document}

enter image description here

We have to add an \ifdim because TikZ is quite confused when it is commanded to draw a rounded corners path from point A to point A (i.e. two identical points):

\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[y=0.2cm]
\draw[rounded corners] (0,0) --(1,0) --(1,0)--(2,0) ; % Some bugs?
\draw[rounded corners] (0,-1)--(1,-1)--       (2,-1);
\draw[rounded corners] (0,-2)--               (2,-2);
\end{tikzpicture}
\end{document}

enter image description here

  • It doesn't works with \multilinks{n1,n2}{n3}{3} – Vinccool96 Mar 18 at 5:24
  • @Vinccool96 I edited my answer so that it works with \multilinks{n1,n2}{n3}{3}. – JouleV Mar 18 at 6:55

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.