如何正确为多列和多行着色

如何正确为多列和多行着色

我是 LaTeX 新手,我需要创建一个特定的表格。左列顶部的主题必须为灰色。因为这些单元格由多行组成,所以我很难正确地为整个表格着色。

\documentclass[sn-mathphys,Numbered]{sn-jnl}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor} % Für farbige Zellen
\usepackage{colortbl} % Für das Färben von Zellen in Tabellen
\usepackage{float} % Für die genaue Platzierung der Tabelle im Text
\usepackage{graphicx} % Falls du Grafiken einbinden möchtest
\usepackage{multirow}%
\usepackage{amsmath,amssymb,amsfonts}%
\usepackage{amsthm}%
\usepackage{tabularx}
\usepackage{mathrsfs}%
\usepackage[title]{appendix}%
\usepackage{hhline}
\usepackage{textcomp}%
\usepackage{manyfoot}%
\usepackage{algorithm}%
\usepackage{algorithmicx}%
\usepackage{algpseudocode}%
\usepackage{listings}%
\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage{colortbl}
\usepackage{booktabs}

\begin{document}


\begin{center}
\setlength{\fboxsep}{0pt}% setting local to this center environment
\begin{tabular}{|c|l|c|}
\hline
\multicolumn{1}{|c|}{\cellcolor[HTML]{BFBFBF}\multirow{2}{*}{\textbf{Generation}}} & Faithfulness & \cellcolor{white}0.9639 \\
& Answer Relevancy & \cellcolor{white}0.8648 \\ \hline
\multicolumn{1}{|c|}{\multirow{3}{*}{\textbf{Retrieval}}} & Context Recall & \cellcolor{white}0.9583 \\
& Context Precision & \cellcolor{white}1.0000 \\
& Context Relevancy & \cellcolor{white}0.8677 \\ \hline
\multicolumn{1}{|c|}{\multirow{2}{*}{\textbf{End-to-end}}} & Answer Correctness & \cellcolor{white}0.8351 \\
& Answer Semantic Similarity & \cellcolor{white}0.9250 \\ \hline
\end{tabular}
\end{center}

\end{document} 

答案1

像这样?

由于您的文档类不在 CTAN 上,因此我使用了article

\documentclass{article}
\usepackage{xcolor} 
\definecolor{mygray}{HTML}{BFBFBF}
\usepackage{tabularray}

\begin{document}
\begin{center}
\begin{tblr}{
  colspec={clc},
  vlines,stretch=0,
  hline{1,3,6,Z}={solid},
  column{1}={mygray, font=\bfseries},
  }
\SetCell[r=2]{c}Generation & Faithfulness & 0.9639 \\
& Answer Relevancy & 0.8648 \\ 
\SetCell[r=3]{c}Retrieval & Context Recall & 0.9583 \\
& Context Precision & 1.0000 \\
& Context Relevancy & 0.8677 \\ 
\SetCell[r=2]{c}End-to-end & Answer Correctness & 0.8351 \\
& Answer Semantic Similarity & 0.9250 \\ 
\end{tblr}
\end{center}
\end{document}

在此处输入图片描述

答案2

与。{NiceTabular}nicematrix

\documentclass[sn-mathphys,Numbered]{sn-jnl}
\usepackage{xcolor} 
\definecolor{mygray}{HTML}{BFBFBF}
\usepackage{nicematrix}

\begin{document}
\begin{center}
\begin{NiceTabular}{>{\columncolor{mygray}\bfseries}clc}[vlines]
\Hline
\Block{2-1}{Generation} & Faithfulness               & 0.9639 \\
                        & Answer Relevancy           & 0.8648 \\ 
\Hline
\Block{3-1}{Retrieval}  & Context Recall             & 0.9583 \\
                        & Context Precision          & 1.0000 \\
                        & Context Relevancy          & 0.8677 \\ 
\Hline
\Block{2-1}{End-to-end} & Answer Correctness         & 0.8351 \\
                        & Answer Semantic Similarity & 0.9250 \\ 
\Hline
\end{NiceTabular}
\end{center}
\end{document}

上述代码的输出

相关内容