I have a problem with knitr and tikzDevice, like someone before me. (See tikzDevice is not getting sizes right (knitr) .) He used dev.args to get rid of this error, but if I run this code through knitr (with rstudio), the fontsize is still messed up. dev.args=list(pointsize=12) doesn't work for me. The only thing that works, is to remove a4paper,12pt. Any ideas on what I did do wrong?


<<dev='tikz', dev.args=list(pointsize=12)>>=


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.