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 have the following MWE:

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

    \begin{document}
      \begin{tikzpicture}
         \coordinate (a) at (0,0);
         \coordinate (b) at (1,-1);
         \newlength{\vsep}
         \setlength{\vsep}{0.5cm}
         \coordinate (abovea) at ($(a) + (0,\vsep)$);
         \coordinate (aboveb) at (b |- abovea);
         \node[fill=black,circle,inner sep=2pt] at (a) {};
         \node[fill=black,circle,inner sep=2pt] at (b) {};
         \draw (a) -- (abovea) -- (aboveb) -- (b);
    \end{tikzpicture}
   \end{document}

It's quit verbose just to connect the points A and B and I am wondering how I can simplify it ?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

In addition to the methods mentioned in Is there a TikZ equivalent to the PSTricks \ncbar command?, you could simplify your code to

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

\begin{document}
\begin{tikzpicture}
  \node[fill=black,circle,inner sep=2pt] (a) at (0,0) {};
  \node[fill=black,circle,inner sep=2pt] (b) at (1,-1) {};
  \draw (a) |- ($(a-|b) + (0,0.5cm)$) -- (b);
\end{tikzpicture}
\end{document}

Here, (a-|b) is the point that has the y-coordinate of a and the x-coordinate of b. Using |- instead of -- means, first move vertically to the y-coord of the second point, then horizontally to the point.

share|improve this answer
    
Two more options without using calc library: \draw (a) --++(90:.5)-|(b); or \draw(a) --([yshift=.5cm]a.center)-|(b);. –  Ignasi Jul 23 at 10:33

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.