1

From http://tug.ctan.org/macros/latex/contrib/ltablex/ltablex.pdf

Another feature that has been added is to treat the X columns like ‘l’ columns if the table contents would allow that to happen without exceeding the specified width of the table. In other words, the specified width is treated as the maximum allowed and not the exact width of the table. This feature is the default but can be disabled (or enabled) with \keepXColumns (or \convertXColumns).

From https://en.wikibooks.org/wiki/LaTeX/Tables

l left-justified column ... a new column specifier X (in uppercase). The column(s) specified with this specifier will be stretched to make the table as wide as specified, greatly simplifying the creation of tables.

Seems I can disable the feature with \keepXColumns and enable it later with \convertXColumns. Why I would want to: to treat the X columns like ‘l’ columns?

I cannot figure out a example for using \keepXColumns and \convertXColumns is there a example table about these two settings usage? How would be table look like if using \keepXColumns or \convertXColumns?

  • 1
    Because it looks kind of silly to have a really wide column with very little in it. – cfr Aug 19 '17 at 23:27
1

tabularx is I think over used, if you are writing a specific document such as a book or a thesis, spending a bit of time choosing appropriate column widths is time well spent.

However there are workflows where you need to typeset a lot of tabular data with different content and need a generic solution that produces acceptable output without hand tuning each table and tabularx can be useful there.

But note that tabularx is designed to adjust the line breaking in columns of text to achieve a stated total table width, as in the two examples in the first block below. That doesn't stop people using it for numeric tables as in the second block. Here though you really want to specify a maximum width so the table keeps within the page, but forcing the table to be over-wide in the case the data is quite small should be a non-aim, it just makes the table hard to read as your eye can not easily scan across the rows. The tabulary package ignores the specified maximum width in such a case, but by default the tabularx package does not have that feature, but the keep X columns feature adds that functionality, as shown in the third block below.

Although in practice I would not use tabularx at all for such a data table, better to use tabular with decimal aligned columns from dcolumn or siunitx.

enter image description here

\documentclass{article}

\usepackage{ltablex}

\begin{document}


\begin{tabularx}{\textwidth}{XXX}
one two three four five six seven&
red yellow blue green&
apple orange pear banana\\
sixteen seventeen eighteen&
black white&
grape cherry  
\end{tabularx}

\begin{tabularx}{.5\textwidth}{XXX}
one two three four five six seven&
red yellow blue green&
apple orange pear banana\\
sixteen seventeen eighteen&
black white&
grape cherry  
\end{tabularx}


\bigskip\hrule\bigskip

\keepXColumns 
\begin{tabularx}{\textwidth}{XXX}
10.1&20.2&30.3\\
11&12&13
\end{tabularx}

\begin{tabularx}{.5\textwidth}{XXX}
10.1&20.2&30.3\\
11&12&13
\end{tabularx}


\bigskip\hrule\bigskip

\convertXColumns
\begin{tabularx}{\textwidth}{XXX}
10.1&20.2&30.3\\
11&12&13
\end{tabularx}

\begin{tabularx}{.5\textwidth}{XXX}
10.1&20.2&30.3\\
11&12&13
\end{tabularx}



\end{document}

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.