TransWikia.com

tabularx does not fill full textwidth when using ltablex

TeX - LaTeX Asked by José Tomás Tocino on July 6, 2021

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.2hsize}X| >{hsize=2.9hsize}X | >{hsize=0.2hsize}X| >{hsize=0.7hsize}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?

2 Answers

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}{>{raggedrightarraybackslash}X}
setlengthextrarowheight{2pt}

begin{document}
    begin{tabularx}{textwidth}{|l| % <--- changed column type
                                  >{hsize=1.3hsize}L| 
                                  c| % <--- changed column type
                                  >{hsize=0.7hsize}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}

Answered by Zarko on July 6, 2021

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.2hsize}X| >{hsize=2.9hsize}X | >{hsize=0.2hsize}X| >{hsize=0.7hsize}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}

Answered by Simon Dispa on July 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP