
私は 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
私は常に、テーブルに過剰な色を付けないようにしています。 すっきりと整理された状態にしておくと、最終的に読みやすくなります。
とはいえ、ここに 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
\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}