In knitr, how to set shape width with \ textwidth from Latex

I tried the following to set the width of the shape 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?

+4
source share
2 answers

The parameter fig.widthmust be numeric to set the size of the image itself. To control the display of a drawing in LaTeX, use the out.widthand parameters out.height. These parameters must be strings, and you will need to avoid backslashes.

Part

<<plot1, fig.width = 5, fig.height = 5, out.width = "0.48\\textwidth">>=
@

, 48% . plot1-1.pdf , LaTeX

\includegraphics[width=0.48\textwidth]{figure/plot1-1}

.tex.

+4

fig.width , R . , \textwidth , . , ( ).

\ textwidth LaTeX, , . ,

\setkeys{Gin}{width=\textwidth}

R. (, graphicx LaTeX, , knitr.)

0

Source: https://habr.com/ru/post/1678126/


All Articles