I'm in a situation where I have two tables, and for space reasons I need to show them beside each other. Most entries to each column of the table are short, but occasionally one is long.
What I'd like is to specify the width of the table, and if a row can't be fit into that width, it's broken up into two lines.
The tricky bit is that sometimes the cells contain math that can't easily be broken up, so in such cases, I'd like to allow the long math to go past the width of its column, and put the remaining columns of the row one line below, so the text doesn't overlap.
This answer suggests that tabularx might be helpful, but I'm not sure how to allow things to go past their columns.
Is this possible? Is there a way to put two tables side-by-side and handle long rows gracefully, without having to manually adjust the offending rows?
I've got a MWE below with two versions. The first is what I'm starting with, tabulars with minipages, and they just spill over.
The second is roughly what I want my result to look like. The biggest things I'm wondering are:
- Is there a way to achieve this automatically, i.e. without manually splitting things onto multiple lines and using
mathrlap
or such? - Why is there extra vertical space in the
tabularx
version? Where do I need to putX
in the layout specification to properly convert from tabular to tabularx?
Here's the code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
\begin{minipage}{0.48\textwidth}
\begin{tabular}{@{}l@{}l@{\ \ }c@{\ \ }ll@{}llll@{}}
\\ & & $\mid$ & $loooooonnnnngggg$ & & $info$ & $Comment$
\\ & & $\mid$ & $info$ & & $info$ & Long long long long comment
\\ & & $\mid$ & $info$ & & $info$ & $Comment$
\end{tabular}
\end{minipage}
\begin{minipage}{0.48\textwidth}
\begin{tabular}{@{}l@{}l@{\ \ }c@{\ \ }ll@{}llll@{}}
\\ & & $\mid$ & $info$ & & $info$ & $Comment$
\\ & & $\mid$ & $info$ & & $info$ & $Comment$
\\ & & $\mid$ & $info$ & & $info$ & $Comment$
\end{tabular}
\end{minipage}
\begin{minipage}{0.48\textwidth}
\begin{tabularx}{\textwidth}{@{}l@{}l@{\ \ }c@{\ \ }ll@{}XXXX@{}}
\\ & & $\mid$ & $\mathrlap{loooooonnnnngggg}$ & & &
\\ & & & & & $info$ & $Comment$
\\ & & $\mid$ & $info$ & & $info$ & Long long long long comment
\\ & & $\mid$ & $info$ & & $info$ & $Comment$
\end{tabularx}
\end{minipage}
\begin{minipage}{0.48\textwidth}
\begin{tabular}{@{}l@{}l@{\ \ }c@{\ \ }ll@{}llll@{}}
\\ & & $\mid$ & $info$ & & $info$ & $Comment$
\\ & & $\mid$ & $info$ & & $info$ & $Comment$
\\ & & $\mid$ & $info$ & & $info$ & $Comment$
\end{tabular}
\end{minipage}
\end{document}
\\
at the start of every row as it forces a blank line at the start,\\
ends a row. – David Carlisle Apr 7 '18 at 0:10