构建 tabularx 简单表的失控参数

构建 tabularx 简单表的失控参数

我想重现这种表格: 桌子

我尝试写下这段代码:

\documentclass{article}
  \usepackage{tabularx,booktabs}
\begin{document}


    \newcolumntype{Y}{>{\centering\arraybackslash}X}
    \medskip\noindent
    \begin{tabularx}{0.75\textwidth}{c *{4}{Y}}
    \toprule
    & & \multicolumn{2}{c}{\textbf{Subject machine: S 
    ==Tomita15modified}\\
    \cmidrule(lr){3-4} 
    \multicolumn{2}{c}{\textbf{Reference machine: R == Tomita15} & in 
    $L(S)$ & in $L(S)^C$\\
    \midrule
    \multicolumn{2}{c|}{\textbf{in $L(R)$}} &  $|TP|=3$ & $|FN|=3$\\
    \hline
    \multicolumn{2}{c|}{\textbf{in $L(R)^C$}}  & $|FP|=0$ & 
    $|TN|=125$\\
    \bottomrule
    \end{tabularx}
\end{document}

我不明白为什么它会返回错误:

   Runaway argument?
   {c *{4}{Y}} \toprule & & \multicolumn {2}{c}{\textbf {Subject machine\ETC.
   ! File ended while scanning use of \TX@get@body. <inserted text>

我该如何解决这个问题?有没有更简单的方法来获取该表?感谢您的关注

答案1

下面是一个可以运行并且看起来更好的代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tabularx, booktabs, makecell, multirow, caption}
\renewcommand{\theadfont}{\normalsize\bfseries\boldmath}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}
\medskip\noindent
\begin{tabularx}{0.75\linewidth}{>{\hsize = 1.4\hsize }Y*{2}{>{\hsize = 0.8\hsize }Y}}
\toprule
\multirow{3.5}{*}{\thead{Reference machine:\\ R == Tomita15}} & \multicolumn{2}{c}{\thead{Subject machine:\\
S ==Tomita15 modified}}\\
 \cmidrule(lr){2-3}
& in
 $L(S)$ & in $L(S)^C$\\
 \midrule
 \thead{in $L(R)$} & $|TP|=3$ & $|FN|=3$\\
 \hline
\thead{in $L(R)^C$} & $|FP|=0$ &
$|TN|=125$\\
\bottomrule
\end{tabularx}

\end{document} 

在此处输入图片描述

答案2

在此处输入图片描述

多列中缺少两个},但我还修复了其他几个问题,您不需要/不想要tabularx这样的表格,因为单元格内没有换行符,所以简单一点tabular更好。最好不要在 booktabs 中使用垂直线(请参阅 booktabs 包文档)

\documentclass{article}
  \usepackage{tabularx,booktabs}
\newcommand\hd[1]{\bfseries\begin{tabular}{@{}c@{}}#1\end{tabular}}
\begin{document}


    \newcolumntype{Y}{>{\centering\arraybackslash}X}
    \medskip\noindent
    \begin{tabular}{cccc}
    \toprule
    \multicolumn{2}{c}{\hd{Reference machine:\\ R == Tomita15}}&
     \multicolumn{2}{c}{\hd{Subject machine:\\
     S  ==Tomita15modified}}\\
    \cmidrule(lr){3-4} 
     && in  $L(S)$ & in $L(S)^C$\\
    \midrule
    \multicolumn{2}{c}{\textbf{in $L(R)$}} &  $|TP|=3$ & $|FN|=3$\\
    \midrule
    \multicolumn{2}{c}{\textbf{in $L(R)^C$}}  & $|FP|=0$ & 
    $|TN|=125$\\
    \bottomrule
    \end{tabular}
\end{document}

相关内容