
저는 LaTex를 처음 사용하는데 이 테이블에 약간의 문제가 있습니다... 그런 종류의 테이블을 많이 작성해야 하는데 이 문제를 자동으로 해결하는 방법을 찾고 싶습니다. 누군가 나를 도와줄 수 있나요? 아래에서 내 코드와 테이블을 찾을 수 있습니다.
정말 감사합니다!
\documentclass{article}
\usepackage{multirow}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{rotating}
\begin{document}
\begin{table}[!ht]
\begin{center}
\caption{Matrice de confusion pour les classes texturales concernant notre campagne d’échantillonnage.}
\begin{tabular}{|
>{\columncolor[HTML]{C0C0C0}}c |
>{\columncolor[HTML]{EFEFEF}}c |c|c|c|c|}
\hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{C0C0C0}} & \multicolumn{5}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Texture\\ observée sur le terrain\end{tabular}}} \\ \hline
\cellcolor[HTML]{C0C0C0} & & \cellcolor[HTML]{EFEFEF}A & \cellcolor[HTML]{EFEFEF}L & \cellcolor[HTML]{EFEFEF}Z & \cellcolor[HTML]{EFEFEF}\textbf{Total} \\ \cline{2-6}
\cellcolor[HTML]{C0C0C0} & A & 3 & 2 & 0 & 5 \\ \cline{2-6}
\cellcolor[HTML]{C0C0C0} & L & 4 & 7 & 0 & 11 \\ \cline{2-6}
\cellcolor[HTML]{C0C0C0} & Z & 0 & 1 & 3 & 4 \\ \cline{2-6}
\multirow{-5}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\rotatebox{90}{Référence CNSW}}} & \textbf{Total} & 7 & 10 & 3 & \textbf{20} \\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}
답변1
나는 항상 테이블의 과도한 색상을 피하려고 노력했습니다. 깨끗하고 깔끔하게 유지하세요. 마지막에는 더 읽기 쉽습니다!
즉, 여기에 한 가지 가능한 해결책이 있습니다. 하지만 위치 를 수동으로 미세 조정해야 합니다 \parbox
.
\documentclass{article}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{rotating}
\renewcommand\theadalign{bc}
\renewcommand\theadfont{\bfseries}
\begin{document}
\begin{table}[!ht]
\caption{Matrice de confusion pour les classes texturales concernant notre campagne d’échantillonnage.}
\begin{center}
\begin{tabular}{*{6}{c}}
\toprule
& \multicolumn{5}{c}{\thead{Texture\\ observée sur le terrain}}\\
\midrule
\multirow{5}{*}{\rotatebox{90}{\parbox[c]{2.2cm}{\centering\textbf{Référence CNSW}}}}
&
& A
& L
& Z
& \textbf{Total}\\
& A
& 3
& 2
& 0
& 5\\
& L
& 4
& 7
& 0
& 11\\
& Z
& 0
& 1
& 3
& 4\\\addlinespace
& \textbf{Total}
& 7
& 10
& 3
& \textbf{20} \\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}
답변2
를 사용하면 nicematrix
모든 확대/축소 수준에서 모든 PDF 뷰어에서 완벽한 출력을 얻을 수 있습니다(회색 패널에 가는 흰색 선이 없으며 특정 확대/축소 수준에서 규칙이 사라지지 않는 것처럼 보입니다).
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{caption}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-top-limit=2pt}
\begin{document}
\begin{table}[!ht]
\centering
\captionsetup{width=9cm, format=hang}
\setlength{\extrarowheight}{2pt}
\caption{Matrice de confusion pour les classes texturales concernant notre campagne d’échantillonnage.}
\begin{NiceTabular}{cccccc}[hvlines,corners=NW]
\CodeBefore
\rectanglecolor{LightGrey!50}{2-2}{2-6}
\Body
& \Block[fill=LightGrey]{1-5}<\bfseries>{Texture\\ observée sur le terrain} \\
\Block[fill=LightGrey]{5-1}<\bfseries\rotate>{Référence\\CNSW} &
\Block[fill=LightGrey!50]{5-1}{}
& A & L & Z & \textbf{Total} \\
& A & 3 & 2 & 0 & 5 \\
& L & 4 & 7 & 0 & 11 \\
& Z & 0 & 1 & 3 & 4 \\
& \textbf{Total} & 7 & 10 & 3 & \textbf{20} \\
\end{NiceTabular}
\end{table}
\end{document}
nicematrix
PGF/Tikz 노드를 사용하기 때문에 여러 컴파일이 필요합니다 .
답변3
다음은 다양한 개선 사항과 코드 단순화가 포함된 솔루션입니다. 특정 문제의 경우 주요 도구는 makecell
표준 셀에서 줄 바꿈을 허용하는 패키지입니다. 단, 장면 뒤에 표 형식이 있기 때문에 표의 색상과 잘 작동하지 않습니다. \Centerstack
의 명령에는 이 stackengine
문제가 없습니다. 또한, 로드 xcolor
할 필요가 없으며 xcolor colortbl
옵션 table
이 이를 수행하고 테이블에 대한 색상 명령을 더 추가합니다. 마지막으로 \cline
컬러 테이블에는 가는 흰색 선이 몇 개 남아 있으므로 \hhline
선의 일부가 배경색이 되도록 s로 대체하여 보이지 않게 했습니다.
\documentclass{article}
\usepackage{multirow}
\usepackage[table, svgnames]{xcolor}
\colorlet{grey2}{LightGrey!25}
\usepackage{rotating}
\usepackage{caption, makecell, hhline}
\newcommand{\myhhline}{\hhline{|>{\arrayrulecolor{LightGrey}}- > {\arrayrulecolor{black}}|>{\arrayrulecolor{grey2}}->{\arrayrulecolor{black}}|----|}}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\begin{table}[!ht]
\centering
\captionsetup{width=9cm, format=hang}
\setlength{\extrarowheight}{2pt}
\caption{Matrice de confusion pour les classes texturales concernant notre campagne d’échantillonnage.}
\begin{tabular}{|
>{\columncolor{LightGrey}}c |
>{\columncolor{grey2}}c|c|c|c|c|}
\hline
\rowcolor{LightGrey} & \multicolumn{5}{c|}{\bfseries\Centerstack{Texture\\ observée sur le terrain}} \\ \hline
\rowcolor{grey2}\cellcolor{LightGrey} & & A & L & Z & \textbf{Total} \\[-0.2pt]
\myhhline
& A & 3 & 2 & 0 & 5 \\[-0.1pt]
\myhhline%
& L & 4 & 7 & 0 & 11 \\[-0.1pt]
\myhhline
& Z & 0 & 1 & 3 & 4 \\[-0.1pt]
\myhhline
\multirow{-5}{*}{\textbf{\rotatebox{90}{\Centerstack{Référence\\ CNSW}}}} & \textbf{Total} & 7 & 10 & 3 & \textbf{20} \\ \hline
\end{tabular}
\end{table}
\end{document}