groff
[Top][All Lists]
Advanced

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

Re: [Groff] tables in a macro


From: Tadziu Hoffmann
Subject: Re: [Groff] tables in a macro
Date: Fri, 16 Jun 2006 17:23:15 +0200
User-agent: Mutt/1.5.11

> I want to have a variable parameter list. At maximum I can
> have up to 10 parameters.  Each parameter opens a new row.
> If the parameter is empty then do not open a new row.

If you can restrict yourself to a simple, particular layout and
don't need the full flexibility of a general table formatting
package, it's not too hard to write the appropriate code
yourself.  Here's an example:


.\" eqn
.\" ----------------------------------------------------------------
.\" Simple two-column table with one to three lines.
.\" First column is centered with predefined text (fooooo, bar, baz).
.\" Second column is right-aligned with text given by arguments.
.de T
.\" -------- find maximum column widths
.nr T1 0
.nr T2 0
.Tw fooooo "\\$1"
.if \\n(.$>1 .Tw bar "\\$2"
.if \\n(.$>2 .Tw baz "\\$3"
.nr T1 +\w'  '
.nr T2 +\w'  '
.\" -------- set up alignment fields
.nr T0 \\n(T1u+\\n(T2u
.ta \\n(T1u +\\n(T2u
.fc # ^
.\" -------- format table into diversion to find height
.in 0
.nf
.di Td
.HR
#^fooooo^##^\\$1 #
.if \\n(.$>1 \{ .HR
#^bar^##^\\$2 # \}
.if \\n(.$>2 \{ .HR
#^baz^##^\\$3 # \}
.HR \c
\D'l 0 |0'\c
\h'-\\n(T2u'\D'l 0 \\n(.hu'\c
\h'-\\n(T1u'\D'l 0 |0'
.br
.di
.fc
.in
.\" -------- output the finished table
.nf
.in +(\\n(.lu-\\n(.iu-\\n(dlu)/2u
.ne \\n(dnu
.Td
.in
.fi
..
.\" ----------------------------------------------------------------
.\" memorize maximum column width
.de Tw
.nr T1 \\n(T1>?\w'\\$1'
.nr T2 \\n(T2>?\w'\\$2'
..
.\" ----------------------------------------------------------------
.\" horizontal rule
.de HR
\v'-.25m'\D'l \\n(T0u 0'\\$1
..
.\" ----------------------------------------------------------------
.ll 5c
.sp 3c
Here is a simple two-column table with the first
column centered and the second column right-aligned.
.T 5 777 100000
It even works with eqn-processed material:
.EQ
delim $$
.EN
.T "$exp ( x ) = sum from {i^=^0} to inf {x sup i over i!}$" "${355 over 113}$"
.\" ----------------------------------------------------------------






reply via email to

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