我正在自动生成 tex 文档(HTML -> pandoc(tex) -> postprocess -> XELATEX),并且我的通用表环境是tabularx
(使用包ltablex
,因此这些实际上是长表)。
这种选择的一个原因是可以一致地分配标题(使用包caption
)。
有时需要外部表格来并排显示带有标题的内部嵌套表格。
\documentclass[a4paper,dvipsnames]{article}
\usepackage[ngerman]{babel}
\usepackage[paper=portrait,pagesize]{typearea}
\usepackage{color}
\usepackage[table]{xcolor}
\definecolor{tableHighlightRowBackground}{gray}{0.9375}
\definecolor{tablecaptionfontcolor}{RGB}{108, 117, 125}
\definecolor{arrayrulecolor}{RGB}{222,226,230}
\usepackage[most]{tcolorbox}
\usepackage{relsize}
\usepackage{ltablex}
\keepXColumns
\usepackage{multirow}
\usepackage{caption}
\DeclareCaptionFont{muted}{\color{tablecaptionfontcolor}}
\captionsetup[table]{singlelinecheck=false, justification=raggedleft, font={muted,small}}
\setlength\parindent{0pt}
\usepackage{booktabs}
\usepackage{colortbl}
\arrayrulecolor{arrayrulecolor}
\begin{document}
\begin{tabular}{@{}ll@{}}
\toprule
\begin{minipage}[t]{0.47\columnwidth}\raggedright
a
\strut
\end{minipage}
&
\begin{minipage}[t]{0.47\columnwidth}\raggedright
b
\strut
\end{minipage}
\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\begin{tabularx} {\textwidth} {Xcrr}
\bfseries
Position & \bfseries Year 2020 & \bfseries Year 2021 \\
\midrule
\endhead
\bottomrule
\caption{Important Caption} \tabularnewline
\endfoot
\rowcolor{tableHighlightRowBackground} % this is another problem, this command applies the bg color to the complete outer row
\bfseries A & { \bfseries 11,40 € } & { \bfseries 10,00 € } \\
\end{tabularx}
\strut
\end{minipage}
&
\begin{minipage}[t]{0.47\columnwidth}\raggedright
d
\strut
\end{minipage}\tabularnewline
\bottomrule
\end{tabular}
\end{document}
这期望输出将是内部 tabularx 下方(外部表格内部)的标题。
我的框架非常灵活,只有一个不变量:内部的 tabularx 应该显示为全宽表格,并带有表格标题和数字。
答案1
这是我根据对所需输出的一些假设提出的建议。我没有更改内部表格以避免重复\bfseries
。
\documentclass{article}
%\usepackage{ltablex}
%\keepXColumns
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{caption}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\definecolor{tableHighlightRowBackground}{rgb}{0.8,0.8,0.8}
\begin{document}
\begin{tabular}{@{}p{0.9\textwidth}l@{}}
\toprule
a & b
\\
{\begin{tabularx} {0.9\textwidth} {Xcrr}
\bfseries
Position & \bfseries Year 2020 & \bfseries Year 2021 \\
\midrule
\rowcolor{tableHighlightRowBackground} % this is another problem, this command applies the bg color to the complete outer row
\bfseries A & { \bfseries 11,40 € } & { \bfseries 10,00 € } \\
\bottomrule
\end{tabularx}}
\captionof{table}{Important Caption}
&
d \\
\bottomrule
\end{tabular}
\end{document}