Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I often find myself writing code like this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \node (aNodeWithALongName) at (1,1) {a};
  \node (bNodeWithALongName) at (1,-1) {b};
  \node (c) at (0,0) {c};

  \draw[->] (aNodeWithALongName) -- (aNodeWithALongName -| c);
  \draw[->] (bNodeWithALongName) -- (bNodeWithALongName -| c);
\end{tikzpicture}
\end{document}

I'm drawing a path, and need to use the first point's position to compute the second point, and I would like to avoid repeating the aNodeWithALongName, like this for example:

  \draw[->] (aNodeWithALongName) -- (current -| c);
  \draw[->] (bNodeWithALongName) -- (current -| c);

And more complex stuff:

  \draw[->] ($(aNodeWithALongName)!.5!(bNodeWithALongName)$) -- (current -| c);
  \draw[->] (bNodeWithALongName) -- ++(0, 1cm) -- (current -| c);

Is there a syntax similar to that which I could use?

share|improve this question
2  
You might be better off using a to path defined as \tikzset{my to/.style={to path={--(\tikztostart-|\tikztotarget)\tikztonodes}}} which you can use as \draw[->] (aNodeWithALongName) to[my to] (c);. See also Tikz: purely vertical arrow from nodeA.south to nodeB.north –  Qrrbrbirlbel Sep 12 '13 at 9:38

1 Answer 1

up vote 2 down vote accepted

I found a solution in this TeX-SX answer:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\newcommand\currentcoordinate{\the\tikz@lastxsaved,\the\tikz@lastysaved}
\makeatother
\begin{document}
\begin{tikzpicture}
  \node (aNodeWithALongName) at (1,1) {a};
  \node (bNodeWithALongName) at (1,-1) {b};
  \node (c) at (0,0) {c};

  \draw[->] (aNodeWithALongName) -- (\currentcoordinate -| c);
  \draw[->] (bNodeWithALongName) -- (\currentcoordinate -| c);

  \draw[->] ($(aNodeWithALongName)!.5!(bNodeWithALongName)$) -- (\currentcoordinate -| c);
  \draw[->] (bNodeWithALongName) -- ++(0, 1cm) -- (\currentcoordinate -| c);
\end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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