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

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

### \input error in tables

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:

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

The following minimal example illustrates the problem.

Main file:

\documentclass{article}\begin{document}\begin{table}\begin{tabular}{lcc}\input{./table}\end{tabular}\end{table}\end{document}

table.tex file:

\hlineVariable & 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.

Tags:

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm
\input is not expandable in LaTeX, you have to use the TeX \input primitive, which is called \@@input in LaTeX:
\documentclass{article}\makeatletter\newcommand*\ExpandableInput[1]{\@@input#1 }\makeatother\begin{document}\begin{table}\begin{tabular}{lcc}\ExpandableInput{./table}\end{tabular}\end{table}\end{document}

localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany
I guess it should work if you put the tabular environment into the file.
\begin{table}[!ht]   \centering   \input{./inputtable}   \caption{Input table}\label{tab:inputtable}\end{table}

Just try it.

Best regards and welcome to the board
Thorsten¹
LaTeX Community Moderator

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

econometrician
Posts: 2
Joined: Tue Feb 10, 2009 12:37 pm
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!

maranna00
Posts: 1
Joined: Wed Dec 26, 2012 10:15 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
\begin{table}{!h]     \caption{}     \label{}     \input{<filename.tex>}\end{table}

and your table input file document should begin with

\begin{tabular} ...\end{tabular}`