# How can I align two nodes to the left in TikZ?

I have two unaligned nodes

|AAAAAAA|

|B|


and I want to have the node with the B aligned to the left of the node with AAAs and below it

|AAAAAAA|

|B|


How can this be done?

-
Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. – Martin Scharrer Mar 16 '11 at 20:56
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count. This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). Otherwise please state what is missing so that people can help you better. – Martin Scharrer Dec 7 '11 at 10:05

Use anchor=west for both nodes. For example:

\begin{tikzpicture}
\node[anchor=west] (1) at (0,1) {AAAAAAAA};
\node[anchor=west] (2) at (0,0) {B};
\end{tikzpicture}

-
Thanks, I understand now: you are placing the west anchors of two nodes at two vertically aligned points. That does the trick, the only limitation is that if the top node increases its heigth you have to move the point of the second node further below. To avoid this the second node could be placed using "below=of 1.south west". – Mário Mar 17 '11 at 9:42
Yes, I agree that Martin's solution (inlcuding node distance) is more flexible. – Michael Ummels Mar 17 '11 at 10:14

You can position "B" below and left of "AAA" without having to know the position of it using the positioning library:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
\node [draw] (A) at (4,5) {AAAA};
\node [draw,below=of A.west,anchor=west] (B) {B};
\end{tikzpicture}
\end{document}


Gives:

-
Note that you can change the distance by adding a value before of, e.g. below=2cm of A. – Martin Scharrer Mar 16 '11 at 22:29
Thanks, your examples helped me to understand the workings of anchor: it makes a node's anchor point (north, east, ...) coincide with the node's position point (defined with "at (x,y)", "below=of p", etc). – Mário Mar 17 '11 at 9:33
For example, using \begin{tikzpicture}[node distance=5mm] \node[draw, anchor=west] (1) {AAAAAAAA}; \node[draw, below=of 1.south west, anchor=north west] (2) {B}; \end{tikzpicture} we can left align the two nodes and have a precise distance of 5mm between them. Thanks a lot. @MichaelUmmels – Mário Mar 17 '11 at 9:49
Important note: one must use below=of A.west, anchor=west (which is what Martin has written) not anchor=west, below=of A.west (which looks just as good, but seems not to work). – John Wickerson Mar 13 '15 at 15:22

If you want to scale the picture, you need to use the Michael's solution and if you don't need to scale the picture you can use the Martin's solution.

-
You can scale my solution by putting it in a \scalebox. – Martin Scharrer Mar 16 '11 at 22:29
@Martin yes I know but I can't do that because if you scale the picture with a \scalebox, you scale the text inside the nodes and you need to avoid this. – Alain Matthes Mar 17 '11 at 5:50
@Martin I think the only solution with positioningis to use node distance=... to adapt the distance between nodes – Alain Matthes Mar 17 '11 at 6:31
Yes, node distance is the way to go. I don't know why scale doesn't affect it. – Martin Scharrer Mar 17 '11 at 10:00
@Martin : I know the problem with this method because in my package "tkz-graph" (very soon on ctan), I used positioningin a first time and then I discover the problem with scale. I changed all the methods to place the vertices. – Alain Matthes Mar 17 '11 at 10:45