0

In the following MWE, the nodes in the matrix are not properly vertically aligned:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}[sibling distance=6mm,level distance=1.3cm,every node/.style={inner sep=4pt, text depth=0pt, minimum width=24mm,minimum height=24mm,align=center,inner sep=2pt}]

    \matrix [draw=red] {
    \node[draw=black, rectangle] {A}; & \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] {B\\ C\\ D}; & \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] {Bbbbbbbb\\ Cccccccc\\ Dddddddd};\\
    };
\end{tikzpicture}

\end{document}

enter image description here

It seems that the problem is introduced by the cylinder shape since the second cylinder is aligned worse than the second.

By the way, why is the cylinder's aspect dependent on the text it contains?

3
  • 1
    By default matrix nodes are aligned to its center. You can change this alignment with anchor option. \matrix[anchor=south] will align all nodes to their bottom point.
    – Ignasi
    Commented Nov 22, 2013 at 10:11
  • I'd also really like to know why the aspect changes based on the node's text, and how I could stop it from changing. Thoughts?
    – Adam Crume
    Commented Dec 8, 2013 at 19:41
  • @AdamCrume you should probably ask a new question for this, I doubt that people are going to see it here.
    – rainer
    Commented Dec 10, 2013 at 8:04

1 Answer 1

1

By default matrix nodes are aligned to its center. TiKZ offers anchor option to change matrix cells alignment. If you want to align all nodes to their bottom point, use \matrix[anchor=south].

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}[every node/.style={inner sep=4pt,% 
       text depth=0pt, minimum width=24mm,%
       minimum height=24mm, align=center, inner sep=2pt}]

    \matrix [draw=red] {
    \node[draw=black, rectangle] (a) {A}; & 
    \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] (b) {B\\ C\\ D}; 
  & \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] (c) {Bbbbbbbb\\ 
                    Cccccccc\\ Dddddddd};\\
    };
    \foreach \i in {a,b,c}
        \fill[red] (\i.center) circle(1pt);
    \draw[red] (a.center)--(b.center)--(c.center);

\begin{scope}[yshift=-5cm]

    \matrix [draw=red,anchor=south] {
    \node[draw=black, rectangle] (a) {A}; & 
    \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] (b) {B\\ C\\ D}; 
  & \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] (c) {Bbbbbbbb\\ 
                   Cccccccc\\ Dddddddd};\\
    };
    \foreach \i in {a,b,c}{
        \fill[red] (\i.center) circle(1pt);
        \fill[blue] (\i.south) circle(1pt);
    }
    \draw[red] (a.center)--(b.center)--(c.center);
    \draw[blue] (a.south)--(b.south)--(c.south);
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .