Numbers, tables and totals / Comparison columns
This period against last period, side by side and comparable
The same set of figures for two periods, printed adjacent so the difference between them can be read without arithmetic.
Why this block is harder than it looks
The whole value of the block is that two numbers can be compared by eye, and almost everything that goes wrong destroys exactly that. Different decimal places between the columns, a thousands separator in one and not the other, a slightly different column width, or a variance column placed on the far side of the table so the eye has to travel: each of these turns a comparison into a calculation. The other trap is that a comparison of two periods of different lengths is not a comparison at all, and if that can happen the document has to say so.
The decisions that make it work
Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.
- Give both period columns identical width, alignment and decimal places. Any asymmetry between them reads as a difference in the data.
- Put the variance column immediately beside the two it compares, not at the end of the row past three other columns.
- Give the two periods explicit headers with their dates, not just current and previous. A reader six months later has no idea which is which.
- State the period lengths where they can differ, and mark any row where the comparison is not like for like.
- Show the variance as both an absolute and a percentage where there is room. Either one alone is misleading on small bases.
- Do not colour the variance red and green. It is invisible in monochrome, and a sign with a fixed slot conveys the same thing on any device.
The fragment
Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.
<table class="compare">
<thead>
<tr>
<th>Line</th>
<th class="n">Q1 2026</th><th class="n">Q1 2025</th>
<th class="n">Change</th><th class="p">%</th>
</tr>
</thead>
<tbody>
<tr><td>Service revenue</td>
<td class="n">184,200.00</td><td class="n">171,400.00</td>
<td class="n"><i></i>12,800.00</td><td class="p"><i></i>7.5</td></tr>
<tr><td>Materials</td>
<td class="n">42,100.00</td><td class="n">45,900.00</td>
<td class="n"><i>−</i>3,800.00</td><td class="p"><i>−</i>8.3</td></tr>
</tbody>
</table>
<style>
.compare { width: 100%; border-collapse: collapse; font-size: 9pt; table-layout: fixed; }
.compare th, .compare td { padding: 3pt 4pt; }
.compare .n, .compare .p {
text-align: right;
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.compare .n { width: 19%; } /* both periods identical width */
.compare .p { width: 10%; color: #555; }
.compare .n i, .compare .p i {
display: inline-block;
width: 6pt; /* fixed sign slot, no colour coding */
font-style: normal;
}
.compare thead th { border-bottom: 0.5pt solid currentColor; }
</style>What breaks when it is built the obvious way
Putting the variance at the end of the row after several other columns. The reader then has to hold two figures in their head while their eye travels, which is the arithmetic the block exists to remove. Adjacency is the entire mechanism.
How to prove it survived pagination
Render two periods where one figure grew and one shrank, including one where the change crosses a digit boundary. Cover the variance column and see whether you can still read the direction of change from the two period columns alone. If not, they are not aligned closely enough.
Where it sits in a finished document
This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The multi-page report template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.
Frequently asked
Will this fragment work on its own?
Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.
Why does it look right in a browser and wrong in the PDF?
Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.
Do I need a special option on the render request for this?
No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.
Other parts of a document
The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.
A schedule of rates with units that stay attached to their prices
A price list keyed by activity and unit of measure, referred to from elsewhere in the document rather than totalled at the bottom.
A row of headline figures that survives a narrow page
Three to five headline numbers across the top of a report, each with a label, giving the summary before the detail.
A quantity price break table where the bands cannot be misread
Prices that change with quantity, printed as bands, where the boundary between one band and the next is the thing that gets read wrong.
An address block with no blank lines where a field was empty
Name, street, locality, postcode and country, set as a block, where any of the middle lines may be absent for a given record and none of the gaps should show.
Multi-page report, as a complete file
The whole document with this block already in place, ready to copy and change.
font-variant-numeric in paged output
The property carrying the weight here, with its real support status.
Every part of a document
The full list, grouped by the kind of problem the block poses.
Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.