10

I am new to tikz. If I have two nodes [A] and [B] as:

[A]

       [B]

How do I align [C] so that it is vertically below [A] and horizontally left of [B] such that:

[A]

[C]    [B]

without resorting to absolute positioning?

Werner
  • 603,163
Mobius Pizza
  • 2,326

2 Answers2

11
\documentclass[11pt]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node (a) at (0,0){[A]};
\node (b) at (5,-4){[B]};  
\node (c) at (a|-b){[C]};
\end{tikzpicture}
\end{document} 
Alain Matthes
  • 95,075
6

You can use relative positioning (§ 3.8; TIKZ & PGF Manual, v. 2.10).

 \documentclass{article}
 \usepackage{tikz}
 \begin{document}
 \begin{figure}
 \centering
 \begin{tikzpicture}[auto]
 \node [draw] (a) {A};
 \node [draw, below of=a] (c) {C};
 \node [draw, right of=c] (b) {B};
 \end{tikzpicture}
 \end{figure}
 \end{document}

enter image description here

badroit
  • 7,557
  • 1
    No, if you need to place C after A and B. And in the question you need to place C after A and B. Another problem with this method appears with scale=.... – Alain Matthes Dec 12 '11 at 21:50
  • 1
    Not sure why you would need to place C after A and B, and not sure that the question implies that need. (The question does state the preference to avoid absolute positioning, and hence I still prefer my answer :P.) – badroit Dec 12 '11 at 21:58
  • The question begins with If I have two nodes [A] and [B] Your method is correct in multiple cases like graphs in the tutorials of the pgfmanual, personally I tried to avoid it in the geometric pictures because it' s difficult to scale the result. – Alain Matthes Dec 12 '11 at 22:37
  • 1
    You could do below right=of... with the positioning library if you set node distance=x<dimen> and y<dimen> to the surrounding scope/tikzpicture. – morbusg Dec 13 '11 at 16:08