TransWikia.com

xltabular not producing desired result

TeX - LaTeX Asked by Lubomir Borisov on March 17, 2021

I want to make a table that spreads to textwidth. I tried several ways (none of them working properly Tabularx (xltabular) with only multicolumns not spreading properly, xltabular produces error in combination with multicolumn and kill)

What I want to know is what I need to change (and learn) in order to make such tables.

MWE

    documentclass[paper=a4,fontsize=18pt]{article}

usepackage{geometry}
geometry{
    % verbose,
    portrait,       % page orientation (landscape or portrait)
    a4paper,        % paper size
    tmargin=5mm,    % page top margin
    bmargin=5mm,    % page bottom margin
    lmargin=5mm,   % page left margin
    rmargin=5mm % page right maring
}

   usepackage[utf8]{inputenc}
    usepackage[defaultsans]{opensans} %font
    usepackage[T1, T2A]{fontenc}
    usepackage{fancyhdr}
    usepackage{multicol}
    usepackage{colortbl}
    usepackage{booktabs}
    usepackage{tabularx}
    usepackage{longtable}
    usepackage{layouts}
    usepackage{xltabular}


%pagestyle{fancy}

definecolor{greyCell}{RGB}{235,235,235}
newcommand{smf}{% small font
    fontsize{9}{11}selectfont
}

begin{document}

defarraystretch{1}%  vertical padding
setlength{tabcolsep}{0.8mm} % for the horizontal padding
fontsize{10}{13}selectfont 


        noindent
noindent
        begin{xltabular}{textwidth}{|*{20}{c|}}
        hline
        multicolumn{20}{|c|}{ textbf{ Header } } 
        multicolumn{2}{|l}{ smf Label} & 
        multicolumn{2}{l}{  } & 
        multicolumn{6}{l}{ smf 2020.07 } & 
        multicolumn{3}{l}{ smf Label} &  
        multicolumn{7}{l|}{ smf long variable }    
        multicolumn{2}{|l}{ smf Label} & 
        multicolumn{2}{r}{ smf 146 } & %  number cell
        multicolumn{6}{l}{ smf long variable test } &  % cell with person name
        multicolumn{3}{l}{ smf Label} &  
        multicolumn{7}{l|}{ smf 23 }     %  number cell
        multicolumn{2}{|l}{ smf Label } & 
        multicolumn{2}{r}{ smf  12 } & %  number cell
        multicolumn{6}{l}{ smf variable variable variable } & % can be long 
        multicolumn{3}{l}{ smf Label} &  
        multicolumn{7}{l|}{ smf Long variable long variable }     
        multicolumn{2}{|l}{ smf Label} & 
        multicolumn{2}{r}{ smf 24568545 } & %  number cell
        multicolumn{6}{l}{ smf long variable here } & 
        multicolumn{3}{l}{ smf Label } &  
        multicolumn{7}{l|}{ smf 1,000.12 }   hline   
        multicolumn{10}{|c}{ cellcolor{greyCell} smf textbf{Label} } &
        multicolumn{10}{|c|}{ cellcolor{greyCell} smf  textbf{Label}   }  hline
        multicolumn{2}{|c|}{ smf textit{label}} & 
        multicolumn{5}{c|}{ smf textit{label} } & 
        multicolumn{2}{c|}{ smf textit{label} } & 
         smf textit{d%} &  
        multicolumn{2}{c|}{ smf textit{label}} & 
        multicolumn{5}{c|}{ smf textit{label} } & 
        multicolumn{2}{c|}{ smf textit{label} } & 
         smf textit{d%}     hline 
            multicolumn{2}{|r|}{ smf  104 } & %  number cell
            multicolumn{5}{l|}{ smf long variable } & 
            multicolumn{2}{r|}{ smf 1,000.00 } & %  number cell
             smf 14.4  &  

            multicolumn{2}{r|}{ smf 455 } & %  number cell
            multicolumn{5}{l|}{ smf long variable } & 
            multicolumn{2}{r|}{ smf 777.20 } & 
             smf 0,4     hline   


        multicolumn{7}{|l|}{ smf long label } & % first row bottom
        multicolumn{2}{r|}{ smf   1,144.00 } & %  number cell
         &  
        multicolumn{7}{l|}{ smf  long label } & 
        multicolumn{2}{r|}{ smf  1,234.12 } & %  number cell
            hline 
        multicolumn{7}{|l|}{ smf long label } & % second row bottom
        multicolumn{2}{r|}{ smf  1,232.12 } & 
         &  
        multicolumn{7}{l|}{ smf  very long label } & 
        multicolumn{2}{r|}{ smf  1,999.12 } & 
            hline 
        multicolumn{7}{|l|}{ smf  long label} & % third row bottom
        multicolumn{2}{r|}{ smf  1,888.32 } & 
         &  
        multicolumn{7}{l|}{ smf  long label } & 
        multicolumn{2}{r|}{ smf  1,878.99 } & 
            hline 
        multicolumn{7}{|l|}{ smf  long label } & % last row bottom
        multicolumn{2}{r|}{ smf    1,878.99 } & 
         &  
        multicolumn{7}{l|}{ smf  long label } & 
        multicolumn{2}{r|}{ smf  1,878.99 } & 
            hline 
        
