我有一个简单的表格,例如:
\documentclass[varwidth]{standalone}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{multirow}
\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.9}
\begin{tabular}{cc}
\cellcolor[rgb]{0.0,0.5,1.0}Unsolvability & \multirow{2}{*}{ \cellcolor[rgb]{0.91,0.91,0.91}Chapter 7}\\
\cellcolor[rgb]{0.0,0.5,1.0}Relaxation & \cellcolor[rgb]{0.91,0.91,0.91}\\
\end{tabular}
\end{center}
\end{document}
但是输出并不是我真正想要的,因为背景颜色覆盖了单元格的文本。
我该如何修复这个问题?
答案1
只需更改\multirow{2}{*}{...}
为\multirow{-2}{*}{...}
:
\documentclass[varwidth]{standalone}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{multirow}
\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.9}
\begin{tabular}{cc}
\cellcolor[rgb]{0.0,0.5,1.0}Unsolvability & \cellcolor[rgb]{0.91,0.91,0.91}\\
\cellcolor[rgb]{0.0,0.5,1.0}Relaxation & \multirow{-2}{*}{ \cellcolor[rgb]{0.91,0.91,0.91}Chapter 7}\\
\end{tabular}
\end{center}
\end{document}
但是,在这种情况下,将表格嵌套在左列更为简单。
\documentclass{standalone}
\usepackage[table]{xcolor}
\renewcommand{\arraystretch}{1.9}
\definecolor{left}{rgb}{0.0,0.5,1.0}
\definecolor{right}{rgb}{0.91,0.91,0.91}
\begin{document}
\begin{tabular}{cc}
\cellcolor{left}%
\begin{tabular}{@{}c@{}}
Unsolvability \\ Relaxation
\end{tabular}
& \cellcolor{right}Chapter 7
\end{tabular}
\end{document}
答案2
使用\columncolor
更简单:
\documentclass[varwidth]{standalone}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{multirow}
\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.9}
\begin{tabular}{>{\columncolor[rgb]{0.0,0.5,1.0}}c
>{\columncolor[rgb]{0.91,0.91,0.91}}c}
Unsolvability & \\
Relaxation & \multirow{-2}{*}{Chapter 7} \\
\end{tabular}
\end{center}
\end{document}
答案3
我的感觉是,您正在以表格的形式执行绘图任务,而不是使用带有彩色单元格的真实表格。在这种情况下,为什么不使用 Ti钾直接使用 Z?它功能强大,而且相对简单,文档也很丰富。
\documentclass[varwidth]{standalone}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{multirow,tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[blk/.style={minimum height=4em,align=center}]
\path [fill=blue!50] (0,0) rectangle (3,2) node[blk,pos=.5] {Unsolvability\\[.5em]Relaxation};
\path [fill=gray!20] (3,0) rectangle (6,2) node[blk,pos=.5] {Chapter 7};
\end{tikzpicture}
\end{center}
\end{document}