5

I want to split my table into multiple files:

\input{table_head.tex} with following content

\begin{table}[htpb]
\centering
\caption{Caption}
\begin{tabular}[r]{ccc}
\addlinespace
\toprule
A & 
B & 
C \\
\midrule

\input{content1.tex} with following content

A1 & B1 & C1 \

\input{content2.tex} with following content

A2 & B2 & C2 \

and so on until

\input{contentX.tex} with following content

AX & BX & CX \

and finally the table footer

\input{table_footer.tex} with the following content

\bottomrule
\end{tabular}
\label{tab:tab_label}
\end{table}

Which command should I use? I get errors with input.

1 Answer 1

5

This question is similar to Supertabular problem with \input: The \bottomrule command has to be immediately preceded by a \\ (or \tabularnewline). Even though \input works as if you had typed the content directly in most cases, this is one of the occasions where it fails: \bottomrule can't find the \\ from the preceding file. In the answer I linked to, Bruno suggests putting the last \\ into the footer file, but I assume you want to keep the structure of all the input files the same. I would suggest adding \\[-\normalbaselineskip] at the start of the table_footer.tex file, which will act as a newline that doesn't actually change the vertical position:

\documentclass{article}
\usepackage{filecontents}
\usepackage{booktabs}

\begin{filecontents}{table_head.tex}
\begin{table}[htpb]
\centering
\caption{Caption}
\begin{tabular}[r]{ccc}
\addlinespace
\toprule
A & 
B & 
C \\
\midrule
\end{filecontents}

\begin{filecontents}{input1.tex}
A1 & B1 & C1\\
\end{filecontents}

\begin{filecontents}{input2.tex}
A2 & B2 & C2\\
\end{filecontents}

\begin{filecontents}{table_foot.tex}
\\[-\normalbaselineskip]\bottomrule
\end{tabular}
\label{tab:tab_label}
\end{table}
\end{filecontents}


\begin{document}
\input{table_head.tex}
\input{input1.tex}
\input{input2.tex}
\input{table_foot.tex}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .