LaTeX figure label from R plot using KnitR?

前端 未结 1 1312
北荒
北荒 2020-12-09 07:34

I can\'t get R/KnitR to create the LaTeX \\label{} statement for a figure. The manual seems to indicate that a \\label{} statement will be created

相关标签:
1条回答
  • 2020-12-09 08:39

    You need to set fig.cap = '' (or whatever you wish) to ensure that a figure environment is used in the latex document. (you may have noticed that the \begin{figure} ... \end{figure} is missing along with the \label{} component

    eg

    \documentclass[12pt, english, oneside]{amsart}
    \begin{document}
    See Figure \ref{fig:plot}.
    <<plot, fig.lp="fig:", fig.cap = ''>>=
    plot(x=0, y=0)
    @
    \end{document}
    

    I would agree that the description from the website is less than clear as to this being necessary.

    • fig.env: ('figure') the LaTeX environment for figures, e.g. set fig.env='marginfigure' to get \begin{marginfigure}

    • fig.cap: (NULL; character) figure caption to be used in a figure environment in LaTeX (in \caption{}); if NULL or NA, it will be ignored, otherwise a figure environment will be used for the plots in the chunk (output in \begin{figure} and \end{figure})

    Although the graphics manual is clear, and the reasoning makes sense

    Figure Caption

    If the chunk option fig.cap is not NULL or NA, the plots will be put in a figure environment when the output format is LATEX, and this option is used to write a caption in this environment using \caption{}. The other two related options are fig.scap and fig.lp which set the short caption and a prefix string for the figure label. The default short caption is extracted from the caption by truncating it at the first period or colon or semi-colon. The label is a combination of fig.lp and the chunk label. Because figure is a float environment, it can float away from the chunk output to other places such as the top or bottom of a page when the TEX document is compiled.

    If you were wishing to replicate a R session output, you wouldn't want the figures to float away from the line of code which defines how they were created.

    0 讨论(0)
提交回复
热议问题