2013-03-26 19 views
1

在你說使用搜索之前,我做了,我讀了this answer,我試了一下,它沒有幫助,我想這可能是因爲從另一個文件中包含它。 (不知道..)對Sweave中的數字的動態引用

我有一個Sweave文件,我正在使用R studio編寫。運行R代碼完美運行,其中包括其他文件。這裏是什麼樣的主文件看起來像一些例子:

\documentclass{report} 

\begin{document} 
\SweaveOpts{concordance=TRUE} 

\maketitle 
\tableofcontents 

\input{tex/introduction} 
\input{tex/methods} 
\SweaveInput{tex/analysis} 
\input{tex/conclusions} 
\SweaveInput{tex/further} 

\bibliographystyle{plain} 
\bibliography{tex/literature} 

\appendix 
\input{tex/appendix} 

\end{document} 

然後由\SweaveInput{}引用的.Rnw文件中的一個我用的是這樣的:

\begin{figure}[h] 
\label{fig1} 
\caption{This is a caption!} 
\centering 
<<fig=TRUE, echo=FALSE>>= 
...data and plotting... 
@ 
\end{figure} 

In figure \ref{fig1} we can see that there is... 

和代替圖號我只是得到[??]

你也許知道爲什麼會發生這種情況?我該如何解決它?

我看着knitr包,但我不知道如何包括一個外部文件,就像我的例子中,我得到了其他有趣的錯誤。另外,我不知道它是否會在那裏工作。基本上,我將不得不做更多的研究,爲什麼我的代碼不起作用,我只想得到當前的代碼運行。

Tnx。

回答

4

label需要在caption之後來。看例如,https://tex.stackexchange.com/q/23385

+0

tnx ..解決了它!我想知道爲什麼我能夠在其他基本'.tex'文件中使用它。 :/ – Alan 2013-03-26 14:55:53

+1

它以錯誤的順序工作,但錯誤地指向前一個數字。在這種情況下,沒有以前的號碼。 – Aaron 2013-03-26 16:02:23