class Asciidoctor::Table
def assign_column_widths width_base = nil, autowidth_cols = nil
width_base - the total of the relative column values used for calculating percentage widths (default: nil)
This method assumes there's at least one column in the columns array.
donates the balance to the final column.
This method rounds the percentage width values to 4 decimal places and
Internal: Assign column widths to columns
def assign_column_widths width_base = nil, autowidth_cols = nil precision = DEFAULT_PRECISION total_width = col_pcwidth = 0 if width_base if autowidth_cols if width_base > 100 autowidth = 0 logger.warn %(total column width must not exceed 100% when using autowidth columns; got #{width_base}%) else autowidth = ((100.0 - width_base) / autowidth_cols.size).truncate precision autowidth = autowidth.to_i if autowidth.to_i == autowidth width_base = 100 end autowidth_attrs = { 'width' => autowidth, 'autowidth-option' => '' } autowidth_cols.each {|col| col.update_attributes autowidth_attrs } end @columns.each {|col| total_width += (col_pcwidth = col.assign_width nil, width_base, precision) } else col_pcwidth = (100.0 / @columns.size).truncate precision col_pcwidth = col_pcwidth.to_i if col_pcwidth.to_i == col_pcwidth @columns.each {|col| total_width += col.assign_width col_pcwidth, nil, precision } end # donate balance, if any, to final column (using half up rounding) @columns[-1].assign_width(((100 - total_width + col_pcwidth).round precision), nil, precision) unless total_width == 100 nil end