xltabular 与多列和 \kill 结合使用时会产生错误

xltabular 与多列和 \kill 结合使用时会产生错误

我需要做的是设置 20 列等宽,并使用多列。为了将表格扩展到 \textwidth,我需要使用 \kill。解释可以在这里找到Tabularx(xltabular)仅包含多列,无法正确展开

现在我收到此错误,! Missing } inserted. 这仅当 xltabular 与多列、X 类型的列和命令结合使用时才会发生\kill。这发生在环境中pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017),在pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 20.12)

有人知道如何解决这个问题吗?或者更好。如何定义具有相等列的表格并使用多列的部分内容?问题是我不知道单元格的长度。

  %--LATEX-COMPILER:lualatex:LATEX-COMPILER       % Specify which compiler to be used
    %LATEX-COMPILE-COUNT:1:LATEX-COMPILE-COUNT      % How many iterations to make the compiler
    \documentclass[paper=a4,fontsize=18pt]{article}
    \usepackage{geometry}
    \geometry{
    % verbose,
    portrait,       % page orientation (landscape or portrait)
    a4paper,        % paper size
    tmargin=5mm,    % page top margin
    bmargin=5mm,    % page bottom margin
    lmargin=5mm,   % page left margin
    rmargin=5mm % page right maring
    }
    
    \usepackage[utf8]{inputenc}
    \usepackage[defaultsans]{opensans} %font
    \usepackage[T1, T2A]{fontenc}
    \usepackage{fancyhdr}
    \usepackage{multicol}
    \usepackage{booktabs}
    \usepackage{tabularx}
    \usepackage{longtable}
    \usepackage{layouts}
    \usepackage{xltabular}

    
    \newcommand{\smf}{ % small font
        \fontsize{9}{11}\selectfont
    }
    
    
     
    \begin{document}
    
   

    % the table does not spread to \textwidth
\begin{xltabular}{\textwidth}{|X|X|X|} 
   % \multicolumn{1}{|c|}{very long content } & setting the widths & of each column \\ \kill
  \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} \\
  \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} 
\end{xltabular}

% table spread to \textwidth but without multicolumn
\begin{xltabular}{\textwidth}{|X|X|X|} 
  test & test & is test \\
  test & test & test 
\end{xltabular}

% table spread to \textwidth, works with multicolumn BUT gives error under TeX Live 2017
\begin{xltabular}{\textwidth}{|X|X|X|} 
  \multicolumn{1}{|c|}{test } & \multicolumn{1}{|c|}{test } & \multicolumn{1}{|c|}{test } \\ \kill
  \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} \\
  \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} 
\end{xltabular}

\end{document}

答案1

从中删除所有 X 列意味着tabularx它永远无法做任何有用的事情,即使您避免了错误。要将文本置于 X 列的中心,请使用而\centering不是 替换。Xc

在此处输入图片描述

 \documentclass[paper=a4,fontsize=18pt]{article}
    \usepackage{geometry}
    \geometry{
    % verbose,
    portrait,       % page orientation (landscape or portrait)
    a4paper,        % paper size
    tmargin=5mm,    % page top margin
    bmargin=5mm,    % page bottom margin
    lmargin=5mm,   % page left margin
    rmargin=5mm % page right maring
    }
    
    \usepackage[utf8]{inputenc}
    \usepackage[defaultsans]{opensans} %font
    \usepackage[T1, T2A]{fontenc}
    \usepackage{fancyhdr}
    \usepackage{multicol}
    \usepackage{booktabs}
    \usepackage{tabularx}
    \usepackage{longtable}
    \usepackage{layouts}
    \usepackage{xltabular}

    
    \newcommand{\smf}{ % small font
        \fontsize{9}{11}\selectfont
    }
    
    
     
    \begin{document}
    
   

    % the table does not spread to \textwidth
\begin{xltabular}{\textwidth}{|X|X|X|} 
   % \multicolumn{1}{|c|}{very long content } & setting the widths & of each column \\ \kill
  \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} \\
  \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} 
\end{xltabular}

% table spread to \textwidth but without multicolumn
\begin{xltabular}{\textwidth}{|X|X|X|} 
  test & test & is test \\
  test & test & test 
\end{xltabular}

% table spread to \textwidth, works with multicolumn BUT gives error under TeX Live 2017
\begin{xltabular}{\textwidth}{|*{3}{>{\centering\arraybackslash}X|}}
   test & test & test \\
   test & test & test \\
\end{xltabular}

\end{document}

由于您指定了 T1 和 T2A 编码,因此这是使用 pdftex 而不是 luatex 处理的。

相关内容