# How to set the row height to equal to the column width of X in the tabularx environment?

Within the tabularx environment, X is a particular width which allows the table to fit the width of the specified horizontal space. I want to create a table which has square cells.

• How can I set the height of a particular row within a table to be the same length as the value of X?
-
Do you really have to use for X here? If you want the cells to be square and you know the table width and how many columns you have you could save TeX an awful lot of work and just tell it the width (or not use a table at all and just make a row of square boxes –  David Carlisle Jul 20 '12 at 9:35

If you can't, for some reason, follow David Carlisle's excellent advice, you can use a strut:

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{|X|X|X|X|}
\hline
\rule{0.0pt}{\linewidth}
& \rule{0.0pt}{\linewidth}
& \rule{0.0pt}{\linewidth}
& \rule{0.0pt}{\linewidth}\\
\hline
\rule{0.0pt}{\linewidth}
& \rule{0.0pt}{\linewidth}
& \rule{0.0pt}{\linewidth}
& \rule{0.0pt}{\linewidth}\\
\hline
\end{tabularx}
\end{document}


with this result:

Note that this doesn't solve any problems you may encounter trying to position text in these boxes. TikZ would probably give you a better answer for that.

Alternatively, following Stephan Lemke's much better suggestion, you can use a parbox:

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{|X|X|X|}
\hline
\parbox[b][\linewidth][t]{\linewidth}{Top Top Top Top Top Top Top Top}
& \parbox[b][\linewidth][c]{\linewidth}{Middle Middle Middle Middle }
& \parbox[b][\linewidth][b]{\linewidth}{Bottom Bottom Bottom Bottom }\\
\hline
\parbox[b][\linewidth][t]{\linewidth}{Top}
& \parbox[b][\linewidth][c]{\linewidth}{Middle}
& \parbox[b][\linewidth][b]{\linewidth}{Bottom}\\
\hline
\end{tabularx}
\end{document}


with this result:

-
Well replacing the rules by parboxes (which allow to set the box height) would probably solve the text positioning issue. –  Stephan Lehmke Jul 20 '12 at 11:07
@StephanLehmke: Thanks for that suggestion; much better than my original. I've taken the liberty of incorporating it into an alternative solution. –  Brent.Longborough Jul 20 '12 at 11:44