Using \input inside a tabular environment does not seem to work in all cases, but I don't see why.
The MWE below gives the following error message:
! Misplaced \noalign.
\toprule ->\noalign
{\ifnum 0=`}\fi \@aboverulesep =\abovetopsep \global \@b...
l.1 \toprule
File main.tex:
\documentclass{standalone}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ll}
\input{inp}
\end{tabular}
\end{document}
File inp.tex:
\toprule
a & b \\
c & d \\
\bottomrule
The document compiles properly if the contents of inp.tex are pasted into the tabular environment. What is happening here?
\documentclass{standalone}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ll}
\toprule
a & b \\
c & d \\
\bottomrule
\end{tabular}
\end{document}

EDIT: The following question is related: Why is \input not expandable?
\makeatletter\let\primitiveinput\@@input\makeatotherin the preamble and using it with\primitiveinput imp\relax. Calling your macro\primitiveinputis confusing: it is not the TeX primitive, but a macro that calls the primitive. – yo' Apr 04 '12 at 10:58\relaxwould again disturb the tranquility oftabular, giving an error for\primitiveinput inp\relax\midrule. So the user would have to strictly adhere to leaving a space behind the file name, something which might not come naturally to LaTeX users... – Stephan Lehmke Apr 04 '12 at 11:03