LaTeX forum ⇒ Graphics, Figures & Tables\input error in tables Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
Posts: 2
Joined: Tue Feb 10, 2009 12:37 pm

\input error in tables

Postby econometrician » Tue Feb 10, 2009 12:46 pm

Hi, this is my first post here, so please be gentle.

I'm using the \input command to insert table contents into my LaTeX document, but if I begin the inputted file with \hline or \midrule (when using booktabs), I get the following error message:

  1. ! Misplaced \noalign.
  2. \hline ->\noalign
  3. {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
  4. l.1 \hline

The following minimal example illustrates the problem.

Main file:

  1. \documentclass{article}
  2. \begin{document}
  3. \begin{table}
  4. \begin{tabular}{lcc}
  5. \input{./table}
  6. \end{tabular}
  7. \end{table}
  8. \end{document}

table.tex file:

  1. \hline
  2. Variable & 5.73 & 3.4 \\

If i copy the exact contents from table.tex into the main file instead of using \input, it works. Also, if i remove \hline from table.tex, it works.

This is a problem for me as i'm using \input to retrieve table contents exported from Stata.

I'm using MikTex 2.7 and LEd 0.52.

Any help would be greatly appreciated!
Last edited by cgnieder on Fri Dec 28, 2012 12:33 pm, edited 1 time in total.
Reason: added code markup


Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Postby phi » Tue Feb 10, 2009 5:28 pm

\input is not expandable in LaTeX, you have to use the TeX \input primitive, which is called \@@input in LaTeX:
  1. \documentclass{article}
  2. \makeatletter
  3. \newcommand*\ExpandableInput[1]{\@@input#1 }
  4. \makeatother
  5. \begin{document}
  6. \begin{table}
  7. \begin{tabular}{lcc}
  8. \ExpandableInput{./table}
  9. \end{tabular}
  10. \end{table}
  11. \end{document}

User avatar
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Wed Feb 11, 2009 10:31 am

I guess it should work if you put the tabular environment into the file.
  1. \begin{table}[!ht]
  2. \centering
  3. \input{./inputtable}
  4. \caption{Input table}\label{tab:inputtable}
  5. \end{table}

Just try it.

Best regards and welcome to the board
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

Posts: 2
Joined: Tue Feb 10, 2009 12:37 pm

Postby econometrician » Thu Feb 19, 2009 10:57 am

The ExpandableInput trick works, thank you!

The second suggestion would probably work too, but I don't have that level of control over the Stata output (unless I want to do a lot of dirty coding).

Anyway, thanks for the help!

Posts: 1
Joined: Wed Dec 26, 2012 10:15 pm

Postby maranna00 » Wed Dec 26, 2012 10:21 pm

basically, what is needed is that you must specify float type (Figure, graphic, table, etc) in the main document, including any captions or labels you want to include or reference later.

So the main document should have the
  1. \begin{table}{!h]
  2. \caption{}
  3. \label{}
  4. \input{<filename.tex>}
  5. \end{table}

and your table input file document should begin with

  1. \begin{tabular}
  2. ...
  3. \end{tabular}

Hope that's helpful.

Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 8 guests