Graphics, Figures & Tables\input error in tables

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

\input error in tables

Post by econometrician »

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:

Code: Select all

! Misplaced \noalign.
\hline ->\noalign 
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.1 \hline
The following minimal example illustrates the problem.

Main file:

Code: Select all

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

Code: Select all

\hline
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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

\input error in tables

Post by phi »

\input is not expandable in LaTeX, you have to use the TeX \input primitive, which is called \@@input in LaTeX:

Code: Select all

\documentclass{article}
\makeatletter
\newcommand*\ExpandableInput[1]{\@@input#1 }
\makeatother
\begin{document}
\begin{table}
\begin{tabular}{lcc}
\ExpandableInput{./table}
\end{tabular}
\end{table}
\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

\input error in tables

Post by localghost »

I guess it should work if you put the tabular environment into the file.

Code: Select all

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

Re: \input error in tables

Post by econometrician »

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

\input error in tables

Post by maranna00 »

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

Code: Select all

\begin{table}{!h]
    \caption{}
    \label{}
    \input{<filename.tex>}
\end{table}
and your table input file document should begin with

Code: Select all

\begin{tabular} 
...
\end{tabular}
Hope that's helpful.
Post Reply