end{xltabular}

end{document}

How it should really look (I did this myself but its not working under environment pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017))
enter image description here

One Answer

Something more like this (which does not use tabularx/xltabular at all) and has far fewer multicolumn

enter image description here




% article class does not have these options
%documentclass[paper=a4,fontsize=18pt]{article}

documentclass{article}

usepackage{geometry}
geometry{
    % verbose,
    portrait,       % page orientation (landscape or portrait)
    a4paper,        % paper size
    tmargin=5mm,    % page top margin
    bmargin=5mm,    % page bottom margin
    lmargin=5mm,   % page left margin
    rmargin=5mm % page right maring
}

% only needed with old latex installations 
  usepackage[utf8]{inputenc}

    usepackage[defaultsans]{opensans} %font
    usepackage[T1, T2A]{fontenc}

% not used in this document
%    usepackage{fancyhdr}
%    usepackage{multicol}
%    usepackage{booktabs}
%    usepackage{layouts}


    usepackage{colortbl}

% not needed as xltabular loads them
%    usepackage{tabularx}
%    usepackage{longtable}

    usepackage{xltabular}


%pagestyle{fancy}

definecolor{greyCell}{RGB}{235,235,235}


% this is exactly the definition of the standard small
%newcommand{smf}{% small font
%    fontsize{9}{11}selectfont
%}

begin{document}

% this is the default so no need to specify
% defarraystretch{1}%  vertical padding

setlength{tabcolsep}{0.8mm} % for the horizontal padding

% this is the standard font with slightly larger baseline space
% it works but is an unusual way to set baselineskip
fontsize{10}{13}selectfont 


% double noindent and should not be used befoe longtable/xltabular
%        noindent
% noindent

setlengthextrarowheight{2pt}% keep hline away from text
small
LTleft=0pt
LTright=0pt
        begin{longtable}{@{extracolsep{fill}}|*{8}{l|}@{}}
        hline
        multicolumn{8}{|c|}{textbf{Header}}
        multicolumn{4}{|l}{%
begin{tabular}{lrl}
Label& &  2020.07
Label& 146 &long variable test
Label & 12 & variable variable variable
label  & 24568545 & long variable here
end{tabular}}
&
        multicolumn{4}{l|}{%
begin{tabular}{ll}
Label &  long variable  
Label & 23
Label& Long variable long variable    
Label & 1,000.12
end{tabular}}

rowcolor{greyCell}
multicolumn{4}{@{}|>{columncolor{greyCell}[.8mm][2cm]}c@{}}{Label}&multicolumn{4}{@{}c|@{}}{Label}
label&label&label&d%&label&label&label&d%hline
104& long variable& 1,000.00&14.4&455&long variable&777.20&0,4hline
111 & long label & 144& 14.4 & 490 & long label & 0.00 & 0hline
&&&&500 &long label &98.63&10hline
multicolumn{2}{|l|}{long label}&1,44.00 &&multicolumn{2}{|l|}{long label}&1,44.00& hline
multicolumn{2}{|l|}{long label}&1,44.00 &&multicolumn{2}{|l|}{long label}&157.66 &hline
end{longtable}
end{document}
        
end{xltabular}

end{document}

Answered by David Carlisle on March 17, 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