我使用制作了一张表格长桌和多列包。我的想法是将表格扩展到 \textwidth ,使用n具有相同宽度的列数,并对每行使用 \textwidth 块。 表格型不是一个选项,因为使用 \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[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}
\end{document}
正如 David Carlisle 所说,这种方法过于复杂。该表实际上包含 8 列(而不是 20 列),因此我发布了他提供的这个 MWE。
\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}
\usepackage{colortbl}
\usepackage{longtable}
\definecolor{greyCell}{RGB}{235,235,235}
\begin{document}
\setlength{\tabcolsep}{0.8mm} % for the horizontal padding
\fontsize{10}{13}\selectfont
\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}
为什么第 5 列的文本被推得那么远?为什么内部表格(标题下)没有扩展到多列的整个宽度?
答案1
嗯,我会按如下方式设计您的表格:
- 考虑一下你问题下面的大多数评论,即你的第二个 MWE
- 对于表格我会用
xltabular
- 在带有数字的列中我将使用
S
列类型 - 形成最常用的多列单元格我将定义新的命令
\mcl
和\mcll
- 在编辑器中删除千位组分隔符(将其插入到左侧
siunitx
)
\documentclass{article}
\usepackage{geometry}
\geometry{
a4paper, % paper size
margin=20mm % all margins are equal
}
%\usepackage[utf8]{inputenc} % only needed with old latex installations
%\usepackage[defaultsans]{opensans} %font
\usepackage[T1, T2A]{fontenc}
\usepackage{longtable, xltabular}
\NewExpandableDocumentCommand\mcll{m}{\multicolumn{2}{|l|}{#1}}
\NewExpandableDocumentCommand\mcl{ m}{\multicolumn{2}{ l|}{#1}}
\usepackage[table]{xcolor}
\definecolor{greyCell}{RGB}{235,235,235}
\usepackage{siunitx}
\begin{document}
\begingroup
\sisetup{group-minimum-digits=4,
group-separator={,}}
\setlength\extrarowheight{2pt}% keep hline away from text
\small
\begin{xltabular}{\linewidth}{ *{2}{|S[table-format=3]
|X
|S[table-format=4.2]
|S[table-format=2.1]}|
}
\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}} \\
\hline
\rowcolor{greyCell}
\multicolumn{4}{|c|}{\textbf{Label}} & \multicolumn{4}{c|}{\textbf{Label}}\\ \hline
{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.00 & 14.4 & 490 & long label & 0.00 & 0 \\ \hline
& & & & 500 & long label & 98.63 & 10 \\ \hline
\mcll{long label} & 144.00 & & \mcl{long label}
& 1 144.00 & \\ \hline
\mcll{long label} & 144.00 & & \mcl{long label}
& 157.66 & \\ \hline
\end{xltabular}
\endgroup
\end{document}