6

I am building a table from several components that I automatically export from STATA. For this, I use \input{} to input the components inside a table and tabular environment. This usually works well, but I now want to input a line that contains a \multicolumn . This generates the LaTeX error !Misplaced \omit. \multispan ->\omit. In addition, the line that I input starts further to the right of the table and not all the way to the left as it should. Here is a minimal example of the code:

 \documentclass[11pt,oneside]{amsart}
 \usepackage{booktabs,multirow}
 \usepackage{tabularx}

 \begin{document}
  \begin{table}
  \caption{Table 1}
  \begin{tabular}{llcc}
  \toprule
  \input{no_degree}
  \midrule
 \multicolumn{4}{l}{Vocational training}\\
 & No training & 400 & 35 \\
 \midrule
 \end{tabular}
 \end{table}
 \end{document}

The table to input, no_degree has the following code:

 \multicolumn{2}{l}{\textbf{No info on secondary degree}} & 214 & 20 \\

Running this generates the error. However, when I just copy and paste exactly the content of the inputted file, the code runs smoothly. This code is the following:

 \documentclass[11pt,oneside]{amsart}
 \usepackage{booktabs,multirow}
 \usepackage{tabularx}

 \begin{document}
  \begin{table}
  \caption{Table 1}
  \begin{tabular}{llcc}
  \toprule
 \multicolumn{2}{l}{\textbf{No info on secondary degree}}&214& 20 \\
  \midrule
 \multicolumn{4}{l}{Vocational training}\\
 & No training & 400 & 35 \\
 \midrule
 \end{tabular}
  \end{table}
 \end{document}

Thanks a lot!

1 Answers1

5

You can not have any non-expandable commands before \multicolumnas once a non expandable token is seen the column cell is started and it is too late to make a spanning cell. unfortunately the LaTeX \input command is non-expandable, to add the brace syntax however you can use the primitive input as

\csname @@input\endcsname no_degree 

or

 \@@input no_degree 

if you are in a region where @ is a letter.

the primitive input is expandable and does not prevent a \multicolumn in the file from working.

David Carlisle
  • 757,742
  • So, I have exactly the same problem as above, but I don't understand the answer (which solved the problem, apparently). Where in my script should I put the lines you wrote, @David Carlisle? Could you please clarify? – Roland Apr 03 '19 at 18:11
  • 3
    @Roland if you have \input{whatever-your-file-is-called} in a tabular then replace it by \csname @@input\endcsname whatever-your-file-is-called – David Carlisle Apr 03 '19 at 19:42