You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LaTeX多行列着色表格报错:Package array Error: Empty preamble: `l' used

问题分析与解决

错误Package array Error: Empty preamble: l' used.`的根源有两个:

  • 自定义列类型时误用了HTML转义字符>,而非LaTeX语法要求的>,导致列类型定义失效。
  • tabular列格式中错误地将普通列格式c与自定义列类型clf连写,LaTeX会将其拆解为c、l、f三个无效组合,触发空前置命令的错误。

修正后的代码

\usepackage{multirow,tabularx} 
\usepackage{xcolor}
\usepackage{colortbl}

\definecolor{lf}{RGB}{204,153,255} % lila fuerte
\definecolor{ns}{RGB}{255,225,193} % naranja suave

% 将列类型定义移至导言区,使用正确的LaTeX语法>
\newcolumntype{clf}{>{\columncolor{lf}}c}
\newcolumntype{cns}{>{\columncolor{ns}}c}

\begin{document}

\begin{table}[!ht]
    \centering
    % 修正列格式,每一列单独指定格式,避免连写混淆
    \begin{tabular}{|c|clf|cns|clf|}
    \hline
    Verbo & CD & Suma binaria & Core \\
    \hline
    \hline
    \multirow{2}{*}{Buy} & 0 & 1 & \multirow{2}{*}{1}\\
    \cline{2-3} & 1 & 0 & \\
    \hline
    \multirow{2}{*}{Sell} & 0 & 0 & \multirow{2}{*}{0}\\
    \cline{2-3} & 1 & 1 & \\
    \hline
    \multirow{2}{*}{Exchange} & 0 & 0 & \multirow{2}{*}{0}\\
    \cline{2-3} & 1 & 1 & \\
    \hline
    \multirow{2}{*}{Use} & 0 & 0 & \multirow{2}{*}{0}\\
    \cline{2-3} & 1 & 1 & \\
    \hline
    \end{tabular}
    \caption{Tabla_1}
    \label{tab:core_contextual}
\end{table}

\end{document}

额外说明

  • 自定义列类型必须使用LaTeX原生的>符号来指定列前命令,不能用HTML转义的>。
  • tabular的列格式中,每个列的格式需单独明确,比如普通列用c,自定义列类型直接写clf,不要将两者连写造成解析混淆。

内容的提问来源于stack exchange,提问作者Bufal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 12:10:27