虾: 是否有一种方法可以对盒子中的所有内容进行垂直对齐?

9

我正在尝试将一些内容垂直居中在一个 bounding_box 中。对于单一的文本,这没有问题:

bounding_box([0, bounds.top], :width => pdf.bounds.right, :height => pdf.bounds.top) do
  text "vertically aligned in the surrounding box", :valign => :center
end

但如果我的边界框中有多个元素,我该怎么办:

bounding_box([0, bounds.top], :width => pdf.bounds.right, :height => pdf.bounds.top) do
  text "vertically aligned in the surrounding box", :valign => :center
  text "vertically aligned in the surrounding box", :valign => :center
end

如果尝试这样做,文本会重叠,那么这种方法是行不通的...

我正在寻找一种方法来对bounding_box的整个内容进行分组,然后将整个组垂直对齐。有没有使用prawn实现这个的方法?

非常感谢你的帮助! Chris

1个回答

7

如果你只有文本行,仍然可以在文本中使用 formatted_text 并使用 \n 进行换行:

formatted_text [
    { text: "#{line1}\n" },
    { text: "#{line2}" }
  ],
  valign: :center,
  leading: 6

我仍然在尝试解决图片/图例组的处理方法,因为即使是表格也似乎行不通。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接