Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在A4PDF的边框上用R书写文本_R_Pdf Generation - Fatal编程技术网

在A4PDF的边框上用R书写文本

在A4PDF的边框上用R书写文本,r,pdf-generation,R,Pdf Generation,我需要在页面最边缘的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

我需要在页面最边缘的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
我得到一个<代码> fo.pdf >代码> 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
不再放在边界上,但是:


好吧,我可以确认它对我也不起作用;它看起来像一只虫子

解决此问题的方法是直接在
pdf
调用中设置A4纸张尺寸:

pdf('foo.pdf', width=8.3, height=11.7) #we set A4 dimensions of 8.3 x 11.7 inches
par(mar=c(0, 0, 0, 0))
par(xaxs='i', yaxs='i' )
plot.new()
text(0, .5, "hello", pos=4, offset=0)
dev.off()

纸张
设置为非
“特殊”
时,参数
页面中心
变得相关。如果将其设置为
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()

您的方法适用于0边界,但不适用于1边界。对于A4纸张,
文本(0,1,“你好”,位置=4,偏移量=0)
将位于页面高度的75%左右。最糟糕的是,凡是
y>1
(或
x>1
)的文本都被认为超出了边界,没有打印出来。