I'm writing a paper for the journal PLOSone. They require that figure captions be placed in the article but not the figure itself (it's submitted separately). So I'm wondering how to get knitr
to spit out the figure caption w/o the figure. Of course, this is not quite possible, since the figure number and hence caption isn't finalized until LaTeX
has been run. So this question may need to be migrated eventually, but maybe someone has an idea about the necessary steps. Here is a MWE:
\documentclass[10pt, letterpaper]{article}
% Bold the 'Figure #' in the caption and separate it from the title/caption with a period
% Captions will be left justified
\usepackage[aboveskip = 1pt, labelfont = bf, labelsep = period, justification = raggedright, singlelinecheck = off]{caption}
\begin{document}
This is my document. Here is a cool plot: Fig.~\ref{LabelA}.
<< ChunkA, fig.cap = "\\label{LabelA}\\bf{A Figure.}" , echo = FALSE >>=
plot(1:10, 1:10)
currCap <- knitr::opts_current$get("fig.cap")
@
<< ChunkB, results = "asis" , echo = FALSE >>=
cat("\n")
cat(currCap)
@
\end{document}
This isn't quite the right approach, for two reasons. First, LaTeX
can process this, but the output from cat(currCap)
creates a duplicate label which confuses it. Second, the line of text that I want in the final pdf is:
Figure 1. A Figure.
but the information that this is Figure 1 and not some other figure is not known prior to compiling in LaTeX
. Here is a little piece of the tex file which shows the output from the above code where you can see how the duplicate label arises.
This is my document. Here is a cool plot: Fig.~\ref{LabelA}.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{figure}
\includegraphics[width=\maxwidth]{figure/ChunkA-1} \caption{\label{LabelA}\bf{A Figure.}}\label{fig:ChunkA}
\end{figure}
\end{knitrout}
\label{LabelA}\bf{A Figure.}
Anyone know a way to make this work?
sed
) to replace all\includegraphics
with a 1-pixel graphic or even remove the graphic altogether and keep the\caption
? Here and here are alternatives.