setMarginsiText中的方法是否以传统方式工作?
我尝试过以下方法:
System.out.println(f.exists());
Document document = new Document(PageSize.A4,36,36,36,36);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f.getAbsolutePath()+"0.pdf"));
document.open();
//reader
PdfReader reader = new PdfReader(new FileInputStream(f));
PdfContentByte cb = writer.getDirectContent();
for(int i = 1 ; i < reader.getNumberOfPages()+1 ; i++)
{
System.out.println(f.getName()+" "+i);
PdfImportedPage page = writer.getImportedPage(reader, i);
document.newPage();
cb.addTemplate(page,0,0);
}
// Add your new data / text here
// for example...
//document.add(new Paragraph("my timestamp"));
document.close();
Run Code Online (Sandbox Code Playgroud)
但是,我获得与输入相同的输出.我想知道是否有一个特殊的技巧让setMargins方法正常工作.
我在一个图中绘制了两个子图(2x1).我想删除两个子图之间的所有间距,并删除顶部子图的xlable和xlabel刻度.此外,我试图删除子图外的所有间距.我试试
set(gca, 'LooseInset', get(gca,'TightInset'))
Run Code Online (Sandbox Code Playgroud)
但它不起作用.现在我手动删除这些边距和标签,我需要处理60个数字并且手动执行所有这些操作非常耗时.有更好的方法吗?谢谢.
我也尝试了subtightplot,它有助于减少所有边距,但xlabel和ylabel也被剪切
margins=[0 0];
t = 0:0.01:10;
y1 = sin(t);
y2 = cos(t);
h1 = subtightplot(2,1,1, margins);
plot(t, y1);
ystr = {'sin(x)','(dimensionless)'}
hy1 = ylabel(ystr);
set(gca, 'fontsize', 14);
set(hy1, 'fontsize', 14);
set(gca, 'XTickLabel', [],'XTick',[])
h2 = subtightplot(2,1,2,margins);
plot(t, y2, 'r-o');
hx2=xlabel('frequency');
hy2=ylabel('amplitude');
set(gca, 'fontsize', 14);
set(hx2, 'fontsize', 14);
set(hy2, 'fontsize', 14);
Run Code Online (Sandbox Code Playgroud)
我也尝试了subplot_tight,但情况更糟
我有以下示例数据:
sel = structure(c(1.29955, 2.52295, 1.11021, 2.52008, 8.20255, 8.50118,
5.82189, 5.8108, 1.55928, 8.2552, 5.25119, 5.55055, 1.22525,
3.152, 3.9299, 5.50921, 5.25591, 5.11218, 1.55951, 2.5525,
9.2358, 2.0928, 5.2538, 2.5539, 8.52592, 2.59521, 5.55858,
5.92955, 2.22089, 1.52105),
.Dim = c(10L, 3L), .Dimnames = list(c("a", "b",
"c", "d", "e", "f", "g", "h",
"i", "j"), c("Label.1", "Label.2", "Label.3")))
Run Code Online (Sandbox Code Playgroud)
我使用此代码绘制图形:
col = c("#FF0000", "#FF0000", "#FF0000")
par(mar=c(7,4,4,2)+0.1)
png(filename='test.png', width=800, height=750)
heatmap.2(sel, col=redgreen(75), scale="row", ColSideColors=col,
key=TRUE, symkey=FALSE, density.info="none", trace="none")
graphics.off()
Run Code Online (Sandbox Code Playgroud)
这给了我这个热图:

