使用Latex生成带有不同颜色单元格的表格。

5

我正在攻读图论中数学博士学位。在我的论文中,我需要在Latex表格中为特定的单元格行(图的边缘)涂色。这个可以实现吗?我只找到了一种能够给整行上色的方法。


你好!请让我们更好地理解您的意思,您是想给单元格中的文本着色还是包括单元格的边框(如果有的话)?您能否请发布一下您自己的代码,在那里您实现了整行着色? - MattAllegro
2个回答

10
您可以使用xcolor包中的\cellcolor来着色特定单元格:
\documentclass{standalone}

\usepackage[table]{xcolor}

\begin{document}

\begin{tabular}{r|c|l}
    A & B & C \\\hline
    1 & 2 & 3 \\\hline
    x & y & \cellcolor{red!25}z
\end{tabular}

\end{document}

enter image description here


3
太好了,我不知道这个!此外,人们可以组合使用:\cellcolor{red!25}\color{blue}{z} - MattAllegro

1

首先建议,如果您的表格不太大,可以手动为每个单元格中的文本上色:

\documentclass[english]{report}
\usepackage{color}
\usepackage{booktabs}

\definecolor{light-blue}{rgb}{0.6,0.6,1}

\begin{document}

\begin{table}
\begin{tabular}{lr}
\toprule
\color{red}{Some text} & \color{light-blue}{and some other}\\
\color{cyan}{inside} & \color{green}{a table}\\
\bottomrule
\end{tabular}
\end{table}

\end{document}

产生以下表格。

screenshot of the output

默认颜色为blackwhiteredgreenbluecyanmagentayellow,更多详细信息请参见here
此外,为了给单元格着色,我建议使用名为ytableau的包。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接