# Missing \begin {document} error

I'm really new to LaTeX so I apologize if this is a really basic question. I am trying to create tables from STATA (a statistical suite) using laTeX and have generated the following table code. However, I keep getting the Missing \begin{document} error whenever I try to render the table.

\begin{center}
\footnotesize
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\begin{tabularx} {14cm} {@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y@{}} \\
\toprule
& \multicolumn{9}{c}{\textbf{Patient died}} \\
\cmidrule(l{.75em}){2-10}
\textbf{To died or exp. end} & \multicolumn{3}{c}{\textbf{No}} &
\multicolumn{3}{c}{\textbf{Yes}} & \multicolumn{3}{c}{\textbf{Total}} \\
\cmidrule(l{.75em}){2-4} \cmidrule(l{.75em}){5-7}\cmidrule(l{.75em})
{8-10}
&No.&Col \%&Cum \%&No.&Col \%&Cum \%&No.&Col \%&Cum \% \\
\midrule
10 or less months&4&23.5&23.5&15&48.4&48.4&19&39.6&39.6 \\
11 to 20 months&6&35.3&58.8&8&25.8&74.2&14&29.2&68.8 \\
21 to 30 months&2&11.8&70.6&7&22.6&96.8&9&18.8&87.5 \\
31 or more months&5&29.4&100.0&1&3.2&100.0&6&12.5&100.0 \\
\textbf{Total}&17&100.0&&31&100.0&&48&100.0& \\
\bottomrule
\addlinespace[.75ex]
\end{tabularx}
\par
\scriptsize{\emph{Source: }cancer.dta}
\normalsize
\end{center}

• The code you have is no real document, it is just the code to create the table. You have to wrap this into a document class of your choice and a document environment and you have to provide the needed package imports. – epR8GaYuh May 28 '18 at 19:00
• welcome to tex.se! for compiling of this code you need complete latex document, beginning with \documentclass{...} and ending with \end{document} – Zarko May 28 '18 at 19:00
• Maybe you are interested in this link: tex.stackexchange.com/questions/11/… – samcarter_is_at_topanswers.xyz May 28 '18 at 19:07

## 1 Answer

this isn't a complete answer, but it might help.

your error message was Missing \begin{document}. that means the error was caused by a package; latex never reached the body of the document.

at the 2017 tug meeting, i presented a talk on debugging. this error was touched on briefly. the slides for the talk are online; the relevant slides are 13 and 22, but the rest of the material might be useful as well, as it describes how to dissect a log file.

briefly, what you need to do is find what \usepackage was involved to trigger the error. once you know that, you can construct a small test to make certain that this is the culprit. and then, if you're not experienced with latex, come back here to ask for help. (you can use the command \listfiles to show the versions of packages involved; often such a problem is the result of a newer version being required, but a helper will need to know what packages and what versions were being used that triggered the error.)