仍在处理精美的表格,现在我正尝试获取具有多列和多行单元格的表格。
我可以正确获得多列单元格,但我仍然在努力处理多行单元格。
Beamer 中的 MWE:
\documentclass[xcolor={dvipsnames,table}]{beamer}
%%TABLE
\usepackage{multirow}
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{red!20}}c}
\newcolumntype{B}{>{\columncolor{blue!20}}c}
\mode<presentation> {
\usetheme[compress]{Singapore}
\usecolortheme{orchid}
}
\begin{document}
\begin{frame}
\sffamily
\arrayrulecolor{white}
\arrayrulewidth=1pt
\renewcommand{\arraystretch}{1}
\rowcolors[\hline]{2}{.!50!White}{}
\resizebox{\linewidth}{!}{%
\begin{tabular}{A|A|A|A|A|B|B|B|A}
\rowcolor{.!50!Black}
\multicolumn{5}{A|}{\arraycolor{White}\bfseries 14 subjects} &
\multicolumn{3}{B|}{\arraycolor{White}\bfseries 10 subjects} &
\multirow{2}{*}{\arraycolor{White}\bfseries Control}\\
\rowcolor{.!50!Black}
\multicolumn{3}{A|}{\arraycolor{White} Surface} &
\multicolumn{2}{A|}{\arraycolor{White} Follicle} &
\multicolumn{3}{B|}{\arraycolor{White} Surface} & \\
No les & Non-inf & Inf & Non-inf & Inf & Cheek & Fh & Nose & Mock\\
\end{tabular}
}%
\end{frame}
\end{document}
编辑!
我看了建议可能重复的问题,但我似乎仍然没有正确理解...但我觉得它已经快完成了。
请查看下面我更新的 MWE:
\documentclass[xcolor={dvipsnames,table}]{beamer}
%%TABLE
\usepackage{makecell, multirow}
\renewcommand\theadfont{\arraycolor{White}\bfseries}
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{red!20}}c}
\newcolumntype{B}{>{\columncolor{blue!20}}c}
\mode<presentation> {
\usetheme[compress]{Singapore}
\usecolortheme{orchid}
}
\begin{document}
\begin{frame}
\sffamily
\arrayrulecolor{white}
\arrayrulewidth=1pt
\renewcommand{\arraystretch}{1}
\rowcolors[\hline]{2}{.!50!White}{}
\resizebox{\linewidth}{!}{%
\begin{tabular}{A|A|A|A|A|B|B|B|A}
\rowcolor{.!50!Black}
\multicolumn{5}{A|}{\arraycolor{White}\bfseries 14 subjects} &
\multicolumn{3}{B|}{\arraycolor{White}\bfseries 10 subjects} & \\
\rowcolor{.!50!Black}
\multicolumn{3}{A|}{\arraycolor{White} Surface} &
\multicolumn{2}{A|}{\arraycolor{White} Follicle} &
\multicolumn{3}{B|}{\arraycolor{White} Surface} &
\multirow{-2}{*}{\thead{Control}}\\
No les & Non-inf & Inf & Non-inf & Inf & Cheek & Fh & Nose & Mock\\
\end{tabular}
}%
\end{frame}
\end{document}
其结果为:
答案1
像这样?
主要问题是组成行颜色和文本着色。用更基本的方法代替它们并考虑大卫·卡莱尔回答 我的问题解决方案是:
\documentclass[xcolor={dvipsnames,table}]{beamer}
%%TABLE
\usepackage{multirow}
\usepackage{hhline}
\makeatletter
\let\zz\reset@color
\def\reset@color{\kern\z@\zz}
\makeatother
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{red!20}}c}
\newcolumntype{B}{>{\columncolor{blue!20}}c}
\mode<presentation> {
\usetheme[compress]{Singapore}
\usecolortheme{orchid}
}
\begin{document}
\begin{frame}
\sffamily
\arrayrulewidth=1pt
\arrayrulecolor{white}
\resizebox{\linewidth}{!}{%
\begin{tabular}{A|A|A|A|A|B|B|B|A}
\rowcolor{.!50!Black}
\multicolumn{5}{A|}{\color{White}\bfseries 14 subjects} &
\multicolumn{3}{B|}{\color{White}\bfseries 10 subjects} & \\
\hhline{>{\arrayrulecolor{white}}--------%
>{\arrayrulecolor{red!20!black!60}}-}
\rowcolor{.!50!Black}
\arrayrulecolor{white}
\multicolumn{3}{A|}{\color{White} Surface} &
\multicolumn{2}{A|}{\color{White} Follicle} &
\multicolumn{3}{B|}{\color{White} Surface} &
\multirow{-2}{*}{\color{white}Control}\\
\hline
No les & Non-inf & Inf & Non-inf & Inf & Cheek & Fh & Nose & Mock\\
\end{tabular}
}%
\end{frame}
\end{document}
附录:
经过近四年的时间,我将为该表使用一个tabularray
可以更好地处理行、列和单元格着色的新包:
使用它的表格代码更简短,更清晰:
\documentclass{beamer}
\usepackage{tabularray}
\begin{document}
\begin{frame}
\frametitle{Table}
\centering
\sffamily
\small
\begin{tblr}{colspec={ c },
colsep = 5pt,
row{1} = {font=\bfseries, bg=black!80, fg=white},
row{2} = {bg=black!80, fg=white},
row{3} = {bg=red!30, fg=white},
hlines={1pt, fg=white}, vlines={1pt, fg=white},
}
\SetCell[c=5]{c} 14 subjects
& & & & & \SetCell[c=3]{c} subjects
& & & \SetCell[r=2]{c} Control \\
\SetCell[c=3]{c} Surface
& & & \SetCell[c=2]{c} Follicle
& & \SetCell[c=3]{c} Surface
& & & \\
No les
& Non-inf
& Inf
& Non-inf
& Inf
& \SetCell{bg=blue7} Cheek
& \SetCell{bg=blue7} Fh
& \SetCell{bg=blue7} Nose
& Mock \\
\end{tblr}
\end{frame}
\end{document}
答案2
{NiceTabular}
这是使用制作该表格的一种方法nicematrix
。无论您使用哪种 PDF 查看器,单元格“控件”中都不会出现任何模糊的线条。
\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{nicematrix}
\mode<presentation> {
\usetheme[compress]{Singapore}
\usecolortheme{orchid}
}
\begin{document}
\newcolumntype{A}{>{\columncolor{red!20}}c}
\newcolumntype{B}{>{\columncolor{blue!20}}c}
\begin{frame}
\begin{center}
\sffamily
\small
\setlength{\tabcolsep}{5pt}
\renewcommand{\arraystretch}{1.2}
\begin{NiceTabular}{AAAAABBBA}[rules={color=white,width=1pt},hvlines-except-borders,colortbl-like]
\CodeBefore
\rowcolor{.!50!Black}{1,2}
\Body
\RowStyle[nb-rows=2,color=white]{}
\RowStyle[bold]{}
\Block{1-5}{14 subjects} &&&&& \Block{1-3}{10 subjects} &&& \Block{2-1}{Control}\\
\Block{1-3}{Surface} &&& \Block{1-2}{Follicle} && \Block{1-3}{Surface} \\
No les & Non-inf & Inf & Non-inf & Inf & Cheek & Fh & Nose & Mock\\
\end{NiceTabular}
\end{center}
\end{frame}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。