缺失,数字视为零。多行多列

缺失,数字视为零。多行多列

这是我的代码。

 \begin{tabular}{*{5}{|c}|}
 \hline
 \multirow{3}{*}{c|}{Independent Variable} & \multicolumn{2}{c|}{Chi-Square Results} \\
 \cline{2-5}

& \multirow{3}{c}{Gender newline\ Female & newline\ Male} 
& \multicolumn{2}{c|}{Alcohol Use} & \multicolumn{2}{c|}{Chi-Square Value} & \multicolumn{2}{c|}{P-Value} & \multicolumn{2}{c|}{Sig
 } \\
 \cline{2-5}

这是我收到的代码错误。

Missing number, treated as zero.
<to be read again> 

l.204 ...}{Gender newline\ Female & newline\ Male}

我正在尝试制作这张表。

在此处输入图片描述

我应该做哪些改变来制作上面的表格?有没有更简单的方法来编码?

答案1

我建议对你的表格进行两种实现;无论哪种情况,都不\multirow需要,并且使用单个列代替前两个列。表格的水平尺寸较小,有助于提高可读性。

\documentclass{article}

% these are only for the second table
\usepackage{booktabs,siunitx}
%%%

\newcommand{\splitcell}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}

% for the second table
\newcommand{\Tsplitcell}[1]{%
  \smash{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}%
}

\begin{document}

\begin{table}[htp]
\centering

\caption{A caption for the table}\label{a-label}

\begin{tabular}{|l|r|r|r|r|}
\hline
\multicolumn{1}{|c|}{\bfseries\splitcell{Independent \\ Variables}} &
  \multicolumn{4}{c|}{\bfseries Chi-Square Results} \\
\hline
& \% Obese & $\chi^2$ Value & $P$-Value & Sig. \\
\hline
\textbf{Gender}           &        &   $0.002$ & $0.967$ &    \\
\quad Female              & $17.4$ &           &         &    \\
\quad Male                & $17.4$ &           &         &    \\
\hline
\textbf{Age}              &        & $522.308$ & $0.000$ & ** \\
\quad Ages 2--5           &  $0.9$ &           &         &    \\
\quad Ages 6--11          &  $9.5$ &           &         &    \\
\quad Ages12--19          & $34.8$ &           &         &    \\
\hline
\textbf{Race}             &        &  $30.329$ & $0.000$ & ** \\
\quad White, non-Hispanic & $12.9$ &           &         &    \\
\quad Black, non-Hispanic & $22.4$ &           &         &    \\
\quad Other               & $18.5$ &           &         &    \\
\hline
\end{tabular}

\end{table}

\begin{table}[htp]
\centering

\caption{A caption for the table}\label{a-label-bis}

\begin{tabular}{
  @{}
  l
  S[table-format=2.1]
  S[table-format=3.3]
  S[table-format=1.3]
  c
}
\toprule
\multicolumn{1}{c}{\bfseries\Tsplitcell{Independent \\ Variables}} &
  \multicolumn{4}{c}{\bfseries Chi-Square Results} \\
\cmidrule{2-5}
& {\% Obese} & {$\chi^2$ Value} & {$P$-Value} & Sig. \\
\midrule
\textbf{Gender}           &        &   0.002 & 0.967 &    \\
\quad Female              & 17.4 &           &         &    \\
\quad Male                & 17.4 &           &         &    \\
\midrule
\textbf{Age}              &        & 522.308 & 0.000 & ** \\
\quad Ages 2--5           &  0.9 &           &         &    \\
\quad Ages 6--11          &  9.5 &           &         &    \\
\quad Ages12--19          & 34.8 &           &         &    \\
\midrule
\textbf{Race}             &        &  30.329 & 0.000 & ** \\
\quad White, non-Hispanic & 12.9 &           &         &    \\
\quad Black, non-Hispanic & 22.4 &           &         &    \\
\quad Other               & 18.5 &           &         &    \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

答案2

我认为你不需要\multirow图片中显示的表格。仔细检查图片后,似乎表格的逻辑结构应该如下

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{l r r r r r}
\toprule
\multicolumn{2}{c}{\textbf{Independent Variables}} & \multicolumn{4}{c}{\textbf{Chi-Square Results}} \\
\cmidrule{3-6}
        &        & Percent Obese & Chi-Square Value & $P$-Value & Sig. \\
\midrule
\textbf{Gender} &                     &        &   $0.002$ & $0.967$ &    \\
                &              Female & $17.4$ &           &         &    \\
                &                Male & $17.4$ &           &         &    \\
\midrule
\textbf{Age}    &                     &        & $522.308$ & $0.000$ & ** \\
                &           Ages~2--5 &  $0.9$ &           &         &    \\
                &          Ages~6--11 &  $9.5$ &           &         &    \\
                &         Ages~12--19 & $34.8$ &           &         &    \\
\midrule
\textbf{Race}   &                     &        &  $30.329$ & $0.000$ & ** \\
                & White, non-Hispanic & $12.9$ &           &         &    \\
                & Black, non-Hispanic & $22.4$ &           &         &    \\
                &               Other & $18.5$ &           &         &    \\
\bottomrule
\end{tabular}

\end{document}

卡方结果

以下是一些有用的提示:

相关内容