如何更改表格中列的顏色

如何更改表格中列的顏色

我在表中使用此程式碼:

\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}

相關內容