# [Tex/LaTex] How to include a multipage table from an external file

longtablestandalonetables

I usually save my tables as standalone PDFs, generated by compiling a standalone document and then include them in the main file via \includegraphics{pdf.name}

However, I now have a two-pages table made with longtable and I would like to include it with the same method, saving it as a separate PDF and then including it with includegraphics.

This does not seem to work and has many issues:

1. standalone class do not work with longtables
2. If I save the table as a normal article then it can't be included with includegraphics

So my question is: How should I proceed to include a multi-page table from an external file? Is it even possible?

This would be a perfect application of the standalone bundle.

You can store your longtable table in (say), mytablefile.tex, and then input it into your main file using input.

Here are two files that demonstrate the idea- note that mytablefile.tex uses the standalone documentclass while mainfile.tex uses standalone package. This is a very simple demonstration, but you can do some more sophisticated things- explore the manual and this site for more details.

Note that with your current approach your table will not inherit the font style of your main document- furthermore, it will likely be scaled and may look out of place- the technique I have demonstrated does not have this problem.

# mainfile.tex

% arara: pdflatex
\documentclass{article}

\usepackage{standalone}
\usepackage{longtable}

\begin{document}
\input{mytablefile}
\end{document}


# mytablefile.tex

% arara: pdflatex
\documentclass[varwidth]{standalone}

\usepackage{longtable}

\begin{document}

\begin{longtable}{cc}
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
\end{longtable}
\end{document}