我想为表格中某些单元格中的一行文本的背景着色。我需要获得如下结果:
我尝试过\columncolor
,\cellcolor
但它们没有给我留下白色边框。这是我的示例代码:
\begin{tabular}{|l|l|l|}
\hline
ID: \cellcolor{gray}{0.9} & blabla & blabla \\ \hline
Title: & blabla & blabla \\ \hline
State: & blabla & blabla\\ \hline
Description: & blabla & blabla \\ \hline
Type: & blabla & blabla \\ \hline
Priority: & blabla & blabla \\ \hline
\end{tabular}
答案1
\documentclass[12pt]{article}
\usepackage{color}
\newcommand\celltitle[1]{{\fboxrule=0pt\fbox{\colorbox[gray]{0.9}{\makebox[3cm]{#1}}}}}
\begin{document}
\begin{tabular}{|l|l|l|}
\hline
\celltitle{ID:} & blabla & blabla \\ \hline
\celltitle{Title:} & blabla & blabla \\ \hline
\celltitle{State:} & blabla & blabla\\ \hline
\celltitle{Description:} & blabla & blabla \\ \hline
\celltitle{Type:} & blabla & blabla \\ \hline
\celltitle{Priority:} & blabla & blabla \\ \hline
\end{tabular}
\end{document}
答案2
以下是对您的代码的简单调整。它需要包color
和colortbl
。关键点是使用命令定义颜色\definecolor
。
\documentclass[12pt]{article}
\usepackage{color,colortbl}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{tabular}{|l|l|l|}
\hline
\cellcolor{Gray}ID: & blabla & blabla \\ \hline
\cellcolor{Gray}Title: & blabla & blabla \\ \hline
\cellcolor{Gray}State: & blabla & blabla\\ \hline
\cellcolor{Gray}Description: & blabla & blabla \\ \hline
\cellcolor{Gray}Type: & blabla & blabla \\ \hline
\cellcolor{Gray}Priority: & blabla & blabla \\ \hline
\end{tabular}
\end{document}