我正在尝试合并彩色表格中的一些单元格。目前,表格如下所示:
我正在尝试合并标记为的四个单元格yy
,并为它们选择自定义颜色(颜色是可选的,但会很好)。
我已尝试对第 2 行至第 5 行进行此操作,但不幸的是,没有合并,并且指定到该单元格的文本也没有出现。
我的表格代码是:
\begin{table}[H]
\sffamily
\arrayrulecolor{white}
\arrayrulewidth=1pt
\renewcommand{\arraystretch}{1.5}
\rowcolors[\hline]{1}{.!50!White}{}
\centering
\begin{tabular}{@{} A|B|C @{}}
\cellcolor{ForestGreen}\arraycolor{White}\bfseries &
\cellcolor{ForestGreen}\arraycolor{White}\bfseries B &
\cellcolor{ForestGreen}\arraycolor{White}\bfseries C \\
\arraycolor{Black}
\multirow{4}{*}{xx} & \multicolumn{1}{l}{a2} & \multicolumn{1}{l}{b2} \\\cline{2-3}
& \multicolumn{1}{l}{a3} & \multicolumn{1}{l}{b3} \\\cline{2-3}
& \multicolumn{1}{l}{a4} & \multicolumn{1}{l}{b4} \\\cline{2-3}
& \multicolumn{1}{l}{a5} & \multicolumn{1}{l}{b5} \\\hline
\rotatebox{90}{yy} & a6& b6\\
\rotatebox{90}{yy} & a7& b7\\
\rotatebox{90}{yy} & a8& b8\\
\rotatebox{90}{yy} & a9& b9\\
\end{tabular}
\caption{caption}
\label{tab::buffer_order}
\end{table}
我的序言如下:
\usepackage[
dvipsnames, % defines the use of the colors from the dvips / SVG set
table, % allows the use of colors in tables
]{xcolor}
\usepackage{floatrow}
\usepackage{multirow}
\usepackage{graphicx}
% defines column types for colored tables
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{LimeGreen!50!white}}m{1cm}}
\newcolumntype{B}{>{\columncolor{LimeGreen!50!white}}m{5cm}}
\newcolumntype{C}{>{\columncolor{LimeGreen!50!white}}m{6cm}}
基本上,我试图垂直合并第一列中的单元格,以便该列中只有三个单元格,其中的文本是垂直书写的;同时保留其余行的配色方案,并可能选择合并单元格的颜色。
答案1
放置multirow
在相应 4 行的最后一行(使用-4
而不是4
then)文本就会显示出来。为了获得均匀着色的单元格,没有白线穿过,我使用了hhline
:
\documentclass{article}
\usepackage[
dvipsnames, % defines the use of the colors from the dvips / SVG set
table, % allows the use of colors in tables
]{xcolor}
\usepackage{floatrow}
\usepackage{multirow}
\usepackage{graphicx}
% defines column types for colored tables
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{LimeGreen!50!white}}m{1cm}}
\newcolumntype{B}{>{\columncolor{LimeGreen!50!white}}m{5cm}}
\newcolumntype{C}{>{\columncolor{LimeGreen!50!white}}m{6cm}}
\usepackage{hhline}
\begin{document}
\begin{table}[H]
\sffamily
\arrayrulecolor{white}
\arrayrulewidth=1pt
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{ A|B|C @{}}
\cellcolor{ForestGreen}\arraycolor{White}\bfseries &
\cellcolor{ForestGreen}\arraycolor{White}\bfseries B &
\cellcolor{ForestGreen}\arraycolor{White}\bfseries C \\
\hhline{---}
& \multicolumn{1}{l}{a2} & \multicolumn{1}{l}{b2} \\
\hhline{>{\arrayrulecolor{LimeGreen!50!white}}->{\arrayrulecolor{white}}|-|-}
& \multicolumn{1}{l}{a3} & \multicolumn{1}{l}{b3} \\
\hhline{>{\arrayrulecolor{LimeGreen!50!white}}->{\arrayrulecolor{white}}|-|-}
& \multicolumn{1}{l}{a4} & \multicolumn{1}{l}{b4} \\
\hhline{>{\arrayrulecolor{LimeGreen!50!white}}->{\arrayrulecolor{white}}|-|-}
\multirow{-4}{*}{xx} & \multicolumn{1}{l}{a5} & \multicolumn{1}{l}{b5} \\ \hline
\rowcolor{LimeGreen!25!white}\cellcolor{yellow} & a6& b6\\
\hhline{>{\arrayrulecolor{yellow}}->{\arrayrulecolor{white}}|--}
\cellcolor{yellow} & a7& b7\\
\hhline{>{\arrayrulecolor{yellow}}->{\arrayrulecolor{white}}|--}
\rowcolor{LimeGreen!25!White}\cellcolor{yellow} & a8& b8\\
\hhline{>{\arrayrulecolor{yellow}}->{\arrayrulecolor{white}}|--}
\cellcolor{yellow}\multirow{-4}{*}{\cellcolor{yellow}\rotatebox[origin=c]{90}{yy}} & a9& b9\\
\end{tabular}
\caption{caption}
\label{tab::buffer_order}
\end{table}
\end{document}
答案2
您可以使用 来做到这一点nicematrix
,而不需要hhline
或multirow
或colortbl
。
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{floatrow}
\usepackage{nicematrix}
\begin{document}
\begin{table}[H]
\sffamily
\renewcommand{\arraystretch}{1.5}
\centering
\begin{NiceTabular}{m{1cm}|m{5cm}|m{6cm}}[rules={color=white,width=1pt}]
\CodeBefore
\rowcolors{6}{LimeGreen!50!white}{LimeGreen!25!white}[cols=2-3]
\rowcolor{ForestGreen}{1}
\Body
\RowStyle[color=white]{\bfseries}
& B & C \\
\hline
\Block[fill=LimeGreen!50!white]{4-1}{xx}
& a2 & b2 \\
& a3 & b3 \\
& a4 & b4 \\
& a5 & b5 \\ \hline
\Block[fill=yellow]{4-1}{\rotate yy}
& a6 & b6 \\
& a7 & b7 \\
& a8 & b8 \\
& a9& b9 \\
\end{NiceTabular}
\caption{caption}
\label{tab::buffer_order}
\end{table}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。