class Prawn::Table
def column_widths
sizes, you should specify more column widths manually.
you see weird problems like CannotFit errors or shockingly bad column
at guessing a good size for columns that have vastly different content. If
Because the natural widths can be silly, this does not always work so well
the table or column size.
each cell's min_width, max_width, and any user-specified constraints on
Calculate and return the constrained column widths, taking into account
def column_widths @column_widths ||= begin if width - cells.min_width < -Prawn::FLOAT_PRECISION raise Errors::CannotFit, "Table's width was set too small to contain its contents " + "(min width #{cells.min_width}, requested #{width})" end if width - cells.max_width > Prawn::FLOAT_PRECISION raise Errors::CannotFit, "Table's width was set larger than its contents' maximum width " + "(max width #{cells.max_width}, requested #{width})" end if width - natural_width < -Prawn::FLOAT_PRECISION # Shrink the table to fit the requested width. f = (width - cells.min_width).to_f / (natural_width - cells.min_width) (0...column_length).map do |c| min, nat = column(c).min_width, natural_column_widths[c] (f * (nat - min)) + min end elsif width - natural_width > Prawn::FLOAT_PRECISION # Expand the table to fit the requested width. f = (width - cells.width).to_f / (cells.max_width - cells.width) (0...column_length).map do |c| nat, max = natural_column_widths[c], column(c).max_width (f * (max - nat)) + nat end else natural_column_widths end end end