1

I had several tables in my document, some longer than others, but all of them defined using tabularx. In one moment I decided I needed a way to break tables across pages, so I found out about ltablex. With big tables it works really nicely, but with smaller tables, like this:

    \begin{tabularx}{\textwidth}{|>{\hsize=0.2\hsize}X| >{\hsize=2.9\hsize}X | >{\hsize=0.2\hsize}X| >{\hsize=0.7\hsize}X |}
        \hline
        \rowcolor{Snow2}
        \textbf{Nº} & \textbf{Nombre de la unidad} & \textbf{\%} & \textbf{Duración} \\
        \hline
        UT11 & Utilización de frameworks arquitectónicos en cliente & 5 & 5 sesiones \\
        \hline      
    \end{tabularx}

Instead of filling the entire width, it just fits the width to the content. The moment I REMOVE the ltablex package, it works properly (but I lose the page-breaking feature).

With ltablex

Is there something that needs to be done?

Also, why does it leave those vertical separations between elements?

4
  • As always on this site please never show sniplets like this, please provide a full but minimal example that others can copy and test as is.
    – daleif
    Jun 30, 2021 at 13:09
  • As an alternative to ltablex, you could give xltabular a try.
    – leandriis
    Jun 30, 2021 at 13:13
  • Are you in landscape? Use \linewidth instead of \textwidth. Jun 30, 2021 at 13:36
  • Any news? Almost half year ago you get two answer? Does any of them fulfil your expectation (that you would upwote or even accept one of them)?
    – Zarko
    Nov 28, 2021 at 0:08

2 Answers 2

3

I am able to reproduce the issue you mention when loading ltablex if I have the geometry package present while using your snippet.

Or using the KOMA-script \documentclass{scrartcl} that also sets the geometry of the page.

In both cases it can be controlled with the command \keepXColumns. From the manual:

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).

Geometry + tabularx

GTx

Geometry + ltablex (table is 411pt wide)

GLT

Geometry + ltablex + \keepXColumns (table is 483.6pt wide = to \texwidth)

GLTk

Only ltablex (geometry not loaded and article class)

LT

Only tabularx (geometry not loaded and article class)

tbx

The two last results are the same since ltables uses tabulax, but notice the vertical space added before the table by ltablex.

\documentclass[12pt,a4paper]{article}

\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}

\usepackage{ltablex}

%\usepackage{tabularx}

\usepackage[table,x11names]{xcolor}
\usepackage{showframe}

\begin{document}
    
\keepXColumns   % used with ltablex and geometry

\noindent \begin{tabularx}{\textwidth}{|>{\hsize=0.2\hsize}X| >{\hsize=2.9\hsize}X | >{\hsize=0.2\hsize}X| >{\hsize=0.7\hsize}X |}
    \hline
    \rowcolor{Snow2}
    \textbf{Nº} & \textbf{Nombre de la unidad} & \textbf{\%} & \textbf{Duración} \\
    \hline
    UT11 & Utilización de frameworks arquitectónicos en cliente & 5 & 5 sesiones \\
    \hline      
\end{tabularx}
    
\end{document}
0

It is not clear, what is your problem. If I a little bit correct your selection of column widths (so, that their contents doesn't overlap) result is just fine:

enter image description here

\documentclass{article}
\usepackage[table,x11names]{xcolor}
\usepackage{ltablex}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\setlength\extrarowheight{2pt}

\begin{document}
    \begin{tabularx}{\textwidth}{|l| % <--- changed column type
                                  >{\hsize=1.3\hsize}L| 
                                  c| % <--- changed column type
                                  >{\hsize=0.7\hsize}L|}
\caption{Used is \texttt{ltablex} table environment}
\label{my-label}    \\
    \hline
    \rowcolor{Snow2}
\textbf{Nº} & \textbf{Nombre de la unidad} 
                & \textbf{\%}   & \textbf{Duración} \\
    \hline
UT11        & Utilización de frameworks arquitectónicos en cliente 
                & 5             & 5 sesiones        \\
    \hline
    \end{tabularx}
\end{document}

You must log in to answer this question.

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