[Tex/LaTex] Insert line break into knitr fig.cap

knitrr

I am using knitr and want to insert a line break in my fig.cap chunk option. Is this possible? The following is all I can think of but it doesn't work. I expect there's some evaluation option but I struggle to understand how evaluation works…

\documentclass{article}

\begin{document}

<<chunk1, fig.cap = "This figure is great! Do you \n agree?">>=
plot(1:10)
@


\end{document}

Best Answer

Use a LaTeX linebreak instead of an R linebreak and use the caption package. The following works for me:

\documentclass{article}

\usepackage[format=plain, justification=raggedright,singlelinecheck=true]{caption}

\begin{document}

<<chunk1, fig.cap = "This figure is great! Do you \\\\ agree?">>=
plot(1:10)
@

\end{document}