表の列の色を変更する方法

表の列の色を変更する方法

テーブルに次のコードを使用しています:

\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(パッケージは、tableロード時にオプションによって呼び出され、拡張されますxcolor)。

MWE では列タイプ が定義されていないC{...}ため、 を使用しますp{...}。また、テーブルの幅がテキスト幅よりも広くなっています。

答え2

パッケージ「colortbl」を使用し、タグは でありcellcolorrowcolorcolumncolor

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

関連情報