grofftbl

tbl with groff/ntoff: borders messed-up when reaching end-of-page


As output for a script, I produce inut for tbl. However, when a table seems to reach an end of page, the borders of a table go all over the place. As an example:

             │            │                │                 │
             │            │                │                 │
             │            │                │                 │
             │            │        ‐ 1 ‐   │                 │
             │            │                │                 │
             │            │                │                 │
             │            │                │                 │
       4.  The in3 intermediate data structure               │
             │            │                │                 │
       In3   is   an   intermediate   language.  The  goal  of  the
       intermediate language is to provide all the content  in  the
       right │order,  in  such  a  way  that the output‐filters can

(this is nroff-output). The column-borders conform to table at the bottom of the page.

This mainly seems to happen when a table is fully specified (i.e. for every row, a line is written in the header), for example:

.TS
allbox,center;
l l l
l l l
l l l
l l l
l l l
^ l l
l l l.

I must do this, because I do not know beforehand when two rows need a merged cell (^).

I tried to put in a conditional new page before every table, but that is less obvious than it looks, because a) nroff (text output) and groff (ps-output) do not seem to handle this the same way and b) it is difficult (due to possible multi-line cells) to predict how long a table will be.

I would like a solution that does not force me to begin a new page for every table.


Solution

  • It may be sufficient just to fully specify the table by giving it an explicit table header, which needs to be repeated at the start of the next page after a page split. You may also need to use macros -mm or -ms, which are also doing end-of-page handling, and need to co-operate with tbl and the T# macro it creates for this purpose.

    The format is

    .TS H
    options ;
    format .
    heading
    .TH
    data
    data
    .TE
    

    The heading line above can be omitted, but you still need the .TH and the .TS H.

    I made some tests with groff 1.22.3 and the following example, with a forced page length (.pl) of 14 lines worked well with -mm but not with -ms.

    ( echo .pl 14
      echo .TS H
      echo 'allbox,center;'
      for ((i=1;i<5;i++)); do echo 'l l l'; done
      echo '^ l l'
      for ((i=1;i<5;i++)); do echo 'l l l'; done
      echo 'l l l.'
      echo .TH
      for ((i=1;i<11;i++)); do echo -e 'a\tb\tc';done
      echo .TE
    ) >t
    tbl t | nroff -mm
    

    Here's part of the output, with the blank lines removed:

             - 1 -
    
         +--+---+---+
         |a | b | c |
         +--+---+---+
         |a | b | c |
         +--+---+---+
    
             - 2 -
    
         +--+---+---+
         |a | b | c |
         +--+---+---+
    
             - 3 -
    
         +--+---+---+
         |  | b | c |
         |a +---+---+
         |  | b | c |
         +--+---+---+