PDFPipe

Numbers, tables and totals / Running balance column

A running balance column that stays readable over many pages

A column on a transaction table showing the balance after each movement, which turns a list of events into something a reader can audit line by line.

Why this block is harder than it looks

A running balance is dense: four columns of digits, most of them similar, repeated for a hundred rows. Typographic failures that are tolerable elsewhere become reading failures here. Proportional digits make the column edge ragged so the eye loses its place. Uniform row shading is unreadable in monochrome. A balance that goes negative and back changes width because of the sign, and if the sign sits inside the right-aligned block every negative row shifts by a character. And unlike a line-item table there is no natural grouping, so a reader crossing a page boundary has nothing to anchor to.

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.

  • Tabular figures on every numeric column, without exception. Not a preference here: it is the difference between a scannable column and a wall.
  • Put the sign in its own fixed-width slot to the left of the digits so the digits never shift.
  • Use hairline rules every five rows rather than alternating background bands. Bands depend on backgrounds printing, rules do not, and at five-row intervals the eye tracks across without the page looking striped.
  • Repeat the column headers on every page, and repeat the opening balance as a brought-forward row so the first balance on a page is derivable from something visible on that page.
  • Keep the date column narrow and its format fixed width. A mixture of 4 Mar and 14 Mar in a left-aligned column makes the detail column start in two different places.
  • Right-align debit, credit and balance onto the same edge grid so the three read as three columns rather than three ragged blocks.

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.

html
<table class="balance">
  <thead>
    <tr>
      <th class="date">Date</th><th>Detail</th>
      <th class="num">Debit</th><th class="num">Credit</th><th class="num">Balance</th>
    </tr>
  </thead>
  <tbody>
    <tr><td class="date">04 Mar</td><td>Invoice 2026-118</td>
        <td class="num">1,240.00</td><td class="num"></td>
        <td class="num"><i class="sign"></i>13,720.00</td></tr>
    <tr><td class="date">09 Mar</td><td>Payment received</td>
        <td class="num"></td><td class="num">2,000.00</td>
        <td class="num"><i class="sign"></i>11,720.00</td></tr>
  </tbody>
</table>

<style>
  .balance {
    width: 100%; border-collapse: collapse;
    table-layout: fixed; font-size: 9pt;
  }
  .balance thead { display: table-header-group; }
  .balance tr { break-inside: avoid; }
  .balance td, .balance th { padding: 3pt 4pt; }
  .balance .date { width: 12%; white-space: nowrap; }
  .balance .num  {
    width: 16%;
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  .balance .sign { display: inline-block; width: 6pt; font-style: normal; }
  /* a hairline every fifth row, instead of shaded bands */
  .balance tbody tr:nth-child(5n) td { border-bottom: 0.4pt solid #bbb; }
</style>

What breaks when it is built the obvious way

Zebra striping with a background colour. It is the default answer for a dense table on screen and it fails twice on paper: print backgrounds are frequently disabled, and where they are not, a hundred rows of alternating grey is heavier than the type it was meant to help.

How to prove it survived pagination

Render two hundred rows with at least one negative balance and one balance that gains a digit. Look along the right edge of the balance column from a shallow angle: it should be perfectly straight. Any waver means either a proportional figure or a sign inside the aligned block.

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 statement of account 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.

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.