1

Here is my code.

 \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}

This the code error that I am receiving.

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

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

I am trying to make this table.

enter image description here

What should I change to make the table above.Is there an easier way to code this?

  • \newline is the command. – Sigur Jul 10 '18 at 0:26
  • You need \& for the literal ampersand. \multirow{3}{c}{Gender newline\ Female \& newline\ Male} (But, of course, you may not want 'newline' literally, as @Sigur says.) – cfr Jul 10 '18 at 0:26
2

I propose two realizations of your table; in either case no \multirow is necessary and a single column is used in place of your first two. The horizontal size of the table is smaller, helping for readability.

\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}

enter image description here

2

I don’t think you need \multirow for the table shown in your picture. After carefully examining the picture, it seems that the logical structure of the table should be as follows

\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}

chi-square results

Some useful tips for you:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.