Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Encountering a strange issue here: I have a node style that I have been using for many flow-charts. It's base has always been in the exact center of the shape, but now i'ts been translated up about 1/4 toward the north anchor. The blue and red lines clearly show it's moved north, but the diamond's base is still in the exact center. What gives?

node base

\documentclass{article}

\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\pagestyle{empty}

\begin{document}

%\input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning, matrix}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, 
                        draw, 
                        text centered, 
                        minimum height=3em ,
                        minimum width = 6em,
                        inner sep = 5pt
                      ]
\tikzstyle{test}    = [ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 0pt,
                        text width = 7em,
                        text centered
                      ]
\tikzstyle{action}  = [ rectangle, draw,
                        text width=8em,
                        inner sep = 3pt, 
                        minimum height=5em
                      ]
\tikzstyle{data}    = [ trapezium, 
                        draw, 
                        trapezium left angle=60, 
                        trapezium right angle=120pt,
                        minimum height = 6em, 
                        text width = 5em,
                        inner xsep = 0pt
                       ]
\tikzstyle{line}    = [ draw, -triangle 45 ]

\tikzstyle{list}  = [ rectangle, draw,
                        minimum width = 6em                      
                      ]

\tikzstyle{ptr-box}  = [ rectangle, 
                        text width = 8em                      
                      ]

\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]

    \matrix [matrix of nodes, column sep = 1em, row sep = 2em,
                nodes={},
                ] (end-mtrx)
    {     
    |[action] (a)| Lorem ipsum dolor sit amet, consectetur adipiscing elit \\
    |[test] (b)| Lorem ipsum dolo  \\        
    |[test] (c)| Lorem ipsum  \\ 
    |[test] (d)| Lorem ipsum dolor & |[action] (e)| Lorem ipsum dolor sit amet, consectetur adipiscing elit \\
    |[state] (f)| Lorem ipsum d & |[state] (g)| Lorem ipsum dolor  & |[state] (bad-sd)| Lorem ipsum dolo\\
     };

     \path[draw, red, line width=5pt] (d.base) -- (e.base);

     \path[draw, blue, line width=5pt] (a.base) -- +(3,0);


\end{tikzpicture}
\end{center}
\end{document}
share|improve this question
    
.base denotes the baseline of the node, the first line's base to be exact. Try .center. –  Qrrbrbirlbel Sep 13 '12 at 19:34
    
Ok, well I'm more concerned with why the bases (which I believe is what a matrix of nodes uses to position them) of the action / rectangle are off. I want to figure out why they are not lining up like they used to (with the centers aligned). –  blitzvergnugen Sep 13 '12 at 19:37
1  
the base anchor will remain unaltered whether you have one line of text or add more lines of text in a node; in your case, it's not the base anchor that has shifted; the anchor remained unaltered, but you added more lines of text. –  Gonzalo Medina Sep 13 '12 at 19:39
    
So the node shifted down because I have more lines of text? I'm not understanding why that happened. I have a previous example of a regular matrix where I have a action & test (from my styles) side by side and their centers are on the same y-coordinate. –  blitzvergnugen Sep 13 '12 at 19:44
1  
Use nodes={draw,anchor=center} in the matrix specification to align them all. –  Qrrbrbirlbel Sep 13 '12 at 19:44

1 Answer 1

up vote 4 down vote accepted

The nodes normally align at their baseline.

You can shift that with the anchor key (section 16.5 "Positioning Nodes" of the PFG/TikZ manual).
I'd add anchor=center to the matrix specification:

\begin{tikzpicture}[align = flush center, font = \small]
    \matrix [matrix of nodes, column sep = 1em, row sep = 2em,
                nodes={anchor=center},
                ] (end-mtrx)
    {     
    |[action] (a)| Lorem ipsum dolor sit amet, consectetur adipiscing elit \\
    |[test] (b)| Lorem ipsum dolo  \\        
    |[test] (c)| Lorem ipsum  \\ 
    |[test] (d)| Lorem ipsum dolor & |[action] (e)| Lorem ipsum dolor sit amet, consectetur adipiscing elit \\
    |[state] (f)| Lorem ipsum d & |[state] (g)| Lorem ipsum dolor  & |[state] (bad-sd)| Lorem ipsum dolo\\
     };

     \path[draw, red, line width=5pt] (d.center) -- (e.center);
     \path[draw, blue, line width=5pt] (a.center) -- +(3,0);
     \path[draw, red,] (d.base) -- (e.base);
     \path[draw, blue,] (a.base) -- +(3,0);
\end{tikzpicture}

Output

output of example

share|improve this answer
    
Strange that I hadn't run into this before since I haven't had to add anchor=center to any of my previous charts. Oh well... Thanks! –  blitzvergnugen Sep 13 '12 at 19:52
1  
@blitzvergnugen If the nodes in a row have the same number of lines there is no difference in aligning. (The centers are at the same y-coordinate.) –  Qrrbrbirlbel Sep 13 '12 at 19:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.