4

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.

Ruben
  • 13,448
Jacob
  • 41
  • 1
    % is a comment (to end of line) so TeX never saw the closing } here %)}\\ you need \% to typeset a % – David Carlisle Apr 03 '14 at 22:03
  • While this may not be an exact duplicate (soooo, duplicate-ish), it still provides details regarding the use of % as output in your document. You need to escape it via \%. See Escape character in LaTeX. – Werner Apr 03 '14 at 22:07
  • 1
    need to escape the % in the second line (which is the immediate cause of your error). That, once corrected, throws up another couple of errors: a stray backslash at the end of the penultimate line (the p values line), and a bad delimiter in the following line because you have space between \(. – Paul Stanley Apr 03 '14 at 22:10

2 Answers2

5

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}
Peter Grill
  • 223,288
0

With the threepartable, siunitx and booktabs packages, it requires less code (defining sim is no more useful) for a better aspect (the decimal dots in the middle column are vertically aligned):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[para]{threeparttable}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{siunitx}
\newcolumntype{T}{S[table-figures-decimal = 4,table-figures-integer = 2]}

\begin{document}
\begin{table}[htbp]
\centering
\begin{threeparttable}
\caption{Closing Date Effects}
\begin{tabular}{@{}lT@{\qquad}c@{}}
\toprule
\midrule
                    &\multicolumn{2}{c}{Voter Turnout\hfill (\%)\tnote{1}}\\
\midrule
Registration Closing Date&      -0.226{\tnote{**}} &     (0.001)\\%
Southern State      &      -8.900         &     (0.142)\\
Close x South (Interaction)&      0.0928         &     (0.674)\\
Constant            &       77.20{\tnote{***}}&     (0.000)\\
\midrule
Observations        &          {51}         &            \\
\midrule
\bottomrule
\end{tabular}
\footnotesize
\begin{tablenotes}
 \item[1]  $ p $-values in parentheses\\
  \item[*]  $ p < 0.05 $
  \item[**]  $ p <  0.01 $
  \item [***] $ p<0.001 $
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document} 

enter image description here

Bernard
  • 271,350