1

Suppose I have two tables next to one another, with a different number of rows, and also different heights in the body cells like this:

\documentclass{article}
\begin{document}
\begin{table}
\begin{tabular}[t]{c c}
  \hline  
  hello & world\\
  \hline  
  a \\
  b \\
  c \\
  d \\
  \hline
\end{tabular}
\begin{tabular}[t]{c c}
  \hline
  lorem & ipsum\\
  \hline  
  $A_{\left(1\right)}^2$ \\
  $B_{\left(2\right)}^2$ \\
  $C_{\left(3\right)}^2$ \\
  \hline  
\end{tabular}
\end{table}
\end{document}

Now, I'd like to have it such that the lines in the body of the right table are spread out so that the bottom lines of the two tables line up perfectly, while still keeping the top and bottom lines of the first row aligned as well.

I've tried playing with \arraystretch and other things, but of course, I can never have both at the same time.

Any suggestions on how to monkeypatch the spacing of a table in such a way would be highly appreciated!

3
  • putting some \vspace in the cells?
    – Plergux
    Oct 13 '20 at 18:48
  • sounds good, but how can I (programmatically) figure out what is the correct amount of vspace to put? I don't want to have to fiddle with the numbers manually too much (it's a long table)
    – carsten
    Oct 13 '20 at 18:56
  • 1
    Make a single tabular with an empty column in between the left and right parts of this tabular.
    – Bernard
    Oct 13 '20 at 19:56
2

You can use the tabularht package which allows you to specify the desired table height and to add extra space between rows:

\documentclass{article}
\usepackage{tabularht}
\begin{document}
\begin{table}
  \begin{tabularht}{1in}{cc}
  \hline  
  hello & world\\
  \hline
  \interrowfill
  a \\
  \interrowfill
  b \\
  \interrowfill
  c \\
  \interrowfill
  d \\
  \interrowfill
  \hline
\end{tabularht}
\begin{tabularht}{1in}{cc}
  \hline
  lorem & ipsum\\
  \hline  
  \interrowfill
  $A_{\left(1\right)}^2$ \\
  \interrowfill
  \
  $B_{\left(2\right)}^2$ \\
  \interrowfill
  $C_{\left(3\right)}^2$ \\
  \interrowfill
  \hline  
\end{tabularht}
\end{table}
\end{document}

The result: enter image description here

1

Apparently you can calculate the height of objects (found here: https://stackoverflow.com/questions/2939450/get-height-on-a-block-of-latex-output) And so you could calculate the height of the tables, and divide the remainder onto the rows in the smaller table:

\documentclass{article}

\begin{document}

\section{Table measurements}

\newdimen\height
\setbox0=\vbox{
\begin{tabular}{c}
    \hline
    a \\
    \hline
    b \\
    c \\
    d \\
    \hline
\end{tabular}
}

\height=\ht0 \advance\height by \dp0
The height is: \the\height

\newdimen\height
\setbox0=\vbox{
\begin{tabular}{c}
    \hline
    A \\
    \hline
    B \\
    C \\
\end{tabular}
}
\height=\ht0 \advance\height by \dp0
The height is: \the\height

\section{The Tables}

\begin{tabular}{c}
    \hline
    a \\
    \hline
    b \\
    c \\
    d \\
    \hline
\end{tabular}
\begin{tabular}{c}
    \hline
    A \\
    \hline
    B \\
    C \\
    \hline
\end{tabular}

\section{Corrected table}

\begin{tabular}{c}
    \hline
    a \\
    \hline
    b \\
    c \\
    d \\
    \hline
\end{tabular}
\begin{tabular}{c}
    \hline
    A \vspace{4pt} \\
    \hline
    B \vspace{4pt} \\
    C \vspace{4pt} \\
    \hline
\end{tabular}

\end{document}

You would have to count the rows in the shorter table and divide, but at least you wouldn't have to fiddle with each and every row.

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.