[Tex/LaTex] tikzDevice is not getting sizes right (knitr)

fontsizeknitrrtikz-pgf

I am using OSX, pdflatex, R (cran), tikz/tikzDevice and knitr to create my documents. My problem is that the font sizes of the produced tikZ-file do not match the LaTeX document font sizes.

Result / Problem

Here's a screenshot of the result:

Screenshot 1

As you can see, the text is way to big and the points/circles are too small.

Files

I have a main LaTeX file, called main.tex, which contains:

\documentclass[a4paper,12pt]{article}

\usepackage{tikz}

\begin{document}

%% begin.rcode myplot, dev='tikz',  external=FALSE, fig.width=5, fig.height=5
% plot(cars)
%% end.rcode

\hspace*{6.3cm}\color{red} speed

\end{document}

I then use a R-Script, called knit.R to convert the result of plot to tikZ-Code:

library(knitr)
render_latex()
knit("/Users/ralfix/Documents/main.tex")

It creates a new LaTeX file, called main-out.tex which contains the following:

...
\input{figure/myplot.tikz}
...
\hspace*{6.3cm}\color{red} speed
...

and a new tikZ-file, called myplot.tikz:

% Created by tikzDevice version 0.6.2-92-0ad2792 on 2013-03-30 18:14:48
% !TEX encoding = UTF-8 Unicode
\begin{tikzpicture}[x=1pt,y=1pt]
...
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  3.00] at (185.47,  6.24) {speed};
...
\end{tikzpicture}

I can remove the scale=3.0 in the tikz file to get the text right, but then some positioning is broken and the circles stay too small.

First Idea

If I remove the [a4paper,12pt] from my documentclass declaration and re-run my script, I get this much better result:

Screenshot 2

But if you compare the tikz output with the red LaTeX-output, the text is still too big. The tikz-file says scale=1.2 for text now.

How and where can I modify something to get every sizing correct?

Best Answer

Just found the solution myself:

Someone can set the point size for tikzDevice manually — With knitr, this is done by adding

dev.args=list(pointsize=12)

to the chunk options.

Hope this will help someone ;)

Related Question