TransWikia.com

Vertical spacing after a tabu environment

TeX - LaTeX Asked by reedy on July 30, 2021

When creating a tabu with two rows, I get more vertical spacing after the environment than when I create a tabu with only one row.

In the document below, the first tabu has two lines, and there is a small space between the end of the table and the rule below it. In the second tabu, I only have one line, and there is a larger space below it.

documentclass{article}
usepackage{geometry}
usepackage{tabu}

geometry{a4paper} 

begin{document}
begin{tabu} to textwidth {X X}%
    These are words & in the first line %
    These are more words & in the second line%
end{tabu}par%
rule{textwidth}{0.4pt}par%
%
%
vspace{2em}par%
%
%
begin{tabu} to textwidth {X X}%
    These are words & in the first line%
end{tabu}par%
rule{textwidth}{0.4pt}par%
%
end{document}

typeset output of above document, displaying inconsistency in spacing after a tabu environment

I’ve been quite careful (I think) with whitespace around the tabu, and I see no difference in the two tables aside from the different number of lines.

I know that I could fix this by adding a vspace{0.5em} or similar right after the tabu with the small spacing, but I am using the tables in a custom command and I would like to avoid a hard-coded solution like this if possible.

This problem also comes up if I substitute a tabular for the tabu. Adding tabulinesep=Xem fixes (or appears to fix) the problem for large X (>1em), but I need small spacings (ideally, ~0em).

Any ideas?

One Answer

Too big for a comment ...

Discovered phenomena is not related only to tabu, but it can be observable at all table environments. For example, at tabularx too:

documentclass{article}
usepackage[a4paper]{geometry}
usepackage{tabularx}
setlengthparindent{0pt}

begin{document}
begin{tabularx}{textwidth}{X X}%
hline
    These are words & in the first line %
    These are more words & in the second line
hline%
end{tabularx}par%
rule{textwidth}{0.4pt}par%

%
vspace{2em}
%
begin{tabularx}{textwidth}{X X}%
hline
    These are words & in the first line
hline%
end{tabularx}par%
rule{textwidth}{0.4pt}par%
%
end{document}

which gives:

enter image description here

This is caused by some strange interaction between tables and rule. If you replace rule with text:

documentclass{article}
usepackage[a4paper]{geometry}
usepackage{tabularx}
setlengthparindent{0pt}

usepackage{lipsum}

begin{document}
begin{tabularx}{textwidth}{X X}%
hline
    These are words & in the first line %
    These are more words & in the second line
hline%
end{tabularx}par%
lipsum[66]

vspace{2em}
%
begin{tabularx}{textwidth}{X X}%
hline
    These are words & in the first line
hline%
end{tabularx}par%
lipsum[66]
end{document}

than result is as expected:

enter image description here

Answered by Zarko on July 30, 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