3

EDIT: Added preamble, and it seems \input table worked! When I manually insert the table, rather than input it, I do not get any errors, and it looks nice. However, when I use \input{table.tex}, I get a host of errors and the PDF won't compile - Misplaced \noalign, Missing } inserted, Missing } inserted, Misplaced \cr, Misplaced \cr. I don't have the problem for \toprule, and I do use the packages siunitx and booktabs.

Here is the code to generate the table:

\documentclass[11pt]{article}

%% links \usepackage[colorlinks=true, allcolors=blue]{hyperref}

%% maths \usepackage{amssymb, amsfonts, amsmath} \usepackage{bm}

%% basic layout formatting
\usepackage[margin=1in]{geometry} % full-width \topskip = 20pt \parskip = 10pt \parindent = 0 pt \baselineskip = 15pt

\usepackage{setspace} % line spacing \onehalfspacing

\usepackage{graphicx}\usepackage{siunitx} \usepackage{adjustbox} \usepackage{caption} % to reset the headers of tables \usepackage{rotating} % for sidewaystable \usepackage{siunitx}

\numberwithin{table}{section} % reset the Table numbering for each section

%% these three are essential for estout \usepackage{booktabs} % neatly formatting lines \usepackage{threeparttable}
\usepackage{dcolumn} % aligning decimals \newcolumntype{d}[1]{D{.}{.}{#1}}

%% bibliography \usepackage{natbib} \bibliographystyle{plainnat}

\begin{document}

%%%% TABLE 1 %%%%

\begin{table}[!htbp] \caption{Summary statistics} \label{tab:table1} \begin{tabular}{lrrrr} \toprule \input{table.tex} \bottomrule \end{tabular}
\end{table}

\end{document}

Here is my table.tex code:

                   &           N&        Mean&          SD\\
 \midrule
 w         &    1&        5&        9\\
 x         &    2&        6&        10\\
 y         &    3&        7&      11\\
 z         &    4&        8&      12\\

1 Answers1

3

I can fully replicate the issue reported by the OP on a MacTeX2021 system, with all updates in place, using the code shown below.

Not sure why this works, but replacing \input{table.tex} with \input table takes care of the issue. (Note that .tex is the default filename extension for use with \input.)

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage[skip=0.333\baselineskip]{caption} % optional

\begin{filecontents}[overwrite]{table.tex} & N& Mean& SD\ \midrule w & 1& 5& 9\ x & 2& 6& 10\ y & 3& 7& 11\ z & 4& 8& 12\ \end{filecontents}

\begin{document}

\begin{table}[!htbp] \caption{Summary statistics} \label{tab:table1} \centering \begin{tabular}{lccc} \toprule \input table % not: '\input{table.tex}' \bottomrule \end{tabular}
\end{table} \end{document}

Mico
  • 506,678