4.3 Líneas y columnas

We now present a few packages that help in manipulating the text stream in its entirety. The first package (lineno) deals with attaching line numbers to paragraphs, supporting automatic references to them. This can be useful in critical editions and other scholarly works.

The second package (paracol) deals with the problem of presenting two text streams side by side— for example, some original and its translation. We show how both packages can be combined in standard cases.

The third package (multicol) deals with layouts having multiple columns. It allows switching between different numbers of columns on the same page and supports balancing textual data. Standard LaTEX already offers the possibility of typesetting text in one- or two-column mode, but one- and two-column output cannot be mixed on the same page.

We finish the section with a short example of the multicolrule package that allows you to define customized “rules” to appear between columns on the page.

4.3.1 lineno - Numeración de líneas de texto

In certain applications it is useful or even necessary to number the lines of paragraphs to be able to refer to them. As TEX optimizes the line breaking over the whole paragraph, it is ill equipped to provide such a facility, because technically line breaking happens at a very late stage during the processing, just before the final pages are constructed. At that point macro processing, which could add the right line number or handle automatic references, has already taken place. Hence, the only ways to achieve line numbering is either by not doing line breaking (as in the case of fancyvrb and similar packages) or by deconstructing the completed page line by line in the “output routine” (i.e., the part of LaTEX that normally breaks the paragraph galley into pages and adds running headers and footers) and attaching the appropriate line numbers at that stage.

The latter approach was taken by Stephan Böttcher in his lineno package (for a number of years maintained by Uwe Lück (1962–2020) and since 2022 maintained by Karl Wette). Although one would expect such an undertaking to work only in a restricted environment, his package is surprisingly robust and works seamlessly with many other packages — even those that modify the LaTEX output routine, such as ftnright, multicol, and wrapfig. It also supports layouts produced with the twocolumn option of the standard LaTEX classes.

4.3.2 paracol - Varios flujos de texto alineados

Sometimes it is necessary to typeset something in parallel columns, for example, when presenting some text and its translation. Parallel in this context means that at certain synchronization points the two text streams are vertically (re)aligned. This type of layout is normally not supported by LaTEX (which by default works with only a single text stream), but it can be achieved by using NAKASHIMA Hiroshi’s paracol package.

4.3.3 multicol - Una forma flexible de manejar múltiples columnas

With standard LaTEX it is possible to produce documents with one or two columns (using the class option twocolumn). However, it is impossible to produce only parts of a page in two-column format because the commands and always start a fresh page. Additionally, the columns are never balanced, which sometimes results in a slightly weird distribution of the material.

The multicol package1 by Frank Mittelbach solves these problems by defining an environment, multicols, with the following properties:

  • Support is provided for 2–20 columns, which can run for several pages.
  • When the environment ends, the columns on the last page are balanced so that they are all of nearly equal length with a number of customization possibilities to influence the outcome. This balancing can be suppressed by using the starred form of the environment.
  • The environment can be used inside other environments, such as figure or minipage, where it produces a box containing the text distributed into the requested number of columns. Thus, you no longer need to hand-format your layout in such cases.
  • Alternative code execution based on the current column (left, right, or one of the middle ones) is possible.
  • Between individual columns, vertical rules of user-defined widths and color can be inserted.
  • The formatting can be customized globally or for individual environments.

4.3.4 multicolrule - Reglas personalizadas para páginas de varias columnas

A fairly recent addition to the LaTEX ecosystem is the multicolrule package by Karl Hagen, which makes use of the L3 programming layer. Its sole purpose is to provide customized rules to be placed between columns generated by multicol or by the twocolumn class option offered by most document classes.

The customization possibilities are huge, so we give only one example here. Some designs make use of additional packages, e.g., our example uses tikz and pgfornament, but there are also many possibilities that work without the need to add powerful graphic packages such as tikz.