6
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[align=left, text ragged, transform shape]
  \matrix [matrix of math nodes, every node/.style={font=\ttfamily, scale = 1, inner sep = 10pt},
        column 1/.style={align=left},
        nodes={font=\ttfamily, draw, left, minimum height=3em},
        row 1/.style={nodes={align=center}},
        ]
  {
    AAAA & BBB & CCCCCC\\
    EE & F & GGG \\
    aaaaa & bbbbb & c\\
  };
\end{tikzpicture}
\end{document}

Each rectangular box around each cell is of different sizes because each cell has a different width and height. I would like the width of a cell to be the maximum width of the column(which is the width of the maximum cell in that column), similarly, for the height of a row. This way the rectangles are properly sized and centering the text works as expected.

I do not want to hardcode the sizes because I do not know beforehand what the will be and this might require tweaking to get it right... and would be a lot of work anyways.

Another example is from

Vertical align in tikz matrix

But in my case I would like the problem cell to actually expand the height of all other cells in the same row(so the 3rd row will have about 1.5(or whatever) the height of the other rows). Again, though, the values should be calculated automatically rather than trying to determine them by hand.

3
  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving problem. Commented Nov 23, 2012 at 8:10
  • you can use text width=\widthof{your longest text}.
    – Ignasi
    Commented Nov 23, 2012 at 9:01
  • @Ignasi That is known as hardcoding the value. Only slightly removed from saying text width=45em. Commented Nov 23, 2012 at 10:08

1 Answer 1

7

You can use the excellent matrixcells package that Andrew Stacey made available on launchpad:

\documentclass{article}
\usepackage{tikz, matrixcells}
\usetikzlibrary{matrix}
\begin{document}

\begin{tikzpicture}
  \matrix [
    matrix of nodes, 
    matrix grid,
    matrix border,
    nodes={font=\ttfamily}
]
  {
    AAAA & BBB & CCCCCC\\
    EE & F & GGG \\
    aaaaa & b & c\\
  };
\end{tikzpicture}
\end{document}
4
  • Thanks. One problem I seem to have is that the rows are bigger than they should. I'm including graphics in cells which may be the cause. Commented Nov 23, 2012 at 12:37
  • 1
    @JonSlaughter: Have you tried setting inner sep=0pt to remove the padding?
    – Jake
    Commented Nov 23, 2012 at 12:40
  • 1
    just did, used align=center, anchor=center, inner sep= 10pt to get looking proper. Thanks again. Commented Nov 23, 2012 at 12:41
  • How can I add these files (using MiKTeX on windows)?
    – soandos
    Commented Nov 13, 2013 at 17:41

You must log in to answer this question.

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