我正在尝试制作一个看起来像图片的乳胶表。标题 1 下应该有 4 列旋转文本,一个灰色单元格包含附加信息。我是乳胶新手,不知道如何以 booktabs 样式制作此表格。
\documentclass{article}
\newcommand*\turn{\rotatebox[origin=b]{90}}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array, caption}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\begin{table}[]
\centering
\begin{tabular}{@{}llllll@{}}
\toprule
& \multicolumn{4}{c}{Header 1} & \\
\cmidrule(lr){2-5}
&\turn{Text1} &\turn{Text2} &\turn{Text3} & \turn{Text4} & \cellcolor{gray!25} \makecell[l]{Some line 1\\ Some line 1\\ Some line 1\\ Some line 1\\ Some line 1} \\
Header 3 & & & & &Header 3\\
\midrule
& & & & & \\
& & & & & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
MWE 重现了这张(不寻常的)表格(如您在问题中所示),其内容如下:
\documentclass{article}
\usepackage[table,xcdraw]{xcolor}
\usepackage{rotating}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage[skip=1ex]{caption}
\begin{document}
\begin{table}[htb]
\centering
\setlength\extrarowheight{2pt}
\settowidth\rotheadsize{Text 4}
\renewcommand\rotheadgape{}
\begin{tabularx}{0.6\linewidth}{ l llll c@{\,}X }
\Xhline{1pt}
& \multicolumn{4}{c}{Header 1}
&& \cellcolor{gray!25} \\
\Xcline{2-5}{0.6pt}
& \rothead{Text 1}
& \rothead{Text 2}
& \rothead{Text 3}
& \rothead{Text 4}
&& \cellcolor{gray!25}%
\multirow{-2.2}{=}{\noindent
Some line 1 Some line 2
Some line 3} \\
Header 3 & & & & && Header 3 \\
\Xhline{0.6pt}
A & & & & && 1 \\
B & & & & && 2 \\
\Xhline{1pt}
\end{tabularx}
\end{table}
\end{document}
附录:
\documentclass{article}
\usepackage[table,xcdraw]{xcolor}
\usepackage{rotating}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcommand\mrrc[1]{\multirow{-2.4}{*}{\rothead{#1}}} % <---
\usepackage[skip=1ex]{caption}
\begin{document}
\begin{table}[htb]
\centering
\setlength\extrarowheight{2pt}
\settowidth\rotheadsize{Text 4}
\renewcommand\rotheadgape{}
\begin{tabularx}{0.6\linewidth}{ l llll c@{\,}L }
\Xhline{1pt}
& \multicolumn{4}{c}{Header 1}
&& \cellcolor{gray!25} \\
\Xcline{2-5}{0.6pt}
& & & & && \cellcolor{gray!25} % <---
\small\linespread{0.84}\selectfont % <---
\multirow{-1.8}{=}{\noindent
Some line 1
Some line 2
Some line 3} \\[1ex]
Header 3 & \mrrc{Text 1} % <--- rotated headers moved down
& \mrrc{Text 2}
& \mrrc{Text 3}
& \mrrc{Text 4}
&& Header 3 \\
\Xhline{0.6pt}
A & & & & && 1 \\
B & & & & && 2 \\
\Xhline{1pt}
\end{tabularx}
\end{table}
\end{document}
希望能够产生你喜欢的东西:
答案2
这是你想要的吗?
\documentclass{article}
\newcommand*\turn{\rotatebox[origin=b]{90}}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array, caption}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\begin{table}[]
\centering
\begin{tabular}{@{}llllll@{}}
\toprule
& \multicolumn{4}{c}{Header 1} & \\
\cmidrule(lr){2-5}
&\multirowcell{3.5}{\turn{Text1}} &\multirowcell{3.5}{\turn{Text2}} &\multirowcell{3.5}{\turn{Text3}} & \multirowcell{3.5}{\turn{Text4}} & \cellcolor{gray!25} \makecell{Some line 1\\ Some line 1\\ Some line 1\\ Some line 1\\ Some line 1} \\
\addlinespace
Header 3 & & & & &Header 3\\
\midrule
& & & & & \\
& & & & & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
这是一个{NiceTabular}
使用 的解决方案nicematrix
。
\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}
\usepackage{booktabs}
\begin{document}
\begin{table}[htb]
\centering
\setlength\extrarowheight{2pt}
\begin{NiceTabular}{llllll}
\CodeBefore
\rectanglecolor{gray!20}{1-6}{2-6}
\Body
\toprule
& \Block{1-4}{Header 1} &&&
& \Block{2-1}{Some line 1\\ Some line 2 \\ Some line 3} \\
\cmidrule(lr){2-5}
\RowStyle{\rotate}
& Text 1
& Text 2
& Text 3
& Text 4 \\
Header 3 & & & & & Header 3 \\
\midrule
A & & & & & 1 \\
B & & & & & 2 \\
\bottomrule
\end{NiceTabular}
\end{table}
\end{document}
此解决方案使用
\booktabs
(nicematrix
与 兼容booktabs
)。因此,使用 很容易缩短\cmidrule
(\cmidrule(rl)
无需虚拟列)。命令
\Block
将nicematrix
其内容置于合并单元格的数学中心。无需像 那样手动调整\multirow
。该命令
\rowstyle
将格式化命令应用于该行的所有单元格。在 中
nicematrix
,彩色面板在所有规则之前绘制(在 PDF 查看器中输出效果更好:在某些 PDF 查看器(如 Adobe Reader)中,规则在某些缩放级别下似乎不会消失)。