Sub topic 7
Calculating column and module sizes
This chapter assumes you know what margins, gutters and columns are, and that you can read a page size in millimetres, points or pixels. Here you turn those parts into exact numbers.
The one formula
Every grid dimension comes from the same relationship. Take the space inside the margins, subtract the gutters, and divide what is left by the number of units.
unit = (length - margin_start - margin_end - (count - 1) * gutter) / countA grid with n columns has n − 1 gutters, because gutters only sit between columns. Forgetting this is the most common error. If you subtract n gutters, every column comes out too narrow and the grid does not fill the text area.
Columns
The function below applies the formula horizontally and assumes equal side margins.
def column_width(page_width, margin, gutter, columns):
"""Width of one column when both side margins are equal."""
usable = page_width - 2 * margin
return (usable - (columns - 1) * gutter) / columns
# A4 portrait is 210 mm wide: 20 mm margins, 5 mm gutters, 4 columns
print(column_width(210, 20, 5, 4)) # 38.75The usable width is 170 mm. The three gutters take 15 mm, which leaves 155 mm. Four columns of 38.75 mm fill that exactly.
Modules
A module is a column width crossed with a row height. The row height uses the same formula along the vertical axis, and the margins may differ between top and bottom. Print layouts often use a larger bottom margin for page numbers.
def unit_size(length, start, end, gutter, count):
"""Size of one column or row; margins may differ."""
return (length - start - end - (count - 1) * gutter) / count
def span_size(unit, gutter, n):
"""Size of a block that spans n units, including n-1 gutters."""
return n * unit + (n - 1) * gutter
def unit_start(start, unit, gutter, index):
"""Offset of unit number index (0-based) from the page edge."""
return start + index * (unit + gutter)
col = unit_size(210, 20, 20, 5, 4)
row = unit_size(297, 20, 20, 5, 6)
print(round(col, 2), round(row, 2)) # 38.75 38.67
print(span_size(col, 5, 2)) # 82.5
print(unit_start(20, col, 5, 1)) # 63.75A feature image that spans two columns is 82.5 mm wide, not 77.5 mm. A spanning block absorbs the gutter between the units it covers. Without that gutter, the image edges would not line up with the columns beside it.
Common errors
- Counting n gutters instead of n − 1.
- Mixing units, for example margins in millimetres and gutters in points.
- Rounding each column separately. Round only the final value, or the columns drift from the right margin.
- Choosing a row height that is not a multiple of the baseline unit, which breaks the vertical rhythm from the baseline grid chapter.
Working backwards
You can also fix the column width and solve for something else. If you want 4 columns of 40 mm with 5 mm gutters, the text area must be 4 × 40 + 3 × 5 = 175 mm wide. On a 210 mm page that leaves 35 mm for two margins, or 17.5 mm each.
Exercise
An A5 page is 148 mm wide. It has 15 mm margins on both sides, 4 mm gutters and 3 columns. How wide is one column, and how wide is a block spanning two columns?
Show answer
The usable width is 148 − 30 = 118 mm. Two gutters take 8 mm, which leaves 110 mm, so each column is 110 / 3 ≈ 36.67 mm. A two-column span is 2 × 36.67 + 4 ≈ 77.33 mm.