groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] background shading using tbl


From: Ted Harding
Subject: Re: [Groff] background shading using tbl
Date: Sat, 03 Jul 2010 17:51:44 +0100 (BST)

On 03-Jul-10 06:06:42, Werner LEMBERG wrote:
>> I hope to create a school directory of about 1,000 students using
>> groff.  I have close to what I want using the tbl processor, but
>> hope to alternate shading between rows: white/grey/white/...
>> 
>> Is there a way to do this?
> 
> There are two possibilities for shaded table cells:
> 
>   . The hdtbl macro package; the examples show a lot of shaded boxes.
>     However, this works for PS output only.
> 
>   . Regarding direct tbl support, you might have a look at this
>     thread:
> 
>       http://lists.gnu.org/archive/html/groff/2006-06/msg00025.html
> 
>     Unfortunately, Gaius stopped working on improving his patch so I
>     wasn't able to add his changes to the groff source tree.
> 
> I believe that those approaches don't work for you since both methods
> specify the table cell colour in advance, while you need it specified
> dynamically.
> 
> I think you have to use manual macro trickery:
> 
>   . flip the colour
>   . write the next line (or whatever) to a diversion to get its
>     dimensions
>   . write a background rectangle with \D'P ...', using the colour set
>     with \M and the dimension of the stored diversion.  Some sample
>     code can be found in the info manual under the description for
>     \D'P ...'.
>   . output the diversion
> 
>     Werner

For a simple table, it is possible to do the job requested (at any
rate adequately) by fairly simple means. The following gives an
example. It is based on the assumption that each line of the table
will be a single line of printed text, with no upwards or downwards
excursions in a subset of the lines (if there are such, equally
in all lines, then you would have to adjust the dimensions of the
vartical shifts and in the "\D'P ... '" command). This assumption
probably matches the context of Andrew's requirement.

The idea is that, at the first table entry in the line (assumed
to be left-justified: "l"), a zero-displacement drawing command
"\D'P ... " draws a filled box over the entire table line. The
shade of grey is set by the "\Z'\D'f 250''" ("\Z'...'" to prevent
it generating a displacement). The table entries are then printed
on top of the grey box.

The same example is shown in three table contexts:
A: No box or horizontal lines.
B: The entire table has a box round it.
C: There is a box, and horizontal rules to separate the lines.
As it happens, the same setup works for all three cases. You may
need to test this out in your own case.

The code uses two of the registers defined in the output of 'tbl':
1: \n[TW], the table width. In Case A, this is defined in terms
of the start-points of the text in the table and the end-points
of the text. Since there is no surrounding box, the table width
does not extend beyond the text. When there is a surrounding box,
the TW is the distance from the left-hand vertical rule to the
right-hand one.
2: \n[3cl0], the amount of padding which 'tbl' puts on either
side when there is a box round the table (or vertical rules on
either side); this has value 0 in Case A.
These are combined so that the drawing of the grey box starts
at a displacement "-\\n[3cl0]u" to the left of the start of text,
and extends over a width \n[TW] to the right, so that it exactly
fills the table width.

The vertical displacements embodied in the code were determined
empirically. Unfortunately, 'tbl' does not seem to create any
register whose value os the height of the current table line:
all vertical displacements are calculated in terms of absolute
motion from the top of the table!

I have defined two strings:

.ds shd0  \" Which is blank, so does nothing, hence "white" line
.ds shd1  \" Which draws the shaded box, hence "grey-shaded" line

I have put them alternately at the starts of the successive lines
of the table. You could simply ignore "shd0", or devise a trick
whereby an initial "\*[shdn]" (say) becomes alrenately "\*[shd1]"
and "\*[shd0]".

Here are the examples:

\Z'\D'f 250''
.ds shd0
.ds shd1 \Z'\v'0.2750v'\h'-\\n[3cl0]u'\
\D'P \\n[TW]u 0 0 -1.050v -\\n[TW]u 0 0 1.050v''
.TS
tab(#);
l l l.
\*[shd1]Andy Armstrong#Class 1A#Sciences
\*[shd0]Alan Beamish#Class 1B#Arts and Humanities
\*[shd1]Brian Aldwych#Class 2A#Media Skills
\*[shd0]Beowulf Budweiser#Class 2B#Brewing and Biochemistry
\*[shd1]Charlie Dimmock#Class 3D#Self-Support
.TE
.sp
.\".ds shd1 \Z'\v'0.2750v'\h'-\\n[3cl0]u'\
.\"\D'P \\n[TW]u 0 0 -1.050v -\\n[TW]u 0 0 1.050v''
.TS
box tab(#);
l l l.
\*[shd1]Andy Armstrong#Class 1A#Sciences
\*[shd0]Alan Beamish#Class 1B#Arts and Humanities
\*[shd1]Brian Aldwych#Class 2A#Media Skills
\*[shd0]Beowulf Budweiser#Class 2B#Brewing and Biochemistry
\*[shd1]Charlie Dimmock#Class 3D#Self-Support
.TE
.sp
.\".ds shd1 \Z'\v'0.2750v'\h'-\\n[3cl0]u'\
.\"\D'P \\n[TW]u 0 0 -1.050v -\\n[TW]u 0 0 1.050v''
.TS
box tab(#);
l l l.
\*[shd1]Andy Armstrong#Class 1A#Sciences
_
\*[shd0]Alan Beamish#Class 1B#Arts and Humanities
_
\*[shd1]Brian Aldwych#Class 2A#Media Skills
_
\*[shd0]Beowulf Budweiser#Class 2B#Brewing and Biochemistry
_
\*[shd1]Charlie Dimmock#Class 3D#Self-Support
.TE

=====================================================================
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 03-Jul-10                                       Time: 17:51:40
------------------------------ XFMail ------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]