Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Welcome to TeX.SE! –  Jubobs Mar 14 '13 at 0:03
    
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}). –  Jubobs Mar 14 '13 at 0:06
1  
@Jubobs that is true unless you use standalone class and package –  JLDiaz Mar 14 '13 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 Mar 14 '13 at 0:15
    
@JLDiaz I didn't know that. Thanks. –  Jubobs Mar 14 '13 at 0:17

1 Answer 1

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.