테이블의 열 색상을 변경하는 방법

테이블의 열 색상을 변경하는 방법

테이블에 이 코드를 사용하고 있습니다.

\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하고 태그는 입니다 cellcolor.rowcolorcolumncolor

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

관련 정보