我有一张表格,我需要给它的第一行上色,类似于第二个示例,但是,由于命令的原因,它不起作用 \multirow
,尽管有行命令,但无法完成。如果我使用\cellcolor
任务词将被剪裁。
\begin{table}[b!]
\begin{center}
\renewcommand{\arraystretch}{1.4}
\scriptsize
\begin{tabular}{|m{0.17\textwidth}| % <-- use 'm', not 'p', col. type
m{0.1\textwidth}|
m{0.11\textwidth}|
m{0.12\textwidth}|
m{0.12\textwidth}|
}
\hline \hline
\multirow{ 2}{*}{A} & \multicolumn{2}{c|}{X} & \multicolumn{2}{c|}{Y} \\ \cline{2-5} & Z & L &M & N
\end{tabular}
\end{center}
\end{table}
\begin{table}[t!]
\begin{center}
\renewcommand{\arraystretch}{1.4}
\scriptsize
\begin{tabular}{|m{0.17\textwidth}| % <-- use 'm', not 'p', col. type
m{0.06\textwidth}|
m{0.11\textwidth}|
m{0.12\textwidth}|
m{0.12\textwidth}|
m{0.18\textwidth}|
}
\hline \hline
\rowcolor{myblue!30}
A & B & C & D & E & F\\ \hline \hline
\end{tabular}
\end{center}
\label{Table01}
\end{table}
答案1
诀窍是从底部到顶部合并单元格,并\multirow
在最后一个合并单元格中应用负参数
\documentclass{article}
\usepackage{array}
\usepackage{multirow}
\usepackage[svgnames]{xcolor}
\usepackage{colortbl}
\colorlet{myblue}{Blue!30}
\begin{document}
\begin{table}
\centering
\renewcommand{\arraystretch}{1.4}
\scriptsize
\begin{tabular}{|
m{0.17\textwidth}|
m{0.1\textwidth}|
m{0.11\textwidth}|
m{0.12\textwidth}|
m{0.12\textwidth}|
}
\hline\hline
\cellcolor{myblue}
& \multicolumn{2}{c|}{X} & \multicolumn{2}{c|}{Y} \\
\cline{2-5}
\cellcolor{myblue}\multirow{-2}{*}{A}
& Z & L & M & N \\
\hline\hline
\end{tabular}
\end{table}
\end{document}
答案2
另一种解决方案是tabularray
:
\documentclass{article}
\usepackage{tabularray}
\usepackage[svgnames]{xcolor}
\colorlet{myblue}{Blue!30}
\begin{document}
\begin{table}
\centering\scriptsize
\begin{tblr}{
colspec={X[1.7]XX[1.1]*2{X[1.2]}},
vlines, hlines,
stretch=1.4,
cell{1}{1}={r=2}{bg=myblue},
cell{1}{2,4}={c=2}{c},
}
\hline
A & X & & Y & \\
& Z & L & M & N \\
\hline
\end{tblr}
\end{table}
\end{document}