# Tikz and alignment with two nodes on the same line

Another minimal example:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\node[draw=black,%
rounded corners=2pt,%
rectangle,%
bottom color=black!80!white] (A) {node aligned on left margin};

\node[draw=black,%
rounded corners=2pt,%
rectangle,%
bottom color=black!80!white] {node aligned on the right margin};

\end{tikzpicture}
\end{document}


in this case I'd like to have the first node aligned on the left margin of the paper and the second one on the right.

-

I suggest you try it this way:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path (0,0) node[draw=black, rounded corners=2pt, rectangle, bottom color=black!80!white, anchor=west] (A) {node aligned on left margin} -- (\textwidth,0) node[draw=black, rounded corners=2pt, rectangle, bottom color=black!80!white, anchor=east] (B) {node aligned on the right margin};
\end{tikzpicture}
\end{document}


The nodes are on a path, which spans the width of the text on the page (\textwidth).

The anchors of the nodes are necessary to make sure the nodes do not get off the page.

-
Instead of anchor=west,anchor=east I find right,left to be more intuitive. –  Peter Grill Sep 28 '11 at 15:09