TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 '14 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.