显然,该命令对于内部具有 tabularx 的boxrule
增强功能不起作用。tcolorbox
我如何指定 tabularx 周围框架的宽度?
这是 MWE:
\documentclass{article}
\usepackage[skins]{tcolorbox}
\usepackage{array,tabularx}
\usepackage{colortbl}
\begin{document}
% \usepackage{array,tabularx}
% \usepackage{colortbl} - or - \usepackage[table]{xcolor}
\tcbset{enhanced,fonttitle=\bfseries\large,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!50!black,colbacktitle=red!30!white,
coltitle=black,center title,
boxrule=10pt, % NO EFFECT
}
\begin{tcolorbox}[tabularx*={\arrayrulewidth0.5mm}{X|X|X},title=My table]
One
& Two
& Three \\\hline\hline
1000.00 & 2000.00 & 3000.00\\\hline
2000.00 & 3000.00 & 4000.00
\end{tcolorbox}
% EDIT : with a multicolumn as 1st cell this does not compile anymore
\begin{tcolorbox}[boxrule=2pt,tabularx*={\arrayrulewidth2pt}{YY|YY|YY},
title=My table
]
\multicolumn{2}{c|}{title}
& \multicolumn{2}{c|}{title}
& \multicolumn{2}{c}{title} \\\hline
2 & d & 3 & e & 4 & f \\\hline
title & \multicolumn{3}{|l|}{h} & \multicolumn{1}{c|}{title} & j \\
\end{tcolorbox}
\end{document}
编辑 :对于 MWE 中的第一个表,第一个答案是可以的,但我使用 amulticolumn
作为第一个单元格,这会带来Misplaces \omit
错误。MWE 已使用有问题的表进行了修改。
答案1
样式的定义tabularx
已将设置为boxrule
。0.5mm
您可以通过从源复制样式并删除此部分来覆盖该设置:
\documentclass{article}
\usepackage[skins]{tcolorbox}
\usepackage{array,tabularx}
\usepackage{colortbl}
\begin{document}
% \usepackage{array,tabularx}
% \usepackage{colortbl} - or - \usepackage[table]{xcolor}
\tcbset{enhanced,fonttitle=\bfseries\large,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!50!black,colbacktitle=red!30!white,
coltitle=black,center title,
boxrule=10pt, % NO EFFECT
}
\makeatletter
\tcbset{tabularx*/.style 2 args={%
boxsep=\z@,top=\z@,bottom=\z@,leftupper=\z@,rightupper=\z@,
toptitle=1mm,bottomtitle=1mm,% boxrule setting here removed
before upper={\arrayrulecolor{tcbcol@frame}\def\arraystretch{1.1}#1%
\tcb@hack@currenvir\tabularx{\linewidth}{#2}},
after upper=\endtabularx\arrayrulecolor{black}}}
\makeatother
\begin{tcolorbox}[tabularx*={\arrayrulewidth0.5mm}{X|X|X},title=My table]
One
& Two
& Three \\\hline\hline
1000.00 & 2000.00 & 3000.00\\\hline
2000.00 & 3000.00 & 4000.00
\end{tcolorbox}
\end{document}
结果:
编辑:在较新版本中,该tcolorbox
定义略有更改。在这种情况下,新定义应如下:
\tcbset{tabularx*/.style 2 args={%
boxsep=\z@,top=\z@,bottom=\z@,leftupper=\z@,rightupper=\z@,
toptitle=1mm,bottomtitle=1mm,
before upper*={%
\let\tcb@CT@arc@save\CT@arc@%
\arrayrulecolor{tcbcolframe}\def\arraystretch{1.1}#1%
\tcb@hack@currenvir\tabularx{\linewidth}{#2}},
after upper*={\endtabularx\global\let\CT@arc@\tcb@CT@arc@save}%
}
}
答案2
如果需要改变boxrule
选项指定的值tabularx*
,那么tabularx*/.append style={boxrule=<dimen>}
更简单,其中.append style
是预定义的处理程序之一pgfkeys
。
完整示例:
\documentclass{article}
\usepackage[skins]{tcolorbox}
\usepackage{array,tabularx}
\usepackage{colortbl}
\tcbset{
enhanced,
fonttitle=\bfseries\large,
fontupper=\normalsize\sffamily,
colback=yellow!10!white,
colframe=red!50!black,
colbacktitle=red!30!white,
coltitle=black,
center title,
% change boxrule set by "tabularx*", by default it's 0.5mm
tabularx*/.append style={boxrule=10pt}
}
\begin{document}
\begin{tcolorbox}[tabularx*={\arrayrulewidth0.5mm}{X|X|X}, title=My table]
One
& Two
& Three \\\hline\hline
1000.00 & 2000.00 & 3000.00\\\hline
2000.00 & 3000.00 & 4000.00
\end{tcolorbox}
\end{document}
更新
只是为了好玩。这里定义了一个在包内部使用的新pgfkeys
处理程序。.patch code={<search>}{<replace>}
\xpatchcmd
xpatch
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{xpatch}
\usepackage{array,tabularx}
\usepackage{colortbl}
\makeatletter
% usage:
% <key>/.patch code={search}{replace}
% similar to def of /handlers/.add code/.code 2 args={...}
\pgfkeys{/handlers/.patch/.code 2 args=%
% Find out, whether with args or not.
\pgfkeysifdefined{\pgfkeyscurrentpath/.@args}%
{% Yes, so add to body and reuse args
\pgfkeyspatchvalue{\pgfkeyscurrentpath/.@body}{#1}{#2}%
% Redefine code
{%
\pgfkeysgetvalue{\pgfkeyscurrentpath/.@args}{\pgfkeys@tempargs}%
\pgfkeysgetvalue{\pgfkeyscurrentpath/.@body}{\pgfkeys@tempbody}%
\def\pgfkeys@marshal{\expandafter\gdef\expandafter\pgfkeys@global@temp\pgfkeys@tempargs}%
\expandafter\pgfkeys@marshal\expandafter{\pgfkeys@tempbody}%
}%
\pgfkeysifdefined{\pgfkeyscurrentpath/.@@body}{%
% support for \pgfkeysndefargs:
\pgfkeyslet{\pgfkeyscurrentpath/.@@body}{\pgfkeys@global@temp}%
}{%
% support for \pgfkeysdefargs:
\pgfkeyslet{\pgfkeyscurrentpath/.@cmd}{\pgfkeys@global@temp}%
}%
}{% No, so single argument (simple \pgfkeysdef). Redefine accordingly.
\edef\pgf@expanded@path{\pgfkeyscurrentpath}%
{%
\pgfkeysifdefined{\pgf@expanded@path/.@cmd}{%
\expandafter\expandafter\expandafter\pgfkeys@temptoks
\expandafter\expandafter\expandafter{%
\csname pgfk@\pgf@expanded@path/.@body\endcsname}%
}{%
\expandafter\pgfkeys@temptoks\expandafter{%
\expandafter\pgfkeyssetvalue\expandafter{\pgf@expanded@path}{##1}}%
}%
\edef\pgfkeys@temp{\the\pgfkeys@temptoks}%
\pgfkeyspatchvalue\pgfkeys@temp{#1}{#2}%
\global\let\pgfkeys@global@temp\pgfkeys@temp
}%
\def\pgf@temp{\pgfkeyssetvalue{\pgf@expanded@path/.@body}}%
\expandafter\pgf@temp\expandafter{\pgfkeys@global@temp}%
\expandafter\long\expandafter\def\expandafter\pgfkeys@temp\expandafter##\expandafter1\expandafter\pgfeov\expandafter{\pgfkeys@global@temp}%
\pgfkeyslet{\pgf@expanded@path/.@cmd}\pgfkeys@temp
}%
}
% usage:
% \pgfkeyspatchvalue{<key>}{<search>}{<replace>}
% similar to \pgfkeysaddvalue
\long\def\pgfkeyspatchvalue#1#2#3{%
\pgfkeysifdefined{#1}{%
\expandafter\xpatchcmd\csname pgfk@#1\endcsname{#2}{#3}{}
{\PackageError{pgfkeys}{Patching for key #1 fails}}%
}{}%
}
\makeatother
\begin{document}
\tcbset{
colframe=black!25,
colbacktitle=black!75
}
\begin{tcolorbox}[boxrule=5pt, tabularx*={\arrayrulewidth0.5mm}{X|X|X}, title=Before patching]
One & Two & Three \\ \hline\hline
1000.00 & 2000.00 & 3000.00 \\ \hline
2000.00 & 3000.00 & 4000.00
\end{tcolorbox}
% patch option "tabularx*", remove "boxrule=0.5mm"
\tcbset{
tabularx*/.patch={boxrule=0.5mm}{}
}
\begin{tcolorbox}[boxrule=5pt, tabularx*={\arrayrulewidth0.5mm}{X|X|X}, title=After patching]
One & Two & Three \\ \hline\hline
1000.00 & 2000.00 & 3000.00 \\ \hline
2000.00 & 3000.00 & 4000.00
\end{tcolorbox}
\end{document}