Support table and table column sizing
All checks were successful
CI Pipeline / build (pull_request) Successful in 13s

This commit is contained in:
2025-12-03 13:50:56 +01:00
parent 00cabb6dfb
commit 843466549a
13 changed files with 520 additions and 30 deletions

View File

@@ -332,6 +332,75 @@ doc.table(style: :borderless) do
end
```
#### Column Sizing
Control table column widths with layout modes and explicit sizing.
**Auto-layout** - columns adjust to fit content:
```ruby
doc.table(layout: :auto) do
doc.tr do
doc.td "Short"
doc.td "This column expands to fit longer content"
end
end
```
**Fixed column widths** - specify widths for all columns:
```ruby
# Inches
doc.table(columns: %w[2in 3in 1.5in]) do
doc.tr do
doc.td "2 inches"
doc.td "3 inches"
doc.td "1.5 inches"
end
end
# Centimeters
doc.table(columns: %w[5cm 10cm]) do
doc.tr { doc.td "5cm"; doc.td "10cm" }
end
# Percentages
doc.table(columns: %w[25% 50% 25%]) do
doc.tr { doc.td "Quarter"; doc.td "Half"; doc.td "Quarter" }
end
```
**Per-cell widths** - set width on individual cells:
```ruby
doc.table do
doc.tr do
doc.td("Narrow", width: "1in")
doc.td("Wide", width: "4in")
end
end
```
**Combined layout and columns:**
```ruby
doc.table(layout: :fixed, columns: %w[2in 2in 2in]) do
doc.tr do
doc.td "A"
doc.td "B"
doc.td "C"
end
end
```
**Width formats:**
| Format | Example | Description |
|--------|---------|-------------|
| Inches | `"2in"` | Fixed width in inches |
| Centimeters | `"5cm"` | Fixed width in centimeters |
| Percentage | `"50%"` | Percentage of table width |
### Images
Images can be added to paragraphs, table cells, and list items. Supports PNG and JPEG formats.
@@ -526,10 +595,10 @@ end
| `li(text)` | List item with text |
| `li { }` | List item with block content |
| `li(text) { }` | List item with text and nested content |
| `table(style:) { }` | Table with optional style |
| `table(style:, layout:, columns:) { }` | Table with optional style, layout (`:auto`/`:fixed`), and column widths |
| `tr { }` | Table row |
| `td(text)` | Table cell with text |
| `td { }` | Table cell with block content |
| `td(text, width:)` | Table cell with text and optional width |
| `td(width:) { }` | Table cell with block content and optional width |
| `image(path, width:, height:)` | Insert image (PNG/JPEG). Dimensions: `"2in"`, `"5cm"`, `"100px"`, or integer pixels |
## Development