在 R 中的 A4 PDF 的边框上书写文本 [英] Writing text on the border of an A4 PDF in R
本文介绍了在 R 中的 A4 PDF 的边框上书写文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在 PDF 设备上在页面的极端边框上书写.使用此代码段:
I need to write on a PDF device on the extreme border of the page. With this snippet:
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
我在页面中间的最左边得到一个带有 hello
的 foo.pdf
,正如预期的那样:
I get a foo.pdf
with hello
on the extreme left in the middle of the page, as intended,that is:
不幸的是,如果我将纸张输出设置为 paper='a4'
,那就是:
Unfortunately, if I set the paper output as paper='a4'
, that is:
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
不再放在边框上,而是:
hello
isn't put on the border anymore, but:
推荐答案
当 paper
设置为除 "special"
之外的其他内容时,参数 pagecentre代码>变得相关.如果将其设置为
FALSE
,则偏移量消失.
When paper
is set to something else than "special"
, argument pagecentre
becomes relevant. If you set it to FALSE
, then the offset disappears.
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()
这篇关于在 R 中的 A4 PDF 的边框上书写文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文