I am translating HTML-tables to latex counterparts.
In HTML, I have a table with full width that distributes the column according to their content.
So this leads to equally spaced columns,
<table style="width: 100%;">
<tr>
<td>a</td>
<td>a</td>
</tr>
</table>
whereas this assigns 4 times as much space to the left column:
<table style="width: 100%;">
<tr>
<td>aaaa</td>
<td>a</td>
</tr>
</table>
See also here for a nested example: https://jsfiddle.net/49nhmqLu/1/
tabularx
I have found that for tabularx
an X
column takes the remaining space:
\begin{tabularx}{\textwidth}{lX}
but there multiple X
-columns would distribute the width equally, not as needed by the content. (XX
would be 50:50, XXX
would be 33:33:33)
My question: Is it possible to have a column type that distributes width relatively to the content? like my aaaa - a
(i.e. 80:20 here) example?
Additional requirement
Actually, the content of the tabular cells may itself consist of tabularx
's 🙈. So I have found that tabularx-in-tabularx seems to be impossible.
If I use outer tabulars
, i can only arrive at full textwidth by having minipages inside:
If I do not insist on the content-aware column widths, I can use tabular
outside and use minipages
with fixed widths (eg two columns with .47\textwidth
each) inside.
\begin{tabular}
\begin{minipage}[t]{0.47\columnwidth}
left outer
\end{minipage} &
\begin{minipage}[t]{0.47\columnwidth}
\begin{tabularx}{\textwidth}{lX}
inner left &
inner right
\end{tabularx}
\end{minipage}
\\
\end{tabular}
I am absolutely clueless how to get an automatic width distribution to work here, the latter example will always be 50:50.
Note that I am not insiting on an outer tabular. Anything else that distributes with according to content is fine as well. In HTML one could use e.g. <div>
's here
In the best case there would exist an environment tabularxyz
which allows:
\begin{tabularxyz}
left outer
&
\begin{tabularx}{\textwidth}{lX}
inner left &
inner right
\end{tabularx}
\\
\end{tabularxyz}
where Latex determines the optimal width for all columns, just as tabulary
does this (but only for plain text contents).
The nested tabularx
's are the result of a placeholder substitution from my reporting software. Most of the time, they are even just used without a surrounding table. I use tabularx because it allows to use full available textwidth.
tabular
environment.tabulary
package.tabulary
.