灵感来自这,这里是 MWE,显示行尾和表格右侧之间的可见边距。这很烦人。有没有什么办法可以去除它?
\documentclass[12pt]{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fancy table
% https://tex.stackexchange.com/questions/112343/beautiful-table-samples
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}
\usepackage{multirow}
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Z}{>{\centering\arraybackslash\hsize=.6\hsize}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{tcolorbox}[tab2,tabularx={Z || Z | Z | Z},title=AAA,width=0.7\textwidth]
BBB & BBB & BBB & BBB \\ \hline\hline
\multirow{3}{*}{XXX} & AAA & AAA & AAA \\ \cline{2-4}
& & AAA & AAA \\ \cline{2-4}
& & AAA & AAA
\end{tcolorbox}
\end{document}
答案1
问题出在对 的误解上>{\hsize=0.6\hsize}X
:它是为X
长度不等的列而设计的,并且值作为重心坐标:它们的总和必须等于列数(这里是 4)。但它们的总和却等于2.4
!由于所有列的宽度都相等,因此删除此规范即可:
\documentclass[12pt]{article}
\usepackage[table, dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\tcbuselibrary{skins}
\usepackage{multirow}
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Z}{>{\centering\arraybackslash}X}%
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{tcolorbox}[tab2,tabularx={Z || Z | Z | Z },title=AAA, width=0.7\textwidth]
BBB & BBB & BBB & BBB \\ \hline\hline
\multirow{3}{*}{XXX} & AAA & AAA & AAA \\ \cline{2-4}
& & AAA & AAA \\ \cline{2-4}
& & AAA & AAA
\end{tcolorbox}
\end{document}
此外,请注意usenames
选项xcolor
已被弃用,因为它现在是默认选项。我添加了table
选项,这样就不必显式加载colortbl
。