# Two tabular environments where the first columns are supposed to have the same width

Right now I'm using the following tabular environment (which I got from here) so that the compactitem inside the table looks good.

\begin{tabular}{@{}l p{10cm}}
blub & \textbf{longer longer longer text}
.
.
.
\end{tabular}

But a little below this table and below another headline, I want to use the same kind of tabular environment again. If I naively just do this, of course it won't have the same column widths as the first table, since the widest text in the first column seems to determine its width. How can I make it so that the second tabular environment copies the width ratio from the first one, if there is any way at all?

• Use p{<length>} also for the first column. – egreg Oct 10 '13 at 13:22
• @egreg: Hum, so is there a way to figure out the width the first column in my document currently has? Since I want the second tabular to copy the width of the first one, but not necessarily by changing the width of the first table and then using the same value. – InvisiblePanda Oct 10 '13 at 13:25
• What if the second table has items wider than those in the first table? – egreg Oct 10 '13 at 13:27
• @egreg: They are strictly smaller by the nature of these two tables ;-) But I guess I'm just going to measure the widths of the first table and then set this specific value. Thanks! – InvisiblePanda Oct 10 '13 at 13:29
• The eqparbox package may be relevant here. – user4686 Oct 10 '13 at 13:52

Here's a trick for this particular case:

\documentclass{article}
\usepackage{environ}
\newdimen\nexttablewd
\newbox\nexttablebox
\NewEnviron{rtabular}[2][c]{%
\setbox\nexttablebox=\vbox{
\renewcommand\\[1][]{\cr}
\halign{##\unskip\hfil&\vbox{##}\cr\BODY\crcr}
\setbox\nexttablebox=\lastbox
\setbox\nexttablebox=\hbox{\unhbox\nexttablebox\setbox\nexttablebox=\lastbox\unskip\setbox\nexttablebox=\lastbox}
\global\nexttablewd=\wd\nexttablebox
}%
\begin{tabular}[#1]{#2}\BODY\end{tabular}
}

\def\zz{some text }\def\zzz{\zz\zz\zz\zz\zz}

\begin{document}
\begin{rtabular}{lp{5cm}}
something & \zzz \\
else & \zzz
\end{rtabular}

\bigskip

\begin{tabular}{p{\nexttablewd}p{5cm}}
what  & \zzz \\
is    & \zzz \\
this? & \zzz
\end{tabular}

\end{document}

Once you have set a two column rtabular environment, the width of its first column is available in the parameter \nexttablewd.

This is obtained by building the first table in a protected environment, then dismantling its last row and getting the width of the first box in it. It could be generalized to tables with more columns.

• The eqparbox package may be relevant here – user4686 Oct 10 '13 at 13:53