I have tried the following to set figure width with knitr and LaTeX:
\documentclass{paper}
\begin{document}
<<fig.width=\textwidth>>
x = runif(1000)
plot(x)
@
\end{document}
However, I get the following error:
<to be read again>
>
l.54 <<fig.width=\textwidth>
>
What am I doing wrong?
The fig.width
option should be numeric for setting the size of the graphic itself. For controlling how the figure is displayed by LaTeX use the out.width
and out.height
options. These options need to be strings, and you'll need to escape backslashes.
The chunk
<<plot1, fig.width = 5, fig.height = 5, out.width = "0.48\\textwidth">>=
@
will generate a five inch by five inch graphic that will take up 48% of the textwidth in the final document. That is, the file plot1-1.pdf
is a five inch by five inch graphic, and the LaTeX code
\includegraphics[width=0.48\textwidth]{figure/plot1-1}
will be placed in the resulting .tex file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With