Question

I have a problem with knitr and tikzDevice, like someone before me. (See https://tex.stackexchange.com/questions/106057/tikzdevice-is-not-getting-sizes-right-knitr/106595#106595 .) 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?

\documentclass[a4paper,12pt]{scrartcl}
\begin{document}

\begin{figure}
<<dev='tikz', dev.args=list(pointsize=12)>>=
x<-1
plot(x)
@
\end{figure}

\end{document}
Was it helpful?

Solution

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) {
        return(NA)
    }
    else {
        pointsize <- substr(docString, psLocation, psLocation + 
            attr(psLocation, "match.length") - 2)
        return(as.numeric(pointsize))
    }
}

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:

\documentclass[12pt,a4paper]{scrartcl}

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top