3

for a few days I've been stacked with a problem which no manual or documentation resolved, please help:

I have my 'main.tex' report document file, where I use the 'standalone' package to load the chapter contents, something like this:

\documentclass[12pt,a4paper,oneside]{report}
\usepackage{standalone}
\begin{document}
  \input{chapter-about-this}
  \input{chapter-about-that}
\end{document}

Inside the 'chapter-about-this.tex' sub-file, I use the 'standalone' package too, this one is to load the charts with plots or another pictures taking hundreds of source code rows:

\documentclass{standalone}
\usepackage{standalone}
\usepackage{pgfplots}
\begin{document}
  \chapter{Very important chapter}
  Blah blah, look at \ref{fig:super-plot}.
  \input{superplot-source-code}
\end{document}

And this nested 'superplot-source-code.tex' sub-file brings the plot:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
  \begin{figure}
    \label{fig:super-plot}
    \caption{Very strange plot}
    ...plot...
  \end{figure}
\end{document}

When I compile the chapter itself, figure reference is built with no problem. The problem comes, when I try to compile the main report file. Figure's caption has its ordered number, but the referencing text inside the chapter looks like 'Blah blah, look at ??.' - with two question mark instead of 1.2 or something like that.

For example, with the bibliography reference input with \cite command, there is no problem, it gives the number, although the source code with bibliography is also sub-filed with this package (but in 1st level include).

I found out, that compilation with 'latex' has to be done for two or three times to reach all the references. But I'm developing with TeXworks editor and compiling with pdfLaTeX+MakeIndex+BibTex with synctex enabled, which - I hope - should run latex for as many times as needed. So where is the point?

6
  • If I understand correctly, you have a \documentclass command in each of the files you input into main.tex. You cannot do that. There can be only one \documentclass in the whole document. Also, packages can only be loaded in the preamble of the document (i.e. before \begin{document}).
    – jub0bs
    Commented Mar 14, 2013 at 0:06
  • 1
    @Jubobs that is true unless you use standalone class and package
    – JLDiaz
    Commented Mar 14, 2013 at 0:12
  • @Dix Labels should appear after captions, not before. I don't know if this could be related with your problem though.
    – JLDiaz
    Commented Mar 14, 2013 at 0:15
  • @JLDiaz I didn't know that. Thanks.
    – jub0bs
    Commented Mar 14, 2013 at 0:17
  • You don't have to sign with your name since it automatically appears in the lower right corner of your post. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you.
    – mafp
    Commented Mar 14, 2013 at 0:25

1 Answer 1

3

Just compile more than once, I got the expected result.

enter image description here

\documentclass[12pt,a4paper,oneside]{report}
\usepackage{filecontents}

\begin{filecontents*}{chapter-about-this.tex}
\documentclass{standalone}
\usepackage{standalone}
\usepackage{pgfplots}
\begin{document}
  \chapter{Very important chapter}
  Blah blah, look at \ref{fig:super-plot} 
    \input{superplot-source-code}
\end{document}
\end{filecontents*}



\begin{filecontents*}{superplot-source-code.tex}
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{graphicx}
\begin{document}
  \begin{figure}
    \label{fig:super-plot}
    \caption{Very strange plot}\centering
    \includegraphics[scale=0.5]{example-image}
  \end{figure}
\end{document}
\end{filecontents*}



\usepackage{standalone}
\begin{document}
  \input{chapter-about-this}
\end{document}

You must log in to answer this question.

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