如您所见,x轴标签被切断.我试图使par(mar=c(7,4,4,2)+0.1)(从默认值par(mar=c(5,4,4,2)+0.1))更大的边距,但这不会改变标签被切断的方式.
我试图改变lmat, …
我的应用程序只是一个修改过的ImageViewer,可以选择缩放和拖动.包含修改后的Imageviewer有一个RelativeLayout(我想用作AbsoluteLayout).
然后,可以将新元素添加到布局中以将它们置于图像的某些点中.元素的位置(x,y)以像素为单位,因此我想没有其他方式可以通过编程方式添加它们,而不是使用XML.
然后,每次执行拖动或缩放操作时,都会更新这些元素的位置.
问题是,不知何故,图像的像素与RelativeLayout中的像素不匹配!因此项目"或多或少"位于但不在适当的位置(距离(0,0)越远,误差越大).
我已经尝试过的事情:
尝试不同的转换,因为问题可能与位图和布局之间的密度差异有关:
Resources r = getResources();
float x = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud)尝试在布局中使用不同的方法来设置边距:
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.leftMargin = (int) newPosition.x;
params.topMargin = (int) newPosition.y;
element.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)我也想在XML中使用RelativeLayout的可用选项,但我真的无法以编程方式找到它,但我可以找到指定维度的方法,我的意思是:
android:layout_marginLeft ="50px" // or "50mm", or dp, or inches...
Run Code Online (Sandbox Code Playgroud)我不知道如何使用网格R包指定PDF打印的边距.
我创建了一个grid.arrange()对象,我把它放在这样的PDF中:
pdf('test.pdf',11.69,8.27)
grid.arrange(textGrob('text1', gp=gpar(cex=4)),
ncol=1, main=textGrob('title', gp=gpar(cex=1.5)),
widths = c(1), heights = c(1))
dev.off()
Run Code Online (Sandbox Code Playgroud)
但标题是在表格的顶部边缘推动.我想补充保证金.如果我为标题添加一个textGrob而不是main=函数,我可以让它远离顶部,但它不是我的解决方案,因为我必须放置图形,它们也接近边缘.
关于折叠边距的CSS 2.1规范的第8.3.1节说明:
如果具有间隙的元素的顶部和底部边距相邻,则其边缘会随着后续兄弟的邻接边缘而折叠,但是所产生的边距不会随着父块的下边缘而崩溃.
这是我的,肯定不稳定的尝试,从这个陈述中做出一些事情:
该语句考虑了一个元素X,其中:
X有间隙,因此"clear:left;","clear:right"中的任何一个.或者"明确:两者;" 属性已应用于它.
由于X的顶部和底部边距是相邻的,在正常流动的情况下,我们正在考虑以下情况:
然后规范说,"它的边缘随着兄弟姐妹的邻接边缘而崩溃",但如上所述,最多只有一个兄弟姐妹,所以这基本上必须意味着如果有一个兄弟姐妹,那么边缘就会崩溃.
"但是由此产生的边际不会随着父块的底部边缘而崩溃." - 我不明白这一点:如果底部边缘与兄弟的上边距相邻,那么除非兄弟的高度为零,否则它不能与父块的下边距相邻.
我完全糊涂了.有人可以用更好的方式解释这个陈述,或许只是举几个例子吗?谢谢.
我想在法线图中绘制一些点,并将这些点链接到它下面显示的地图.我想要的基本是(这里我手动添加了链接):

不知怎的,我应该用segments它pdt=T来写边距,但我不确定我需要做什么数学变换才能为进入地图的分段末端设置正确的坐标.
我宁愿使用传统的plot功能而不是 ggplot2
这里是用于绘制示例的源(警告可能需要一些时间来加载打开的街道地图):
library(OpenStreetMap)
#Random point to plot in the graph
fdata=cbind.data.frame(runif(12),runif(12),c(rep("A",4),rep("B",4),rep("C",4)))
colnames(fdata)=c("x","y","city")
#random coordinate to plot in the map
cities=cbind.data.frame(runif(3,4.8,5),runif(3,50.95,51),c("A","B","C"))
colnames(cities)=c("long","lat","name")
#city to color correspondance
color=1:length(cities$name)
names(color)=cities$name
maxlat=max(cities$lat)
maxlong=max(cities$long)
minlat=min(cities$lat)
minlong=min(cities$long)
#get some open street map
map = openmap(c(lat=maxlat+0.02,long=minlong-0.04 ) ,
c(lat=minlat-0.02,long=maxlong+.04) ,
minNumTiles=9,type="osm")
longlat=openproj(map) #Change coordinate projection
par(mfrow=c(2,1),mar=c(0,5,4,6))
plot( fdata$y ~ fdata$x ,xaxt="n",ylab="Comp.2",xlab="",col=color[fdata$city],pch=20)
axis(3)
mtext(side=3,"-Comp.1",line=3)
par(mar=rep(1,4))
#plot the map
plot(longlat,removeMargin=F)
points(cities$lat ~ cities$long, col= color[cities$name],cex=1,pch=20) …Run Code Online (Sandbox Code Playgroud) 我曾经pdftk解压PDF,然后将其作为文本文件打开.
我想编辑/ MediaBox字段,这是我的情况
/MediaBox [0 0 612 792]
Run Code Online (Sandbox Code Playgroud)
例如,我想减少利润
/MediaBox [100 0 512 792]
Run Code Online (Sandbox Code Playgroud)
不幸的是它不起作用.我可以0改成一个2或一个,9但我不能举个100例子.
知道为什么吗?
我正在绘制如下图表.我用来生成图例的代码是
legend(4, 20, c("Placebo", "Progabide"), lty=1:2, pch=c(1,16), col=1:2, cex=0.8)
Run Code Online (Sandbox Code Playgroud)

问题是内边距(垂直方向)太大,我想减少它.我想缩小内部边缘的另一种方法是进一步减少"cex".但随后盒子里的文字也会变小.有没有办法减少盒子但不减少其内容.