3

I've learned these tricks:

\draw (X) -- ++(1,1);        % relative positioning
\draw (X) -- (P1 |- P2);       
% intersecting coordinates: the x-coordinate of P1 and the y-coordinate of P2

Is there a way to replace P1 in the second \draw command above with something that designates the current position?

Similar complete example:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[font=\sffamily]

\node[draw, circle](C1) at (2,2){Hey dude!};
\node[draw, circle](C2) at (3,4){C2};
\draw[thick] (C1.east) -- ++(1,1) -- (4,0 |- C2.south);

\coordinate(X) at ($(C1.east) + (1,1)$);
\draw[red,thick](X) -- (X |- C2.south);
\end{tikzpicture}
\end{document}

enter image description here

The red vertical line is what I want (but I had to manually calculate it and define a coordinate); the black diagonal line next to it is the line drawn by -- (4,0 |- C2.south) and I want to replace 4,0 with something representing the current position.

4

You know how to use coordinates. So you could just say \draw[thick] (C1.east) -- ++(1,1) coordinate (y) -- (y |- C2.south);. I left the red line in the code as thin and dashed for comparison.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[font=\sffamily]

\node[draw, circle](C1) at (2,2){Hey dude!};
\node[draw, circle](C2) at (3,4){C2};
\draw[thick] (C1.east) -- ++(1,1) coordinate (y) -- (y |- C2.south);

\coordinate(X) at ($(C1.east) + (1,1)$);
\draw[red,thin, dashed](X) -- (X |- C2.south);
\end{tikzpicture}
\end{document}

enter image description here

  • what does the coordinate (y) do? I don't understand. – Jason S Apr 27 '16 at 19:54
  • 1
    I am just assigning to the relative point (C1.east) -- ++(1,1) the coordinate (which is just a node without physical size) of name y. Then I am able to reference this point afterwards. You make use of this by calculating the coordinate at the intersection (y |- C2.south). Basically I do nothing else than you, when you say \coordinate(X) at ($(C1.east) + (1,1)$); \draw[red,thin, dashed](X) -- (X |- C2.south); but in a little different syntax being more compact. – JMP Apr 27 '16 at 19:59

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.