PDFPipe

Numbers, tables and totals / Unit conversion table

A conversion table that does not imply false precision

Values given in two systems of units side by side, on a datasheet or a specification that will be read in more than one country.

Why this block is harder than it looks

The layout is simple and the trap is arithmetic made visible. A value of 2 inches converted to 50.8 millimetres looks like a measurement accurate to a tenth of a millimetre, which it is not: it is a two-significant-figure value dressed up. Print every converted value to the machine's precision and the table claims accuracy the source does not have, and somebody downstream will machine to it. The layout question is how to show a converted value as a conversion rather than as an independent measurement.

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.

  • Round the converted value to the same number of significant figures as the source, not to a fixed number of decimals.
  • Mark the converted column as converted in the header, so it is read as derived rather than as measured.
  • Set the converted column a shade lighter and slightly smaller, which signals derived without needing a footnote.
  • State the conversion factor once, at the foot, so anybody who needs more precision can recompute rather than trusting the display.
  • Keep the nominal and the actual apart. A nominal 2 inch pipe is not 50.8 millimetres of anything, and printing a conversion of a nominal size is a category error the table should not make.
  • Align both columns on the decimal point with tabular figures, so the differing precisions are visible rather than hidden by right alignment alone.

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="convert">
  <thead>
    <tr><th>Dimension</th><th class="n">Specified</th>
        <th class="n conv">Converted</th></tr>
  </thead>
  <tbody>
    <tr><td>Plate thickness</td><td class="n">2.0 mm</td>
        <td class="n conv">0.079 in</td></tr>
    <tr><td>Sheet width</td><td class="n">1,250 mm</td>
        <td class="n conv">49.2 in</td></tr>
  </tbody>
</table>
<p class="factor">Converted at 1 in = 25.4 mm, rounded to the precision of the
  specified value.</p>

<style>
  .convert { border-collapse: collapse; font-size: 9pt; }
  .convert th, .convert td { padding: 3pt 12pt 3pt 0; }
  .convert .n {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  .convert .conv {
    color: #666;                       /* derived, not measured */
    font-size: 8.5pt;
  }
  .convert thead th { border-bottom: 0.5pt solid currentColor; }
  .factor { margin-top: 4pt; font-size: 8pt; color: #555; }
</style>

What breaks when it is built the obvious way

Printing the converted value to four decimal places because that is what the calculation returned. It reads as a tolerance, it is not one, and on an engineering document somebody will work to it.

How to prove it survived pagination

Take a specified value given to two significant figures and check its converted value carries no more than two. Then ask an engineer to read the converted column and say what tolerance it implies. If the answer is tighter than the source, the rounding is wrong.

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 product datasheet 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.