[Tex/LaTex] Need help with multicolumn error

errorsmulticolumn

I am having difficulties with what I assume to be a simple issue. I'm in the process of learning LaTeX, and currently having STATA output most of my LaTeX code, which I then insert into TeXworks in order to generate PDFs.

Whenever I try to output this specific code, I receive the error:

"File ended while scanning use of \multicolumn."

Here is the code I am using:

\documentclass{article}
\begin{document}
\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Closing Date Effects}
\begin{tabular}{l*{1}{cc}}
\hline\hline
                    &\multicolumn{2}{c}{(1)}           \\    
                    &\multicolumn{2}{c}{Voter Turnout (%)}\\
\hline
Registration Closing Date&      -0.226\sym{**} &     (0.001)\\
Southern State      &      -8.900         &     (0.142)\\
Close x South (Interaction)&      0.0928         &     (0.674)\\
Constant            &       77.20\sym{***}&     (0.000)\\
\hline
Observations        &          51         &            \\
\hline\hline
\multicolumn{3}{l}{\footnotesize \textit{p}-values in parentheses}\\\
\multicolumn{3}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \                  (p<0.001\)}\\
\end{tabular}
\end{table}
\end{document}

My best guess has been that I'm missing some braces in the \multicolumn sections, but I can't find where. I thought perhaps on the last line:

\multicolumn{3}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \                      (p<0.001\)}\\

But no matter the number of braces I use, it still errors out.

Best Answer

There errors were:

  1. The missing backslash before the %,
  2. You had used three \\\ instead of \\ at the end of some lines, and a single \ one on the last line.
  3. As per egreg's suggestion, I made the numbers to be in math mode. This is especially important for negative numbers -- otherwise you have a dash instead of a negative sign.
  4. Instead of \textit{} you should be using $p$ as p is math variable.

Note:

enter image description here

Code:

\documentclass{article}
\begin{document}
\begin{table}[htbp]\centering
\def\sym#1{\ifmmode{}^{#1}\else\({}^{#1}\)\fi}
\caption{Closing Date Effects}
\begin{tabular}{l*{1}{cc}}
\hline\hline
                           &\multicolumn{2}{c}{(1)}           \\    
                           &\multicolumn{2}{c}{Voter Turnout (\%)}\\ % <--- Missing a backslash
\hline
Registration Closing Date  &      $-0.226\sym{**}$ &     $(0.001)$\\ % <--- Negative numbers should be in math mode
Southern State             &      $-8.900$         &     $(0.142)$\\
Close x South (Interaction)&      $0.0928$         &     $(0.674)$\\
Constant                   &      $77.20\sym{***}$ &     $(0.000)$\\
\hline
Observations               &          $51$         &            \\
\hline\hline
\multicolumn{3}{l}{\footnotesize $p$-values in parentheses}\\ % <-- had extra backslash
\multicolumn{3}{l}{\footnotesize \sym{*} $p<0.05$, \sym{**} $p<0.01$, \sym{***} $p<0.001$}\\ % <-- missing backslash
\end{tabular}
\end{table}
\end{document}
Related Question