2
\documentclass[border=80pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[on grid]
\draw [help lines] (0, 0) grid (3, 2);

\node (A) at (0, 0) {A};
\node[above right = 1 and 1 of A] (B) {B};
\node[above right = 1 and 1 of B] (C) {C};
\node[right = 3 of A] (D) {D};

\draw[->] (A) -- (0.8, 0.1) -- (B);
\draw[->] (B) -- (C);
\draw[->] (C) -- (D);

\end{tikzpicture}

\end{document}

enter image description here

I'm drawing 4 nodes and 3 lines. When connecting A and B, I hope the line pass through (0.8, 01), which it does by using \draw[->] (A) -- (0.8, 0.1) -- (B);

But tikz fails to parse the coordinate when I use relative position: \draw[->] (A) -- [above right = 0.1 and 0.8 of A] -- (B);. So can I use relative position like [above right = 0.1 and 0.8 of A] to control the path of line drawing?

Update:

@Ignasi suggests an interesting solution, which unfortunately I couldn't reproduce using keyword shift:

\documentclass[border=80pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[line width=1pt, on grid]
\draw [help lines] (0, 0) grid (3, 2);

\node (A) at (0, 0) {A};
\node[above right = 1 and 1 of A] (B) {B};
\node[above right = 1 and 1 of B] (C) {C};
\node[right = 3 of A] (D) {D};

%\draw[->] (A) -- (1, 0) -- (B);
\draw[->] (A) -- ([shift={(0, -1)}]B) -- (B);
\draw[->] (B) -- (C);
\draw[->] (C) -- (D);

\end{tikzpicture}

\end{document}

enter image description here

11
  • this answer may interest you
    – js bibra
    Jan 22, 2021 at 14:52
  • 3
    A relative coordinate from the pen position is defined with ++(0.8,0.1). Use \draw[->] (A)--++(0.8,0.1)--(B);
    – Ignasi
    Jan 22, 2021 at 15:33
  • 1
    @Rahn I'm not sure about what you mean. With ++(x,y) you refer a relative coordinate from the last position of the pen. But you can use relative coordinates from other nodes with ([shift={(x,y)}]B)
    – Ignasi
    Jan 22, 2021 at 16:57
  • 2
    @Rahn If you need to define some auxiliar coordinate for further reference, like Jes suggested, i think it's better to use a coordinate node instead of a regular node. A coordinate is just that, a point without dimensions but a node has certain size by default and lines will stop at it's border.
    – Ignasi
    Jan 22, 2021 at 17:00
  • 1
    @Rahn You're right it was my mistake. You should indicate a coordinate with shift not only a node's name. Try with ([shift={(x,y)}]B.center).
    – Ignasi
    Jan 25, 2021 at 8:59

2 Answers 2

4

You can use the calc library, then you can refer to the point as ($(A)+(0.8, 0.1)$).

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}

\begin{tikzpicture}[on grid]
\draw [help lines] (0, 0) grid (3, 2);

\node (A) at (0, 0) {A};
\node[above right = 1 and 1 of A] (B) {B};
\node[above right = 1 and 1 of B] (C) {C};
\node[right = 3 of A] (D) {D};

\draw[->] (A) -- ($(A)+(0.8, 0.1)$) -- (B);
\draw[->] (B) -- (C);
\draw[->] (C) -- (D);

\end{tikzpicture}

\end{document}
1
  • You can also use the calc library and replace \draw[->] (A) -- ($(A)+(0.8, 0.1)$) -- (B); by \draw[->] (A) -- ($(B)-(0.2, 0.9)$) -- (B); if you want to define your intermediate point from node B.
    – SebGlav
    Jan 23, 2021 at 15:59
1

enter image description here

\documentclass[border=80pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
    
    \begin{tikzpicture}[on grid]
        \draw [help lines] (0, 0) grid (3, 2);
        
        \node (A) at (0, 0) {A};
        \node[above right = 1 and 1 of A] (B) {B};
        \node[above right = 1 and 1 of B] (C) {C};
        \node[right = 3 of A] (D) {D};
        
        \draw[->, red] (A) -| (B);
        \draw[->, green] (A) |- (B);
        
        
    \end{tikzpicture}
    
\end{document}
1
  • I know |- and -| but they don't solve my problem.
    – Rahn
    Jan 22, 2021 at 14:56

You must log in to answer this question.

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