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.


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




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

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


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


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

\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
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  3.00] at (185.47,  6.24) {speed};

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?

2 Answers 2


Just found the solution myself:

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


to the chunk options.

Hope this will help someone ;)


Yihui answered the question:

This turns out to be a bug of tikzDevice package, which has been reported long time ago (but still not fixed). The problem is the regular expression used to detect the pointsize was wrong (they should have used pt instead of [pt]):

> tikzDevice:::getDocumentPointsize
function (docString) 
    psLocation <- regexpr("\\d+[pt]", docString, ignore.case = T, 
        perl = T)
    if (psLocation == -1) {
    else {
        pointsize <- substr(docString, psLocation, psLocation + 
            attr(psLocation, "match.length") - 2)

There are a number of ways to fix this problem. The best way is to fix it in tikzDevice, of course. Before that happens, you can use this simple trick:


That is, switch 12pt with a4paper so that 12 instead of 4 can be detected.

  • 1
    Welcome to TeX.sx! Commented Apr 2, 2013 at 20:09
  • Thank you for your answer! In my real setup, I do not set the font and paper size explicitly. I use my own document class which sets the sizes internally, so the LaTeX parser of tikzDevice does not see the font size. So the only solution for me was to set the sizes with knitr. Commented Apr 4, 2013 at 19:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .