如何用 two-row header 创建 table - PrawnPDF

How to create a table with a two-row header - PrawnPDF

我用 PrawnPDF 生成了一个简单的 table,如下所示

|h1|h2|h3|h4|
-------------
|d1|d2|d3|d4|
|d1|d2|d3|d4|
|d1|d2|d3|d4|

由下面的代码生成

tb = [["h1", "h2", "h3", "h4"],
      ["d1", "d2", "d3", "d4"],
      ["d1", "d2", "d3", "d4"],
      ["d1", "d2", "d3", "d4"]]

table(tb)do
  row(0).font_style = :bold
end

现在 header 需要由两行组成,如下所示

|text       |
|h1|h2|h3|h4|
-------------
|d1|d2|d3|d4|
|d1|d2|d3|d4|
|d1|d2|d3|d4|

我尝试制作一个子table并将其用作header,但它并没有跨越所有table。看起来像

|text       |
|h1|h2|h3|h4|
----------------------
|d1         |d2|d3|d4|
|d1         |d2|d3|d4|
|d1         |d2|d3|d4|

并且没有一行是粗体。

这里是目前的代码

text = make_cell(content: 'text', colspan: 4)
header_array = [[text], ["h1", "h2", "h3", "h4"]]
header = make_table(header_array)

tb = [[header],
      ["d1", "d2", "d3", "d4"],
      ["d1", "d2", "d3", "d4"],
      ["d1", "d2", "d3", "d4"]]

table(tb)do
  row(0).font_style = :bold
end

关于如何跨越 header 的任何想法?

PS大虾我用的是1.3.0和prawn-table0.2.2

谢谢

更新 - 根据 Florent 的回答,如果你 want/need 将一个块传递给 table。

header_text = [[{content: "Text", colspan: 4}]]
tb = [["h1", "h2", "h3", "h4"],
  ["d1", "d2", "d3", "d4"],
  ["d1", "d2", "d3", "d4"],
  ["d1", "d2", "d3", "d4"]]

table(header_text + tb)do
  row(0).font_style = :bold
  self.header = 2
end

你尝试使用 header 参数吗?

header_text = [[{content: "Text", colspan: 4}]]
tb = [["h1", "h2", "h3", "h4"],
  ["d1", "d2", "d3", "d4"],
  ["d1", "d2", "d3", "d4"],
  ["d1", "d2", "d3", "d4"]]

table(header_text + tb, header: 2)do
  row(0).font_style = :bold
end