Discussion:
need to right justify tikz nodes ("east" anchor ingored)
(too old to reply)
Anonymous
2014-11-25 18:37:38 UTC
Permalink
This is roughly what I need:

===8<------------------------------
field1 field2
this is a lower text line that is longer than the above
===8<------------------------------

What's important is that the east of field2 is vertically aligned with
the east of the lower line. I know I could make this happen with one
large node, but I need 3 separate nodes so I can draw lines and
reference the positions of the text.

When I request that alignment, this is roughly what I get:

===8<------------------------------
field1 field2
this is a lower text line that is longer than the above
===8<------------------------------

What's wrong with this code?

===8<------------------------------
\documentclass{minimal}
\usepackage{tikz}

\usetikzlibrary{positioning}

\usepackage[pdftex,active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

\begin{tikzpicture}
\node (upr-fld-1) {field1};
\node [anchor=west] (upr-fld-2) [right =of upr-fld-1] {field2};
\node [anchor=north east] (lower) [below =of upr-fld-2.east] {%
this is a lower text line that is longer than the above};
\end{tikzpicture}

\end{document}
===8<------------------------------
Ulrike Fischer
2014-11-26 12:57:07 UTC
Permalink
Post by Anonymous
===8<------------------------------
field1 field2
this is a lower text line that is longer than the above
===8<------------------------------
What's important is that the east of field2 is vertically aligned with
the east of the lower line. I know I could make this happen with one
What's wrong with this code?
\node [anchor=west] (upr-fld-2) [right =of upr-fld-1] {field2};
\node [anchor=north east] (lower) [below =of upr-fld-2.east] {%
this is a lower text line that is longer than the above};
below sets the anchor of the node to north, so your anchor=north
east is ignored. You can either use below left (with an x-shifting
part of 0cm), or you can use yshift:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{positioning}

%\usepackage[pdftex,active,tightpage]{preview}
%\PreviewEnvironment{tikzpicture}

\begin{document}

\begin{tikzpicture}
\node (upr-fld-1) {field1};
\node [anchor=west] (upr-fld-2) [right =of upr-fld-1] {field2};
\node [below left= 1cm and 0cm of upr-fld-2.east] (lower) {%
this is a lower text line that is longer than the above};
\node [anchor=north east] (lower2) at
([yshift=-2cm]upr-fld-2.east) {%
this is a even more lower text line that is longer than the
above};

\end{tikzpicture}

\end{document}
--
Ulrike Fischer
http://www.troubleshooting-tex.de/
Anonymous
2014-11-26 17:56:49 UTC
Permalink
Post by Ulrike Fischer
below sets the anchor of the node to north, so your anchor=north
east is ignored. You can either use below left (with an x-shifting
Thanks Ulrike. I overcame my own problem by putting nodes in a \path,
as follows:

====8<----------------------------------
\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{positioning}

\usepackage[pdftex,active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\begin{tikzpicture}
\path node (upr-fld-1) {field1}
+(0,0) node [right=of upr-fld-1,anchor=east] (upr-fld-2) {field2}
+(0,0) node [below=of upr-fld-2.east,anchor=east] (lower) {%
this is a lower text line that is longer than the above}
+(0,0) node [below=of lower.east,anchor=east] (lower2) {%
this is a even more lower text line that is longer than the above};
\end{tikzpicture}
\end{document}
====8<----------------------------------

I'm disturbed that I had to use dummy coordinates "+(0,0)", which
were necessary to make the compiler continue. And making it a "path"
is non-intuitive.

So I like your solution better.

Loading...