![beamer、hhline 和 [table]{xcolor} 不兼容吗?](https://linux22.com/image/366729/beamer%E3%80%81hhline%20%E5%92%8C%20%5Btable%5D%7Bxcolor%7D%20%E4%B8%8D%E5%85%BC%E5%AE%B9%E5%90%97%EF%BC%9F.png)
以下示例按预期工作:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{makecell, multirow}
\renewcommand\theadfont{\normalsize\bfseries\color{white}}
\renewcommand{\theadgape}{}
\usepackage{hhline}
\begin{document}
\centering
\setlength\arrayrulewidth{2pt}
\arrayrulecolor{yellow}
\def\clinecolor{\hhline{>{\arrayrulecolor{yellow}}--%
>{\arrayrulecolor{gray}}-}}
\setlength\extrarowheight{2pt}
\begin{tabular}{ c | c | c }%
\rowcolor{gray}
\multicolumn{2}{c|}{\thead{AAA -- BBBB}} & \\
\clinecolor
\rowcolor{gray}
\color{white} AAA & \color{white} BBB & \multirow{-2}{*}{\thead{CCC}} \\
\hhline{>{\arrayrulecolor{yellow}}-|-|-}
\rowcolor{gray!25}
aaa & bbb & ccc \\
\hline
\rowcolor{gray!25}
ddd & eee & fff
\end{tabular}
\end{document}
但以下不是:
\documentclass[xcolor=table]{beamer}
\usepackage{makecell, multirow}
\renewcommand\theadfont{\normalsize\bfseries\color{white}}
\renewcommand{\theadgape}{}
\usepackage{hhline}
\begin{document}
\begin{frame}
\frametitle{test}
\centering
\setlength\arrayrulewidth{2pt}
\arrayrulecolor{yellow}
\def\clinecolor{\hhline{>{\arrayrulecolor{yellow}}--%
>{\arrayrulecolor{gray}}-}}
\setlength\extrarowheight{2pt}
\begin{tabular}{ c | c | c }%
\rowcolor{gray}
\multicolumn{2}{c|}{\thead{AAA -- BBBB}} & \\
\clinecolor
\rowcolor{gray}
\color{white} AAA & \color{white} BBB & \multirow{-2}{*}{\thead{CCC}} \\
\hhline{>{\arrayrulecolor{yellow}}-|-|-}
\rowcolor{gray!25}
aaa & bbb & ccc \\
\hline
\rowcolor{gray!25}
ddd & eee & fff \\
\hhline{|-|-|-|}
\end{tabular}
\end{frame}
\end{document}
为什么 Beamer 中的规则如此奇怪地错位?有没有什么解决方法?
答案1
正如 samcarter 评论的那样
\documentclass[xcolor=table]{beamer}
\usepackage{makecell, multirow}
\renewcommand\theadfont{\normalsize\bfseries\color{white}}
\renewcommand{\theadgape}{}
\usepackage{hhline}
\makeatletter
\let\zz\reset@color
\def\reset@color{\kern\z@\zz}
\makeatother
\begin{document}
\begin{frame}
\frametitle{test}
\centering
\setlength\arrayrulewidth{2pt}
\arrayrulecolor{yellow}
\def\clinecolor{\hhline{>{\arrayrulecolor{yellow}}--%
>{\arrayrulecolor{gray}}-}}
\setlength\extrarowheight{2pt}
\begin{tabular}{ c | c | c }%
\rowcolor{gray}
\multicolumn{2}{c|}{\thead{AAA -- BBBB}} & \\
\clinecolor
\rowcolor{gray}
\color{white} AAA & \color{white} BBB & \multirow{-2}{*}{\thead{CCC}} \\
\hhline{>{\arrayrulecolor{yellow}}-|-|-}
\rowcolor{gray!25}
aaa & bbb & ccc \\
\hline
\rowcolor{gray!25}
ddd & eee & fff \\
\hhline{|-|-|-|}
\end{tabular}
\end{frame}
\end{document}
答案2
改为使用booktabs
– 更准确地设置\above/belowrulesep
为0pt
并使用\midrule
:
\documentclass[xcolor=table]{beamer}
\usepackage{makecell, multirow}
\usepackage{booktabs}
\renewcommand\theadfont{\normalsize\bfseries\color{white}}
\renewcommand{\theadgape}{}
\begin{document}
\begin{frame}
\frametitle{test}
\centering
\setlength\arrayrulewidth{2pt}
\setlength\extrarowheight{2pt}
\setlength\belowrulesep{0pt}\setlength\aboverulesep{0pt}
\setlength\lightrulewidth{2pt}
\arrayrulecolor{yellow}
\begin{tabular}{ c | c | c }%
\rowcolor{gray}
\multicolumn{2}{c|}{\thead{AAA -- BBBB}} & \\
\midrule
\rowcolor{gray}
\color{white} AAA & \color{white} BBB & \multirow{-2}{*}{\thead{CCC}} \\
\midrule
\rowcolor{gray!25}
aaa & bbb & ccc \\
\midrule
\rowcolor{gray!25}
ddd & eee & fff \\
\end{tabular}
\end{frame}
\end{document}
答案3
带有以下软件包的变体tabularray
:
\documentclass{beamer}
\usepackage{tabularray}
\begin{document}
\begin{frame}
\centering
\begin{tblr}{
colspec={ccc},
row{1-2}={bg=gray,fg=white},
row{1}={font=\bfseries},
row{3-Z}={bg=lightgray},
hline{2-Y}={yellow,wd=2pt},
vline{2-Y}={yellow,wd=2pt},
}
\SetCell[c=2]{} AAA - BBBB & & \SetCell[r=2]{} CCC \\
AAA & BBB & \\
aaa & bbb & ccc \\
ddd & eee & fff
\end{tblr}
\end{frame}
\end{document}
答案4
使用,您可以绘制所有规则,{NiceTabular}
但边界和块(由 创建)除外。nicematrix
hvlines-except-borders
\Block
\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}
\begin{document}
\begin{center}
\arrayrulecolor{yellow}
\setlength{\arrayrulewidth}{2pt}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{10pt}
\begin{NiceTabular}{ccc}[hvlines-except-borders]
\RowStyle[nb-rows=2,color=white,rowcolor=gray]{}
\RowStyle[bold]{}
\Block{1-2}{AAA - BBBB} & & \Block{2-1}{CCC} \\
AAA & BBB \\
\RowStyle[nb-rows=2,rowcolor=gray!25]{}
aaa & bbb & ccc \\
ddd & eee & fff
\end{NiceTabular}
\arrayrulecolor{black}
\end{center}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。
结果可能令人失望。垂直规则\arrayrulewidth
在设计上从数组下方突出的长度等于...在最常见的情况下,使用垂直规则进行完美连接很有用...
但是,使用nicematrix
(version ≥ 6.12),可以用 在末尾绘制一条白色规则\Hline[color=white]
。
\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix,tikz}
\begin{document}
\begin{center}
\arrayrulecolor{yellow}
\setlength{\arrayrulewidth}{2pt}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{10pt}
\begin{NiceTabular}{ccc}[hvlines-except-borders]
\RowStyle[nb-rows=2,color=white,rowcolor=gray]{}
\RowStyle[bold]{}
\Block{1-2}{AAA - BBBB} & & \Block{2-1}{CCC} \\
AAA & BBB \\
\RowStyle[nb-rows=2,rowcolor=gray!25]{}
aaa & bbb & ccc \\
ddd & eee & fff
\Hline[color=white]
\end{NiceTabular}
\arrayrulecolor{black}
\end{center}
\end{document}
但还有另一种方法。可以用字母 ( I
) 和命令定义一种新类型的规则\MyLine
,并在序言中和行之间使用它。
\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix,tikz}
\NiceMatrixOptions
{
custom-line =
{
letter = I ,
command = MyLine ,
total-width = 2pt ,
tikz = { line width = 2pt , yellow }
}
}
\begin{document}
\begin{center}
\setlength{\arrayrulewidth}{0pt}
\begin{NiceTabular}{cIcIc}[columns-width=15mm,cell-space-limits=3pt]
\RowStyle[nb-rows=2,color=white,rowcolor=gray]{}
\RowStyle[bold]{}
\Block{1-2}{AAA - BBBB} & & \Block{2-1}{CCC} \\
\MyLine
AAA & BBB \\
\MyLine
\RowStyle[nb-rows=2,rowcolor=gray!25]{}
aaa & bbb & ccc \\
\MyLine
ddd & eee & fff
\end{NiceTabular}
\arrayrulecolor{black}
\end{center}
\end{document}
现在,垂直规则突出于数组下方,其值为,\arrayrulewidth
但值\arrayrulewidth
为零。因此,输出是完美的。