0

I'm writing on a large document with many tables. Rules require me to provide every table as a standalone PDF file as well, so I do this:

In main.tex:

\documentclass{article}
\usepackage{standalone}
\begin{document}
\section{Hello}\label{sec:hello}
\input{table}
\end{document}

In table.tex

\documentclass[float=true,preview=true]{standalone}
\begin{document}
\begin{table}
\begin{tabular}{c}
   A table in section \ref{sec:hello}
\end{tabular}
\caption{A Table}
\end{table}
\end{document}

Now, at first glance, this works nicely. However, in the standalone version of the table, the section reference is broken for obvious reasons, since LaTeX doesn't know about the section in the standalone file.

I suppose there is some hack to make this work by making LaTeX use the main.aux when compiling table.tex, but I can't really think of a nice way to handle this. Any suggestions?

7
  • 4
    Try with xr as suggested here: Cross-referencing between different files
    – Werner
    Nov 5 '15 at 5:04
  • Do you need captions in those standalone table files? If you remove the table environment` from table.tex and use \includestandalone then things will work.
    – user11232
    Nov 5 '15 at 5:12
  • 1
    I'm not sure whether I need the captions, I need to check, but xr seems to work as intended, thanks!
    – carsten
    Nov 5 '15 at 5:28
  • Oh, I just discovered one more thing: It would be nice if the tables also had the correct numbers in the standalone. Would this be possible?
    – carsten
    Nov 5 '15 at 5:41
  • @carsten: What does "correct numbers" mean?
    – Werner
    Nov 5 '15 at 6:15