我正在将此代码用于表格:
\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
”且标签为cellcolor
,rowcolor
并且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}