xltabular 没有产生预期的结果

xltabular 没有产生预期的结果

我想制作一张可以延伸到\textwidth。我尝试了几种方法(但没有一种能正常工作Tabularx(xltabular)仅包含多列,无法正确展开xltabular 与多列和 \kill 结合使用时会产生错误

我想知道的是,为了制作这样的表格,我需要改变(和学习)什么。

平均能量损失

    \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}

\def\arraystretch{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}

它实际上应该是什么样子(我自己做了这个但它在环境下不起作用pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017)在此处输入图片描述

- - -编辑 - - -

我做了一个新的 MWE,只使用 longtable 和 multicolumn。其想法与使用n列数并取其中的一部分。这次每行都使用具有计算宽度的 p 类型列。

\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[english,bulgarian]{babel}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{longtable}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{layouts}

\renewcommand{\familydefault}{\sfdefault}   

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

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


          
           \vspace{-4mm}
            \noindent
                
      \LTleft=0pt 
      \LTright=0pt
    \begin{longtable}{@{\extracolsep{\fill}}*{20}{p{0.5\textwidth}} @{}}
    \hline
    \multicolumn{20}{|p{\dimexpr 1\textwidth-2\tabcolsep}|}{ \centering \textbf{ Платежна бележка } }\\ % header
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep}}{ \smf Период } & % ---------------- row 1
    \multicolumn{2}{p{\dimexpr 0.1\textwidth-2\tabcolsep}}{  } & 
    \multicolumn{6}{p{\dimexpr 0.3\textwidth-2\tabcolsep}}{ \smf 2020.07 } & 
    \multicolumn{3}{p{\dimexpr 0.15\textwidth-2\tabcolsep}}{ \smf Календар } & 
    \multicolumn{7}{p{\dimexpr 0.35\textwidth-2\tabcolsep}|}{ \smf 5 Пет дневна работна седмица } \\ 
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep}}{ \smf За лице } & % ---------------- row 2
    \multicolumn{2}{p{\dimexpr 0.1\textwidth-2\tabcolsep}}{ \smf\raggedleft\arraybackslash 146 } & 
    \multicolumn{6}{p{\dimexpr 0.3\textwidth-2\tabcolsep}}{ \smf Атанас Антонов Атанасов } & 
    \multicolumn{3}{p{\dimexpr 0.15\textwidth-2\tabcolsep}}{ \smf Работни дни } & 
    \multicolumn{7}{p{\dimexpr 0.35\textwidth-2\tabcolsep}|}{ \smf 23 } \\ 
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep}}{ \smf Заето в } & % ---------------- row 3
    \multicolumn{2}{p{\dimexpr 0.1\textwidth-2\tabcolsep}}{ \smf\raggedleft\arraybackslash 12 } & 
    \multicolumn{6}{p{\dimexpr 0.3\textwidth-2\tabcolsep}}{ \smf Поддръжка } & 
    \multicolumn{3}{p{\dimexpr 0.15\textwidth-2\tabcolsep}}{ \smf Трудов стаж } & 
    \multicolumn{7}{p{\dimexpr 0.35\textwidth-2\tabcolsep}|}{ \smf 24г. 1м. 4д. към 01.07.2020 } \\ 
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep}}{ \smf Длъжност } & % ---------------- row 4
    \multicolumn{2}{p{\dimexpr 0.1\textwidth-2\tabcolsep}}{ \smf\raggedleft\arraybackslash 24236003 } & 
    \multicolumn{6}{p{\dimexpr 0.3\textwidth-2\tabcolsep}}{ \smf Експерт, организация на труда } & 
    \multicolumn{3}{p{\dimexpr 0.15\textwidth-2\tabcolsep}}{ \smf Осн. заплата } & 
    \multicolumn{7}{p{\dimexpr 0.35\textwidth-2\tabcolsep}|}{ \smf 1,000.00 } \\ \hline
    \multicolumn{10}{|p{\dimexpr 0.5\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \centering \cellcolor{greyCell} \textbf{ Начисления } } &
    \multicolumn{10}{p{\dimexpr 0.5\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \centering \cellcolor{greyCell} \textbf{ Удръжки } } \\ \hline
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \centering \textit{шифър} } &
    \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \centering \textit{Наименование} } &
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \centering \textit{Сума} } &
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \centering \textit{д\%} } &
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \centering \textit{шифър} } &
    \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \centering \textit{Наименование} } &
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \centering \textit{Сума} } &
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \centering \textit{д\%} } \\ \hline 
                                  \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft  } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright От 01.07.2020 г. ОМВ } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 1,000.00 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 0 } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 455 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright Разпл. сметка Уникредит } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 777.20 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 0 } \\ \hline
                                           \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 104 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright Заплата по щат } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 1,000.00 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 23 } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 485 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright Разпл. сметка FiBank } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 75.00 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 0 } \\ \hline
                                           \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 111 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright Допл.проф.опит и стаж } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 144.00 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 14.4 } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 490 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright Банков заем } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 0.00 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 0 } \\ \hline
                                       \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 500 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright Данък общ доход } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 98.63 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 10 } \\ \hline
                                       \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 501 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright ЛОВ ф.\textquotedbl{}Безработица\textquotedbl{} } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 4.58 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 0.4 } \\ \hline
                                       \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 533 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright ЛОВ ф.\textquotedbl{}Пенсии\textquotedbl{} } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 75.28 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 6.58 } \\ \hline
                                       \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 536 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright ЛОВ ф.\textquotedbl{}ОЗМ\textquotedbl{} } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 16.02 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 1.4 } \\ \hline
                                       \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 537 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright ЛОВ ф.\textquotedbl{}ДЗПО УПФ\textquotedbl{} } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 25.17 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 2.2 } \\ \hline
                                       \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 540 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright Здравно осигуряване } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 36.61 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 3.2 } \\ \hline
                                       \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{  } &
                        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 560 } &
        \multicolumn{5}{|p{\dimexpr 0.25\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedright Членски внос Подкрепа } &
        \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 35.50 } &
        \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{ \smf \raggedleft 0 } \\ \hline
                    
    \multicolumn{7}{|p{\dimexpr 0.35\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf  \raggedright Всичко начисления } & % row 1 bottom
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 1,144.00 } & 
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &  
    \multicolumn{7}{|p{\dimexpr 0.35\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf  Всичко удръжки } & 
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft  1,144.00 } & 
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{   }  \\  \hline 
    \multicolumn{7}{|p{\dimexpr 0.35\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf  \raggedright Осигурителен доход } & % row 2 bottom
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 1,144.00 } & 
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &  
    \multicolumn{7}{|p{\dimexpr 0.35\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf  Всичко за осигуреното лице } & 
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft  157.66 } & 
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{   }  \\  \hline 
    \multicolumn{7}{|p{\dimexpr 0.35\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf  \raggedright Облагаем доход } & % row 3 bottom
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 1,144.00 } & 
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &  
    \multicolumn{7}{|p{\dimexpr 0.35\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf  Всичко за осигурителя } & 
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft  224.44 } & 
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{   }  \\  \hline 
    \multicolumn{7}{|p{\dimexpr 0.35\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf  \raggedright Данъчна основа } & % row 4 bottom
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft 986.34 } & 
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}}{ } &  
    \multicolumn{7}{|p{\dimexpr 0.35\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf  Сума за получаване } & 
    \multicolumn{2}{|p{\dimexpr 0.1\textwidth-2\tabcolsep-1\arrayrulewidth}}{ \smf \raggedleft  887.71 } & 
    \multicolumn{1}{|p{\dimexpr 0.05\textwidth-2\tabcolsep-1\arrayrulewidth}|}{   }  \\  \hline 
    \end{longtable}

\结束{文档}

这次我得到了很多\hbox 溢出\vbox 未满。结果与第一张图片几乎相同。我可以做些什么来优化代码?也许我在计算中遗漏了一些东西?也欢迎使用不同的方法(产生相同的结果)。

答案1

更像这样的东西(根本不使用 tabularx/xltabular)并且有远的更少\multicolumn

在此处输入图片描述




% 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
% \def\arraystretch{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

\setlength\extrarowheight{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,4\\\hline
111 & long label & 144& 14.4 & 490 & long label & 0.00 & 0\\\hline
&&&&500 &long label &98.63&10\\\hline
\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}

相关内容