[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: vertical centering of text in tbl rows
From: |
Werner LEMBERG |
Subject: |
Re: vertical centering of text in tbl rows |
Date: |
Wed, 27 Jan 2010 15:42:56 +0100 (CET) |
> So what would be the way to get numbers to be properly vertically
> centered with groff? Tables like my file1 are very common.
Sorry for the late reply.
Here's an ASCII picture which shows the relationship between the base
line, the height, and the depth of a glyph.
---------------------------------- previous base line
^
+---------+
| | \n[.v]
| |
| |\n[rst]
| |
| | V
------+---------+----------------- current base line
| |\n[rsb]
+---------+
To center the glyph vertically between the current and the previous
base line, we calculate
\n[rsb] - (\n[.v] - (\n[rst] - \n[rsb])) / 2
= \n[rsb] - (\n[.v] - \n[rst] + \n[rsb]) / 2
= \n[rsb] - \n[.v]/2 + \n[rst]/2 - \n[rsb]/2
= (\n[rsb] + \n[rst] -\n[.v]) / 2
(note that `rsb' is negative for values below the baseline). Finally,
for your example, we have to correct the offset for the vertical space
reserved for the top and bottom line.
Using groff's `string macro' feature, we can write it like the stuff
below.
Werner
======================================================================
.ps 12
.vs 14
.nf
.
.
.ds CV \
\v'((\w'\\$1'u * 0) \
+ (((\\n[rsb]u + \\n[rst]u - \\n[.v]u)) / 2u) \
+ ((\\n[.v]u - \\n[.s]p) * 2u))'\
\\$1\
\v'((\w'\\$1'u * 0) \
- (((\\n[rsb]u + \\n[rst]u - \\n[.v]u)) / 2u) \
- ((\\n[.v]u - \\n[.s]p) * 2u))'
.
.
.vs (\n[.v]u - \n[.s]p)
\l'1i\[ul]'
.vs \n[3g]u
\*[CV "12345"]
.vs (\n[.v]u - \n[.s]p)
\l'1i\[ul]'
.vs \n[3g]u