我对knitr
和tikzDevice
有问题,就像我之前的一些人一样。(参见https://tex.stackexchange.com/questions/106057/tikzdevice-is-not-getting-sizes-right-knitr/106595#106595。)他使用dev.args
来消除这个错误,但是如果我通过knitr
(与rstudio
一起)运行这段代码,字体大小仍然混乱。dev.args=list(pointsize=12)
对我不起作用。唯一有效的方法是删除a4paper,12pt
。你知道我哪里做错了吗?
documentclass[a4paper,12pt]{scrartcl}
begin{document}
begin{figure}
<<dev='tikz', dev.args=list(pointsize=12)>>=
x<-1
plot(x)
@
end{figure}
end{document}
这原来是tikzDevice
包的一个bug,很久以前就报告了(但仍然没有修复)。问题是用于检测点大小的正则表达式是错误的(他们应该使用pt
而不是[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))
}
}
有很多方法可以解决这个问题。当然,最好的方法是在tikzDevice
中修复它。在此之前,您可以使用这个简单的技巧:
documentclass[12pt,a4paper]{scrartcl}
即将12pt
与a4paper
交换,这样可以检测到12
而不是4
。