How can I set a table row to span multiple columns?

2,430 views
Skip to first unread message

AK

unread,
Nov 9, 2011, 10:22:34 AM11/9/11
to Prawn
I tried this:

data = [['small','small'],['big'],['small','small']]

Prawn::Document.generate("x.pdf") do
table data do |t|
t.rows(1).width = 540
end
end

But it gives me:

Prawn::Errors::CannotFit: Table's width was set too small to contain
its contents (min width 559.996, requested 540.0)

I also tried setting:

t.rows(1).columns(0).width = 540

but same thing.

Sara T

unread,
Nov 9, 2011, 10:46:21 AM11/9/11
to Prawn
Short answer: I think you're out of luck.

Long answer: colspan was removed after the 0.84 release, and they
haven't worked out a way to put it back in. Right now you can put a
subtable inside a cell, but you can't merge cells.

The manual in PDF format - subtables are on page 80:
http://prawn.majesticseacreature.com/manual.pdf

-Sara

John Twilley

unread,
Nov 9, 2011, 11:16:55 AM11/9/11
to prawn...@googlegroups.com
This is probably the single feature that will improve my current prawn
usage. I'm fakin' it with clumsy hackarounds and I sorta like the
results, but a proper multi-row/multi-column solution would be much
more elegant and easier to maintain!

Jack.
--
mathuin at gmail dot com

Randy Parker

unread,
Nov 9, 2011, 12:06:52 PM11/9/11
to prawn...@googlegroups.com
Last week I wished for a colspan feature when creating a report that required 7 nested tables. One of the nested tables would have been required even with colspan, but as it stands, each of the other 6 have column widths computed from the 7th table that has the greatest number of columns.  Sort of a clumsy DIY colspan.

The actual difficulty of creating the 7-table report isn't that much more than a 2-table-with-colspan approach, but the column spanning way of looking at it is just more familiar to everybody because it's what you do with spreadsheets and HTML.  Colspan is a convenience feature.

Naturally, every downstream programmer new to Prawn who fools with this report for the next several years can be expected to attempt to "clean it up" with colspan (the code has comments, but they'll check to make sure that Prawn hasn't added the "missing colspan" since the last time someone looked)

- Randy

Brad Ediger

unread,
Nov 9, 2011, 12:17:33 PM11/9/11
to prawn...@googlegroups.com

On Nov 9, 2011 7:22 AM, "AK" <ak.from.w...@gmail.com> wrote:
>
> I tried this:
>
> data = [['small','small'],['big'],['small','small']]
>
> Prawn::Document.generate("x.pdf") do
>    table data do |t|
>        t.rows(1).width = 540
>    end
> end
>
> But it gives me:
>
> Prawn::Errors::CannotFit

The other posters are correct. The is currently no way for table cells to span a column or row. You're getting that error because Prawn is attempting to size the first column to fit that entire oversized cell.

I have some ideas about how to implement spanning in Prawn, but I haven't had the time to flesh them out yet.

Brad

AK

unread,
Nov 10, 2011, 10:50:30 AM11/10/11
to Prawn
Mine was a little bit goofy, because I have a 2-page side-by-side
layout, but I'm just doing crazy and confusing loops to manage it and
it seems to be working.
Reply all
Reply to author
Forward
0 new messages