3

As part of a larger display, I am placing two tabular environments together, one above the other. These two environments are going to appear in one column of a larger tabular, and I want the two environments to have the same width. I would prefer not to use tabular*, because I don't want to have to guess the width and keep adjusting it as the contents change.

I tried setting them in a single tabular, but then both columns got too wide, making the total both too wide and unpleasant to read. In other words, it won't do have both tables share a first column, because that column will be too wide for the first table to be readable. And they can't share a second column, because the second table won't really have room for a second column of that width.

However, if they have the same total width, everything should look good. But I don't know how to find that total width other then playing guessing games with tabular* and explicit widths.

Is there a way to change the following MWE so that the second table is set to the width of the first table? (With suitable \extracolsep).

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\thispagestyle{empty}
\begin{center} 

\begin{tabular}[t]{@{}l@{}}
\begin{tabular}{@{}ll@{}}
\multicolumn2{c}{(a) Names}\\[\medskipamount]
\toprule
$x, f$&Name of a variable (or function)\\
$X$& Name of a module\\
$K$& Name of a value constructor\\
$t$& Name of a type\\
$T$& Name of a module type\\
\bottomrule
\end{tabular}
\\
\begin{tabular}{@{}ll@{}}
\strut\\
\multicolumn2{c}{(b) Declarations in the theory}\\[\medskipamount]
\toprule
\mbox{(abstype $t$)}&$t :: *$ or $t :: * \mathrel @ \pi$\\
\mbox{(type $t$ $\tau$)}&$t = \tau$\\
\mbox{(val $x$ $\tau$)}&$x : \tau$\\
\bottomrule
\end{tabular}
\end{tabular}
\end{center}
\end{document}

example of two tables

  • Similar question: Table with two tabulars of different width – leandriis Sep 18 at 16:24
  • @leandriis Thanks for the pointer (search didn't turn that one up), but that doesn't solve the problem. (You'll note that the answer to that question still exhibits the problem I'm trying to solve.) – Norman Ramsey Sep 18 at 17:34
2

I'd set the captions and the rules in the outer (main) tabular and use two inner tabulars for the actual data:

enter image description here

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{@{} l @{}}
  \multicolumn{1}{@{} c @{}}{(a) Names} \\[\medskipamount]
  \toprule
  \begin{tabular}{@{} l l @{}}
    $x, f$ & Name of a variable (or function) \\
    $X$    & Name of a module                 \\
    $K$    & Name of a value constructor      \\
    $t$    & Name of a type                   \\
    $T$    & Name of a module type
  \end{tabular} \\
  \bottomrule \\[\dimexpr-\normalbaselineskip+\bigskipamount]
  \multicolumn{1}{@{} c @{}}{(b) Declarations in the theory} \\[\medskipamount]
  \toprule
  \begin{tabular}{@{} l l @{}}
    (abstype $t$)     & $t :: *$ or $t :: * \mathrel{@} \pi$ \\
    (type $t$ $\tau$) & $t = \tau$                           \\
    (val $x$ $\tau$)  & $x : \tau$
  \end{tabular} \\
  \bottomrule
\end{tabular}

\end{document}
  • Oooh! Clever! Why didn't I think of that?? – Norman Ramsey Sep 18 at 17:35
2

REVISED: Here it is, WITHOUT tabular*.

I took the OP's MWE and enclosed the larger width tabular portion in its own sub-tabular, using \multicolumn to place it.

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\thispagestyle{empty}
\begin{center} 

\begin{tabular}[t]{@{}l@{}}
\begin{tabular}{@{}ll@{}}
\multicolumn2{c}{(a) Names}\\[\medskipamount]
\toprule
\multicolumn2{@{}c@{}}{\begin{tabular}{@{}ll@{}}
$x, f$&Name of a variable (or function)\\
$X$& Name of a module\\
$K$& Name of a value constructor\\
$t$& Name of a type\\
$T$& Name of a module type\\
\end{tabular}}\\
\bottomrule
\strut\\
\multicolumn2{c}{(b) Declarations in the theory}\\[\medskipamount]
\toprule
\mbox{(abstype $t$)}&$t :: *$ or $t :: * \mathrel @ \pi$\\
\mbox{(type $t$ $\tau$)}&$t = \tau$\\
\mbox{(val $x$ $\tau$)}&$x : \tau$\\
\bottomrule
\end{tabular}
\end{tabular}
\end{center}
\end{document}

enter image description here

2

With nested tabulars:

enter image description here

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\thispagestyle{empty}
\begin{center} 

\begin{tabular}{@{}ll@{}}
\multicolumn2{c}{(a) Names}\\[\medskipamount]
\toprule
$x, f$&Name of a variable (or function)\\
$X$& Name of a module\\
$K$& Name of a value constructor\\
$t$& Name of a type\\
$T$& Name of a module type\\
\bottomrule
\strut\\
\multicolumn2{c}{(b) Declarations in the theory}\\[\medskipamount]
\toprule
\multicolumn{2}{@{}l@{}}{\begin{tabular}{@{}ll@{}}
\mbox{(abstype $t$)}&$t :: *$ or $t :: * \mathrel @ \pi$\\
\mbox{(type $t$ $\tau$)}&$t = \tau$\\
\mbox{(val $x$ $\tau$)}&$x : \tau$\\
\end{tabular}}\\
\bottomrule
\end{tabular}
\end{center}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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