I'm trying to create a diagram and would like my nodes left aligned using the anchor=west
option. I'd prefer to use relative positioning to make my diagram more flexible to changes. Here's my example:
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[%
every node/.style = {anchor=west}]
\node[fill=red!40, draw] (n0) at (0,0) {Base node} ;
\node[fill=red!40, draw] (n1) at (0,-2) {Node with longer text} ;
\node[fill=red!40, draw] (n2) [below=of n1] {Node with even longer text} ;
\end{tikzpicture}
\end{document}
Notice how the second node uses the anchor=west
style set for every node, but the third node with the longest text seems to be centered below the second vs. being left aligned with it. Is there a way to accomplish what I'm looking for?
Essentially, I want the alignment of the second node without having to specify absolute coordinates.
Best Answer
try this
from de pgfmanual:
16.5.2 Basic Placement Options
Unfortunately, while perfectly logical, it is often rather counter-intuitive that in order to place a node above a given point, you need to specify the south anchor. For this reason, there are some useful options that allow you to select the standard anchors more intuitively:
/tikz/above
(default 0pt)Does the same as anchor=south. If the is specified, the node is additionally shifted upwards by the given .
/tikz/below=<offset>
(default 0pt) Similar to above./tikz/left=<offset>
(default 0pt) Similar to above./tikz/right=<offset>
(default 0pt) Similar to above.