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 want to create a blockdiagram using tikz. I would like to use "above of, below of, etc." to position my nodes in order to keep it as flexible as possible. I would no like to position a node D on right of A (same y) and above C (same X). However, the following example does not work as expected:

\documentclass{article}
\usepackage{tikz}   % library for drawings
\usetikzlibrary{positioning}

\begin{document}
\tikzstyle{block} = [draw, rectangle, 
  minimum height=3em, minimum width=4em]

 \begin{figure}
     \begin{tikzpicture}[auto, node distance=2cm,>=latex]
       \node [block] (a) {A};
       \node [block, below of=a] (b) {B};
       \node [block, right of=b] (c) {C};
       \node [block, above of=c, right of=a] (d) {D};
     \end{tikzpicture}
  \end{figure}
\end{document}

This is the generated output: enter image description here

I want D to be exactly over C and on the same height as A

Has same one an idea how to solve this, without introducting distances and coordinates?

share|improve this question
    
Perhaps you could the pdf output as it appears on your system as image. –  student Oct 30 '12 at 11:39
    
Each something of= overwrites the other as each sets the full anchor point. So you need to use a different mechanism for setting the points. –  Andrew Stacey Oct 30 '12 at 11:55
1  
Scratch that; each doesn't overwrite the other. What they do is add to each other, but each adds the full displacement. Intriguing. –  Andrew Stacey Oct 30 '12 at 12:01
    
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  hpesoj626 Oct 30 '12 at 12:55
add comment

1 Answer

up vote 10 down vote accepted

You should only use one above of=... so what you are trying to do is not in general possible with this syntax (though because of the regularity of the positions in your example then in fact above of=c would do, but I'll assume that this is a very simple example and that the real case is more complicated).

Probably the easiest way to get what you want is to use the (a -| c) syntax for specifying coordinates. This is a way of specifying the intersection of the horizontal line through (a) with the vertical line through (c). A more complicated (but flexible) example with the calc library loaded would use the let keyword as in \path let \p1=(a),\p2=(c) in (\x2,\y1) node [block] (d) {D};

Here's the simple version:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/79693/86}
\usepackage{tikz}

\begin{document}
\tikzstyle{block} = [draw, rectangle, 
  minimum height=3em, minimum width=4em]

 \begin{figure}
     \begin{tikzpicture}[auto, node distance=2cm,>=latex]
       \node [block] (a) {A};
       \node [block, below of=a] (b) {B};
       \node [block, right of=b] (c) {C};
        \node [block] (d) at (a -| c) {D};
     \end{tikzpicture}
  \end{figure}
\end{document}

Note that because you are using above of=... rather than above=of ..., the positioning library isn't needed. Note that =of and of= are not synonymous.

The result of the above is:

node positioning

share|improve this answer
    
Works perfectly! Thanks a lot! –  vipers36 Oct 30 '12 at 12:18
add comment

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.