I recently opened knitr, and I mainly use it to create graphs with dev=tikz to easily get a set of latex sets. However, I do not understand how to set the package parameters fig.width and out.width with consistency.
I mean, I know that the first one is the R option and the second is the latex option coming with \includegraphics , but it seems that if fig.width too large compared to out.width , then the lines are very thin, because latex compresses the image. On the other hand, if it is too small, then latex stretches it, and everything is too large.
In principle, I would like to have a setting in which I select only out.width , and then the thickness of the lines and texts is consistent with the size of the document text.
I include MWE illustrating my problem. In addition, I set fig.height in the first example, otherwise the image was larger than the page, and I do not really understand this.
Any help is appreciated!
\documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage[T1]{fontenc} \usepackage{graphicx} <<setup, include=FALSE, cache=FALSE>>= library(knitr) options(formatR.arrow=TRUE,width=50) opts_chunk$set(fig.path='figure/graphics-', cache.path='cache/graphics-', fig.align='center', dev='tikz') @ \begin{document} \begin{figure}[!ht] <<fig_1,fig.width=2, fig.height = 3,out.width = '\\textwidth',echo=FALSE>>= x = seq(1,3,l=100) plot(x,cos(x), type ="l", xlab = "x", ylab = "y") @ \end{figure} \begin{figure}[!ht] <<fig_2,fig.width=10, out.width = '\\textwidth',echo=FALSE>>= x = seq(1,3,l=100) plot(x,cos(x), type ="l", xlab = "x", ylab = "y") @ \end{figure} \end{document}