在 R 中在 A4 PDF 的边框上写入文本

2024-01-10

我需要在 PDF 设备上在页面的最边缘书写。有了这个片段:

pdf('foo.pdf')          #Write next plot to foo.pdf in current dire 
par(mar=c(0, 0, 0, 0))  #Set numbers of lateral blank lines to zero
par(xaxs='i', yaxs='i') #Does not extend axes by 4 percent for pretty labels 
plot.new()              #Create a blank plot, as we just want to write our text  
text(0, .5, "hello", pos=4, offset=0) #Write to the right with no default 0.5 offset
dev.off()               #Close device, that is saving for a PDF device

I get a foo.pdf with hello按照预期,在页面中间的最左边,即:

不幸的是,如果我将纸张输出设置为paper='a4', 那是:

pdf('foo.pdf', paper='a4') #note the A4 setting 
par(mar=c(0, 0, 0, 0))
par(xaxs='i', yaxs='i' )
plot.new()
text(0, .5, "hello", pos=4, offset=0)
dev.off()

hello不再放在边界上,但是:


When paper设置为其他值"special", 争论pagecentre变得相关。如果您将其设置为FALSE,则偏移量消失。

pdf('foo.pdf', paper='a4', pagecentre=FALSE)
par(mar=c(0, 0, 0, 0))
par(xaxs='i', yaxs='i' )
plot.new()
text(0, .5, "hello", pos=4, offset=0)
dev.off()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 R 中在 A4 PDF 的边框上写入文本 的相关文章

随机推荐