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?
xras suggested here: Cross-referencing between different files – Werner Nov 05 '15 at 05:04tableenvironmentfromtable.texand use\includestandalone` then things will work. – Nov 05 '15 at 05:12xrseems to work as intended, thanks! – carsten Nov 05 '15 at 05:28main.tex, LaTeX assigns them the numbers 1 and 2. Now, compiling the standalone versions, they both get called "Table 1", since they are each the first table in the standalone document. I would like the captions in the standalone to state the table numbers as given in the main document. – carsten Nov 05 '15 at 20:23standalonedocuments for content. You may consider using only whatever you have within thedocumentenvironment instead. If there's no reason for using file in thestandaloneformat, then I'd suggest doing that. – Werner Nov 05 '15 at 20:33