I'm using a program to generate LaTeX code utilize the tabular package. It creates an error that reads
! Missing number, treated as zero.
<to be read again>
##
l.17 \begin{tabularx} {#}
{@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y@{}} \\
?
The code I'm using is as follows:
\documentclass[11pt, oneside]{article}
\usepackage{booktabs}
\usepackage{tabularx}
\title{Brief Article}
\author{The Author}
\begin{document}
\maketitle
%\section{}
%\subsection{}
\begin{center}
\footnotesize
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\begin{tabularx} {#} {@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y@{}} \\
\toprule
& \multicolumn{2}{c}{\textbf{surveyseason}} \\
\cmidrule(l{.75em}){2-3}
&\textbf{1}&\textbf{} \\
&Col \%&Col \% \\
\midrule
\textbf{sex}&& \\
female&45.3&47.2 \\
male&54.5&56.8 \\
\midrule
\textbf{grade}&& \\
9th&29&23 \\
10th&26&25 \\
11th&12.8&2.5 \\
12th&2.8&21.3 \\
\midrule
\textbf{ethbest}&& \\
american indian or alaska native&3.9&3.9 \\
native hawaiian or pacific islander&1.6&1.6 \\
asian american&9.8&9.8 \\
white or caucasian&60.4&60.4 \\
other&8.8&8.8 \\
\midrule
\textbf{highsch}&& \\
san dieguito&17.6&17.6 \\
torrey pines&33.5&33.5 \\
lacosta canyon&29.0&29.0 \\
canyon crest&19.8&19.8 \\
\bottomrule
\addlinespace[.75ex]
\end{tabularx}
\par
\scriptsize{\emph{Source: }test.dta}
\normalsize
\end{center}
\end{document}
Best Answer
The first argument of the
tabularx
environment should be the width that thetabularx
should span. In your case, you passed it a length#
, which is incorrect. Instead, pass it something like\linewidth
:The usage/notation is mentioned in the
tabularx
documentation:Since this is program-generated output, you'll either have to update the measurement manually (in the TeX output), or from the program of course.
Other manual improvements could include
using the
*{<num>}{<colspec>}
notation for repeating a column specification<col spec>
a total of<num>
times. Sowill change into
It is somewhat strange that you're listing a large number of columns in your
tabularx
column specification, yet you're only using three ever.Not using
\\
as the first line of yourtabularx
.Note the use of
\noindent
to avoid an overfull\hbox
warning.