
이 테이블이 있는데 셀의 색상을 변경하고 싶습니다. 저는 "Orange", "DarkGrey", "lightGrey" 색상을 정의했습니다. 맨 위 제목 행을 주황색으로 만들었고, 첫 번째 열의 나머지 셀은 짙은 회색으로, 다른 모든 열의 나머지 셀은 밝은 회색으로 만들고 싶습니다. 어떻게 해야 하나요?
\centering
\begin{tabularx}{1\textwidth} {
| >{\centering\arraybackslash}X
| >{\centering\arraybackslash}X
| >{\centering\arraybackslash}X | }
\hline
\rowcolor{Orange}\multicolumn{3}{|c|}{\textcolor{white}{\textbf{Title}}} \\
\hline
item 11 & item 12 & item 13 \\
\hline
item 21 & item 22 & item 23 \\
\hline
\end{tabularx}
답변1
배경색을 지정하려면 다음과 같이 하세요.
\documentclass{article}
\usepackage[table, svgnames]{xcolor}
\usepackage{tabularx}
\begin{document}
\centering
\begin{tabularx}{1\textwidth} {
| >{\centering\arraybackslash\columncolor{DarkGrey}}X
| >{\centering\arraybackslash\columncolor{LightGrey}}X
| >{\centering\arraybackslash\columncolor{LightGrey}}X | }
\hline
\rowcolor{Orange}\multicolumn{3}{|c|}{\textcolor{white}{\textbf{Title}}} \\
\hline
item 11 & item 12 & item 13 \\
\hline
item 21 & item 22 & item 23 \\
\hline
\end{tabularx}
\end{document}
답변2
tabularray 패키지 사용
\documentclass{article}
\usepackage{tabularray}
\usepackage{xcolor}
\begin{document}
\begin{tblr}
{
hlines,vlines,
colspec=*{3}{X[c,bg=gray!25]},
column{1} = {bg=gray!75},
row{1} = {bg=orange, fg=white, font=\bfseries},
cell{1}{1} = {c=3}{c},%<-- the multicol
}
Title\\
item 11 & item 12 & item 13 \\
item 21 & item 22 & item 23
\end{tblr}
\end{document}
답변3
의 .{NiceTabular}
nicematrix
\documentclass{article}
\usepackage{nicematrix}
\usepackage{xcolor}
\begin{document}
\begin{NiceTabular}{X[c]X[c]X[c]}[hvlines]
\CodeBefore
\columncolor{gray!75}{1}
\columncolor{gray!25}{2,3}
\rowcolor{orange}{1}
\Body
\Block{1-3}{\color{white}\sffamily\bfseries Title}\\
item 11 & item 12 & item 13 \\
item 21 & item 22 & item 23
\end{NiceTabular}
\end{document}
여러 컴파일이 필요합니다( nicematrix
내부적으로 PGF/Tikz 노드를 사용하기 때문에).