TransWikia.com

Incompatibility between xltabular and multirow

TeX - LaTeX Asked on July 12, 2021

When I discovered xltabular I said “wow, this is a miracle!”: A package that combines tabularx and longtable and where one can give ratios of cell widths and a global width, and all calculations are done automatically, a dream becomes reality! And it works great, except for one thing: it seems to be incompatible with multirow.

Here is an MWE:

documentclass{article}
usepackage{xltabular,multirow}
pagestyle{empty}
usepackage{makecell}
setcellgapes{2.5pt}
begin{document}

renewcommandarraystretch{1.4644}
makegapedcells

begin{center}begin{xltabular}{textwidth}{|
>{setlength{hsize}{0.076hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.129hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.087hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.167hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.14hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.116hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.16hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.125hsize}centeringarraybackslash}X|}
hline 
multicolumn{3}{|c|}{A. bla bla bla
}
&multicolumn{2}{c|}{B. bla bla bla
}
&C. bla bla bla bla  bla bla bla bla  bla bla bla bla 
&D. bla bla bla bla  bla bla bla bla  bla bla bla bla
&E. bla bla bla bla bla bla bla  bla bla bla bla bla bla 
cline{1-5}F. bla bla bla bla bla bla 
&G. bla bla bla bla bla bla 
&H. bla bla bla bla bla bla 
&I. bla bla bla bla bla bla 
&J. bla bla bla bla bla bla 
&
&
&hline
end{xltabular}end{center}

which gives

enter image description here

Naturally I would like to convert cells C, D and E into 2-row cells to use the vertical space of F-J cells. Using the following code:

begin{center}begin{xltabular}{textwidth}{|
>{setlength{hsize}{0.076hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.129hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.087hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.167hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.14hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.116hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.16hsize}centeringarraybackslash}X|
>{setlength{hsize}{0.125hsize}centeringarraybackslash}X|}
hline 
multicolumn{3}{|c|}{A. bla bla bla
}
&multicolumn{2}{c|}{B. bla bla bla
}
&multirow{2}{*}{C. bla bla bla bla  bla bla bla bla  bla bla bla bla}
&multirow{2}{*}{D. bla bla bla bla  bla bla bla bla  bla bla bla bla}
&multirow{2}{*}{E. bla bla bla bla bla bla bla  bla bla bla bla bla bla }
cline{1-5}F. bla bla bla bla bla bla 
&G. bla bla bla bla bla bla 
&H. bla bla bla bla bla bla 
&I. bla bla bla bla bla bla 
&J. bla bla bla bla bla bla 
&
&
&hline
end{xltabular}end{center}

I get the (rather disappointing) result:

enter image description here

Do you know how to achieve the multi-row effect using xltabular?

One Answer

You can play withe optional argument of `multirow to move upwards or downwards the content of the multirow. Here is a code with the correct values for hsize. I also reduced the value of tabcolsep, because the columns widths are really small. One also may question having values up to the third decimal digit.

documentclass{article}
usepackage{geometry}
usepackage{xltabular,multirow}
pagestyle{empty}
usepackage{makecell}
setcellgapes{2.5pt}

begin{document}

renewcommandarraystretch{1.4644}
makegapedcells

begin{center}
setlength{tabcolsep}{3pt}
begin{xltabular}{textwidth}{|
>{hsize=0.608hsizecenteringarraybackslash}X|
>{hsize=1.032hsizecenteringarraybackslash}X|
>{hsize=0.696hsizecenteringarraybackslash}X|
>{hsize=1.336hsizecenteringarraybackslash}X|
>{hsize=1.12hsizecenteringarraybackslash}X|
>{hsize=0.928hsizecenteringarraybackslash}X|
>{hsize=1.28hsizecenteringarraybackslash}X|
>{centeringarraybackslash}X|
}
hline
multicolumn{3}{|c|}{A. bla bla bla
}
&multicolumn{2}{c|}{B. bla bla bla
}
&multirow{2}{=}[-0.9ex]{C. bla bla bla bla bla bla bla bla bla bla bla bla}
&multirow{2}{=}[-0.9ex]{D. bla bla bla bla bla bla bla bla bla bla bla bla}
&multirow{2}{=}[-0.9ex]{E. bla bla bla bla bla bla bla bla bla bla bla bla bla}
cline{1-5}F. bla bla bla bla bla bla
&G. bla bla bla bla bla bla
&H. bla bla bla bla bla bla
&I. bla bla bla bla bla bla
&J. bla bla bla bla bla bla
&
&
&hline
end{xltabular}
end{center}

end{document} 

enter image description here

Correct answer by Bernard on July 12, 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