如何更改表格中列的颜色

如何更改表格中列的颜色

我正在将此代码用于表格:

\documentclass[a4paper, 12pt, oneside]{Thesis}

\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{array}

\begin{document}
\begin{table}[H]
\centering
{\renewcommand{\arraystretch}{2}
\begin{tabular}{ |c|C{5cm}|C{5cm}|C{5cm}|}
\hline
\textbf{} & \textbf{A} & \textbf{B} & \textbf{C} \\ 
\hline
 & Means of Mounting & Material & Means of De-mounting \\ \hline   
1 & Friction & Rubber & Lever \\ \hline
2 & Tight Fit(Formschluss) & Magnet & Complete Removal \\ \hline
3 & Holes & Alloy & Spring/Elasticity \\ \hline

\end{tabular}}
\caption{Morphological Box}

\end{table}

\end{document}

我想给每列的背景上色

答案1

在此处输入图片描述

\documentclass[a4paper, 12pt, oneside]{Thesis}

\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{array}

\begin{document}
\begin{table}
\centering
{\renewcommand{\arraystretch}{2}
\begin{tabular}{ |>{\columncolor{red!30}}c|
                  >{\columncolor{blue!30}}p{5cm}|
                  >{\columncolor{yellow!30}}p{5cm}|
                  >{\columncolor{green!30}}p{5cm}|}
\hline
\textbf{} & \textbf{A} & \textbf{B} & \textbf{C} \\
\hline
 & Means of Mounting & Material & Means of De-mounting \\ \hline
1 & Friction & Rubber & Lever \\ \hline
2 & Tight Fit(Formschluss) & Magnet & Complete Removal \\ \hline
3 & Holes & Alloy & Spring/Elasticity \\ \hline

\end{tabular}}
\caption{Morphological Box}

\end{table}

\end{document}

您可以在包的文档中找到如何为表格着色的详细信息(在加载时colortbl通​​过选项调用和扩展)。tablexcolor

在您的 MWE 中,您没有定义列类型C{...},因此我使用p{...}。此外,您的表格比文本宽度更宽。

答案2

使用包“ colortbl”且标签为cellcolorrowcolor并且columncolor

\documentclass[a4paper, 12pt, oneside]{Thesis}

\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{array}
\usepackage{colortbl}
\begin{document}
\begin{table}
\centering
{\renewcommand{\arraystretch}{2}
\begin{tabular}{ |c|c|c|c|}
\hline
\textbf{} & \textbf{A} & \textbf{B} & \textbf{C} \\ 
\hline\rowcolor{cyan!10}
 & Means of Mounting & Material & Means of De-mounting \\ \hline   
1 & \cellcolor{cyan!20}Friction & Rubber & Lever \\ \hline
2 & Tight Fit(Formschluss) & Magnet & Complete Removal \\ \hline
3 & \multicolumn{1}{>{\columncolor{cyan!20}}c}{Holes} & Alloy & Spring/Elasticity \\ \hline

\end{tabular}}
\caption{Morphological Box}

\end{table}

相关内容