使用 \cline 时出错

使用 \cline 时出错

对于某个表格布局,我被迫使用\cline,但我一直遇到错误,我找不到原因。
现有的论坛帖子有类似的问题,无法帮助我解决问题。
我在命令上收到以下错误\cline:未定义的控制序列抱歉,我只使用 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{mathrsfs}%
\usepackage[title]{appendix}%
\usepackage{xcolor}%
\usepackage{textcomp}%
\usepackage{manyfoot}%
\usepackage{booktabs}%
\usepackage{algorithm}%
\usepackage{algorithmicx}%
\usepackage{algpseudocode}%
\usepackage{listings}%
\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}
\usepackage{blindtext}
\usepackage[T1]{fontenc}


\begin{document}


\begin{center}
\begin{tabular}{|c|l|}
\hline
\rowcolor[HTML]{EFEFEF} 
\multicolumn{1}{|c|}{\multirow{2}{*}{\cellcolor[HTML]{EFEFEF}\textbf{Generation}}} & \multicolumn{1}{l|}{Faithfulness} \\ \cline{2-2}
\rowcolor[HTML]{EFEFEF} 
& \multicolumn{1}{l|}{Answer Relevancy} \\ \hline
\rowcolor[HTML]{EFEFEF} 
\multicolumn{1}{|c|}{\multirow{3}{*}{\cellcolor[HTML]{EFEFEF}\textbf{Retrieval}}} & \multicolumn{1}{l|}{Context Recall} \\ \cline{2-2}
\rowcolor[HTML]{EFEFEF} 
& \multicolumn{1}{l|}{Context Precision} \\ \cline{2-2}
\rowcolor[HTML]{EFEFEF} 
& \multicolumn{1}{l|}{Context Relevancy} \\ \hline
\rowcolor[HTML]{EFEFEF} 
\multicolumn{1}{|c|}{\multirow{2}{*}{\cellcolor[HTML]{EFEFEF}\textbf{End-to-end}}} & \multicolumn{1}{l|}{Answer Correctness} \\ \cline{2-2}
\rowcolor[HTML]{EFEFEF} 
& \multicolumn{1}{l|}{Answer Semantic Similarity} \\ \hline
\end{tabular}
\end{center}

\end{document}

我的目标是根据以下模板生成一个表格: 在此处输入图片描述

答案1

据我所知,没有Numbered选项。sn-jnl

而且,biblatex不能使用,因为该类使用natbib

您的问题可以通过以下方式解决

  1. 大大简化输入,并且
  2. 使用\hhline而不是\cline

一定没有必要为每个单元格重新声明对齐类型。而且,\rowcolor您无需对每一行都重复声明,只需声明即可\columncolor

\multirow通过在底部添加条目并使用负数行数来扩展,可以解决该问题。

\documentclass[sn-mathphys]{sn-jnl}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor} % Für farbige Zellen
\usepackage{hhline}
\usepackage{multirow}

\begin{document}


\begin{center}
\begin{tabular}{|>{\columncolor[HTML]{EFEFEF}}c|>{\columncolor[HTML]{EFEFEF}}l|}
\hline
& Faithfulness \\ \hhline{~|-}
\multirow{-2}{*}{\textbf{Generation}} 
& Answer Relevancy \\ \hline
& Context Recall \\ \hhline{~|-}
& Context Precision \\ \hhline{~|-}
\multirow{-3}{*}{\textbf{Retrieval}}
& Context Relevancy \\ \hline
& Answer Correctness \\ \hhline{~|-}
\multirow{-2}{*}{\textbf{End-to-end}} 
& Answer Semantic Similarity \\ \hline
\end{tabular}
\end{center}

\end{document}

在此处输入图片描述

你也可以避免\columncolor

\documentclass[sn-mathphys]{sn-jnl}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor} % Für farbige Zellen
\usepackage{hhline}
\usepackage{multirow}

\begin{document}

\begin{center}
\setlength{\fboxsep}{0pt}% setting local to this center environment
\colorbox[HTML]{EFEFEF}{\begin{tabular}{|c|l|}
\hline
& Faithfulness \\ \hhline{~|-}
\multirow{-2}{*}{\textbf{Generation}}
& Answer Relevancy \\ \hline
& Context Recall \\ \hhline{~|-}
& Context Precision \\ \hhline{~|-}
\multirow{-3}{*}{\textbf{Retrieval}}
& Context Relevancy \\ \hline
& Answer Correctness \\ \hhline{~|-}
\multirow{-2}{*}{\textbf{End-to-end}}
& Answer Semantic Similarity \\ \hline
\end{tabular}}
\end{center}

\end{document}

当然,\multirow在印刷方面建议避免使用垂直规则。

\documentclass[sn-mathphys]{sn-jnl}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor} % Für farbige Zellen
\usepackage{booktabs}

\begin{document}

\begin{center}
\setlength{\fboxsep}{0pt}% setting local to this center environment
\colorbox[HTML]{EFEFEF}{%
  \begin{tabular}{ll}
  \toprule
  \textbf{Generation}
    & Faithfulness \\
    & Answer Relevancy \\
  \midrule
  \textbf{Retrieval}
    & Context Recall \\
    & Context Precision \\
    & Context Relevancy \\
  \midrule
  \textbf{End-to-end}
    & Answer Correctness \\
    & Answer Semantic Similarity \\
  \bottomrule
  \end{tabular}%
}
\end{center}

\end{document}

在此处输入图片描述

答案2

与。{NiceTabular}nicematrix

\documentclass[sn-mathphys]{sn-jnl}
\usepackage[T1]{fontenc}
\usepackage{xcolor} 
\usepackage{booktabs}
\usepackage{nicematrix}

\begin{document}

\begin{center}
  \begin{NiceTabular}{ll}[hvlines,cell-space-limits=3pt]
  \CodeBefore
    \arraycolor[HTML]{EFEFEF}
  \Body
  \Block{2-1}{Generation}
    & Faithfulness \\
    & Answer Relevancy \\
  \Block{3-1}{Retrieval}
    & Context Recall \\
    & Context Precision \\
    & Context Relevancy \\
  \Block{2-1}{End-to-end}
    & Answer Correctness \\
    & Answer Semantic Similarity \\
  \end{NiceTabular}
\end{center}

\end{document}

上述代码的输出

相关内容