I have two parallel tables not equal in height. I'd like to set \bottomrule of the shorter left table to the same height as the right one. Is this even possible without rearranging the rows? Using \vspace{} is one approach I tried, but it's too tricky. So I asked myself if there is a better solution?

\documentclass{article}

\usepackage{ragged2e, tabularx, makecell, booktabs}

\newcommand\mc[1]{%
    \multicolumn{1}{c}{#1}}

\renewcommand\tabularxcolumn[1]{%
    >{\RaggedRight}m{#1}}

\begin{document}

\begin{table}[!htb]\centering\small\setlength{\extrarowheight}{2pt}
    \caption{Two uneven parallel tables.\label{tab:test}}
    \begin{tabularx}{.45\columnwidth}[t]{XX}
        \toprule
            \mc{Column1} & \mc{Column2} \\
        \midrule
            Row 1 & Row 1 \\
            Row 2 & Row 2 \\
            Row 3 & Row 3 \\
            Row 4 & Row 4 \\% \vspace{3.05pt} \\
        \bottomrule
    \end{tabularx}
    \begin{tabularx}{.45\columnwidth}[t]{XX}
        \toprule
           \mc{Column1} & \mc{Column2} \\
        \midrule
            Row 1 & \makecell[l]{Row 1 with \\ line break} \\
            Row 2 & Row 2 \\
            \makecell[l]{Row 2 with \\ line break} & Row 2 \\
        \bottomrule
    \end{tabularx}
\end{table}

\end{document}
  • 1
    (1) welcome (2) wjy make it as two tables, and not just one, and then use a black column between the two parts and use \cmidrule for the lines? – daleif Aug 10 at 12:07
  • This is just a snippet. It's a bigger table with text above and underneath. I divided it so it doesn't take too much vertical space. – pCC Aug 10 at 12:12
up vote 3 down vote accepted

You can \hbox the two tables up and then display them in two tables which add the contents of the other table as a \vphantom and below that a \bottomrule. Note that you should not use \bottomrule in both tables, it's added automatically.

\documentclass{article}

\usepackage{ragged2e, tabularx, makecell, booktabs}

\newcommand\mc[1]{%
    \multicolumn{1}{c}{#1}}

\renewcommand\tabularxcolumn[1]{%
    >{\RaggedRight}m{#1}}

\newsavebox\resizeboxA
\newsavebox\resizeboxB
\newcommand\BottomRuleAligned
  {%
    \begingroup
    \def\additionalspace{\noalign{\vfill}}%
    \setbox\resizeboxA\hbox\bgroup
      \ignorespaces
  }
\newcommand\EndFirstTable
  {%
      \ifhmode\unskip\fi
    \egroup
    \setbox\resizeboxB\hbox\bgroup
      \ignorespaces
  }
\newcommand\EndSecondTable
  {%
      \ifhmode\unskip\fi
    \egroup
    \begin{tabular}[t]{@{}l@{}}
      \vphantom{\usebox\resizeboxB}\usebox\resizeboxA\\
      \bottomrule
    \end{tabular}%
    \BottomRuleAlignedTableSep
    \begin{tabular}[t]{@{}l@{}}
      \vphantom{\usebox\resizeboxA}\usebox\resizeboxB\\
      \bottomrule
    \end{tabular}%
    \endgroup
  }
\newcommand\BottomRuleAlignedTableSep{\hskip1em}


\begin{document}

\begin{table}[!htb]\centering\small\setlength{\extrarowheight}{2pt}
    \caption{Two uneven parallel tables.\label{tab:test}}
    \BottomRuleAligned
      \begin{tabularx}{.45\columnwidth}[t]{XX}
          \toprule
              \mc{Column1} & \mc{Column2} \\
          \midrule
              Row 1 & Row 1 \\
              Row 2 & Row 2 \\
              Row 3 & Row 3 \\
              Row 4 & Row 4 \\% \vspace{3.05pt} \\
      \end{tabularx}
    \EndFirstTable
      \begin{tabularx}{.45\columnwidth}[t]{XX}
          \toprule
             \mc{Column1} & \mc{Column2} \\
          \midrule
              Row 1 & \makecell[l]{Row 1 with \\ line break} \\
              Row 2 & Row 2 \\
              \makecell[l]{Row 2 with \\ line break} & Row 2 \\
      \end{tabularx}
    \EndSecondTable
\end{table}

\end{document}

enter image description here

EDIT: Same vertical above the table as a single \begin{tabularx} has and horizontal spacing reduced to just a space. Now you shouldn't use \toprule and \bottomrule as both are added automatically (this fixes your spacing difference):

\documentclass{article}

\usepackage{ragged2e, tabularx, makecell, booktabs}

\newcommand\mc[1]{%
    \multicolumn{1}{c}{#1}}

\renewcommand\tabularxcolumn[1]{%
    >{\RaggedRight}m{#1}}

\newsavebox\resizeboxA
\newsavebox\resizeboxB
\newcommand\BottomRuleAligned
  {%
    \begingroup
    \def\additionalspace{\noalign{\vfill}}%
    \setbox\resizeboxA\hbox\bgroup
      \ignorespaces
  }
\newcommand\EndFirstTable
  {%
      \ifhmode\unskip\fi
    \egroup
    \setbox\resizeboxB\hbox\bgroup
      \ignorespaces
  }
\newcommand\EndSecondTable
  {%
      \ifhmode\unskip\fi
    \egroup
    \begin{tabular}[t]{@{}l@{}}
      \toprule
      \vphantom{\usebox\resizeboxB}\usebox\resizeboxA\\
      \bottomrule
    \end{tabular}%
    \BottomRuleAlignedTableSep
    \begin{tabular}[t]{@{}l@{}}
      \toprule
      \vphantom{\usebox\resizeboxA}\usebox\resizeboxB\\
      \bottomrule
    \end{tabular}%
    \endgroup
  }
\newcommand\BottomRuleAlignedTableSep{\space}


\begin{document}

\begin{table}[!htb]\centering\small\setlength{\extrarowheight}{2pt}
    \caption{Two uneven parallel tables.\label{tab:test}}
    \BottomRuleAligned
      \begin{tabularx}{.45\columnwidth}[t]{XX}
              \mc{Column1} & \mc{Column2} \\
          \midrule
              Row 1 & Row 1 \\
              Row 2 & Row 2 \\
              Row 3 & Row 3 \\
              Row 4 & Row 4 \\% \vspace{3.05pt} \\
      \end{tabularx}
    \EndFirstTable
      \begin{tabularx}{.45\columnwidth}[t]{XX}
             \mc{Column1} & \mc{Column2} \\
          \midrule
              Row 1 & \makecell[l]{Row 1 with \\ line break} \\
              Row 2 & Row 2 \\
              \makecell[l]{Row 2 with \\ line break} & Row 2 \\
      \end{tabularx}
    \EndSecondTable
\end{table}

\end{document}

enter image description here

  • This solution worked for me, thanks! But there is a bit more space between the caption and the table now, at least in my document. Can't tell exactly why. – pCC Aug 10 at 13:35
  • 1
    @pCC I fixed the spacing. – Skillmon Aug 10 at 13:58
  • 1
    @pCC appreciation is usually expressed in votes (and accepting the most helpful answer -- which you fortunately already did). – Skillmon Aug 10 at 14:24

Since you load makecell, we can have different values of \arraystretch for the column heads and the rest of the tables, so here is a solution playing with \arraystretch:

\documentclass{article}

\usepackage{ragged2e, tabularx, makecell, booktabs}
\usepackage{setspace}

\renewcommand\tabularxcolumn[1]{>{\RaggedRight}m{#1}}

\begin{document}

\begin{table}[!htb]\centering\small\setlength{\extrarowheight}{2pt}
\renewcommand{\theadfont}{\normalsize}
\renewcommand{\theadset}{\renewcommand{\arraystretch}{0.3}}%{\setstretch{0.3}}%
    \caption{Two uneven parallel tables.\label{tab:test}}
   \begingroup\renewcommand{\arraystretch}{1.097}
   \begin{tabularx}{.45\columnwidth}[t]{XX}
\toprule
\thead{Column 1} & \thead{Column 2} \\[-1pt]
\midrule
            Row 1 & Row 1 \\
            Row 2 & Row 2 \\
            Row 3 & Row 3 \\
            Row 4 & Row 4 \\% \vspace{3.05pt} \\
        \bottomrule
    \end{tabularx} \endgroup
    \begin{tabularx}{.45\columnwidth}[t]{XX}
\toprule
\thead{Column 1} & \thead{Column 2} \\
\midrule
            Row 1 & \makecell[l]{Row 1 with \\ line break} \\
            Row 2 & Row 2 \\
            \makecell[l]{Row 2 with \\ line break} & Row 2 \\
        \bottomrule
    \end{tabularx}
\end{table}

\end{document} 

enter image description here

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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