2

In my document I have a couple of tables that each have to columns. I'd like to make the first column of all tables the same width, and the second column of each table should consume the rest of the page.

The second requirement I could achieve with tabularx and using X. However, I do not know how I can make the first column of each table the same size without specifying an exact size. I do not want to specify an exact size since I want the first columns of all tables to have the minimal width that is necessary to display the longest text in the first column in any table. Is there any way to achieve that without specifying a concrete width?

2 Answers 2

1

I would like to add this as a comment, but I don't have the reputation for that. You could try it with ltxtable. It combines tabularx and longtable. You can use a longtable with the X column and you can use the \kill command of longtable. With it you can paste the longest first column in each table and then kill it. This row will not appear but it will still be used to measure the width of the table. Of course then other rows shouldn't be longer than the first row.

0

Here is a solution with nicematrix (≥ 6.25a). The package provides a mechanism in order to have all the columns of the tabulars (created by {NiceTabular} of nicematrix of the same width, except the X columns. That's what you need.

\documentclass{article}
\usepackage{geometry}
\usepackage{nicematrix}

\begin{document}

\begin{NiceMatrixBlock}[auto-columns-width]
\begin{center}
\begin{NiceTabular}{@{}lX}
1 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus rhoncus lectus ac odio ullamcorper dignissim.
In sed nibh sed velit volutpat pellentesque quis quis mauris \\
2 & Praesent dapibus gravida arcu lacinia efficitur. In in tortor ut purus egestas facilisis. Vivamus vitae tortor
eleifend, laoreet neque non, ultricies leo 
\end{NiceTabular}
\end{center}
Now, the second table:
\begin{center}
\begin{NiceTabular}{@{}lX}
12345678 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus rhoncus lectus ac odio ullamcorper dignissim.
In sed nibh sed velit volutpat pellentesque quis quis mauris \\
2 & Praesent dapibus gravida arcu lacinia efficitur. In in tortor ut purus egestas facilisis. Vivamus vitae tortor
eleifend, laoreet neque non, ultricies leo 
\end{NiceTabular}
\end{center}
\end{NiceMatrixBlock}

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .