Projekt

Allgemein

Profil

Aktionen

Tables

For table rendering, we use htmltabs (link to repository) developed by Patrick Schulz rather than other table packages known from TeX.

Include htmltabs

Add this line to the preamble

\usepackage{htmltabs}

Table Markup

Mapping XHTML -> LaTeX

The htmltabs markup reflects the structure of a HTML table.

XML TeX Description
<table>…</table> \begin{htmltab}[…] … \end{htmltab}
<col /> \HTcol[…] vor thead
<colgroup>…</colgroup> \HTcolgroup[…]{…} before thead
<thead>…</thead> \begin{thead}[…] … \end{thead} after tbody
<tfoot>…</tfoot> \begin{tfoot}[…] … \end{tfoot} after tbody, before thead
<tbody>…</tbody> \begin{tbody}[…] … \end{tbody}
<tr>…</tr> \HTtr[…]{…}
<td>…</td> \HTtd[…]{…}
<th>…</th> \HTth[…]{…}

It is important that the grid is kept: for x columns and y rows (taking into account colspan and rowspan) there must be x × y cells.

Attributes and CSS Properties

The following "attributes" can be included in the optional argument (if empty, omit) of all "elements":
  • style={} contains CSS property-value pairs, syntax within the curly braces is as in XML, e.g.
\HTtd[style={<CSS-Eigenschaft-1>:<CSS-Wert-1>; <CSS-Eigenschaft-2>: <CSS-Wert-2>; … }]{<Inhalt>}

The CSS properties in the HTML can be transferred directly to TeX. The same applies to the environments:

\begin{htmltab}[style={<CSS-Eigenschaft-1>:<CSS-Wert-1>; <CSS-Eigenschaft-2>: <CSS-Wert-2>; … }]
  …
Currently implemented CSS properties:
  • margin, with or without -top, -left, -right, -bottom: length
  • padding, with or without -top, -left, -right, -bottom: length
  • border, with or without -top, -left, -right, -bottom; with or without -width, -style, -color
    • if -width/-style/-color and -top/-left/-right/-bottom is omitted:
      • one value: style
      • two values: width style
      • three values: width style color. Applies to all sides of the element.
  • border-style: solid, dashed, dotted, none, double
  • border-color: TeX color name (needs to be defined first with \definecolor{<name>}{<color-space>}{<color-declaration>}) or hex value \#rrggbb
  • border-width: length
    If there is no side with -top/-left/-right/-bottom given, several values are possible:
    • if there is one value it applies to all sides
    • two values: top/bottom and left/right
    • three values: top and left/right and bottom
    • four values: top and right and bottom and left
  • border-collapse: none, collapse
  • vertical-align: top, middle, bottom
  • background-color: Hintergrundfarbe. TeX color name or hex value \#rrggbb
  • color: text color. TeX color name or hex value \#rrggbb
  • font-size: font size. xx-small, x-small, small, normal, large, x-large, xx-large
  • font-weight: font weight. bold, normal
  • font-family: font family. use values for generic font-families, e.g. sans-serif, serif, monospace
  • font-style: font style: normal, italic
  • font-variant: font variant: normal, small-caps
  • text-align: right, center, left, justified
  • hyphen: none (no hyphenation), auto (TeX-hyphenation)
  • class=<name> corresponds to the class attribute in HTML.
  • the \HTcol-Element can yield a width attribute with a given column width, e.g.
    \col[width=20mm,style={text-align: center}]
    \col[width=0.2,style={text-align:justified,hyphen=auto}]

    The first column would have a fixed width of 20mm, the second a relative width of 20% of the width of the entire table.
    The first column is centered, the second is justified with activated hyphenation. Permissible values for column widths are:
    • Length (number and measurement unit) for fixed with columns,
    • Number <= 1 for relative width (0.5 is half of the table width)
    • Number > 1 Anteile auf Gesamtsumme bezogen, e.g. three columns with width=20, width=10 and width=30 mean, that the first is one third of the total width (20/60), the secnd is a sixth (10/60) and the third is a half (30/60) of the total width.
  • Htmltab can also have width, this would then correspond to the total width of the table. If this information is missing, the table is set in its original width, but at most the width of the type area (more precisely: \linewidth).
  • \HTtd and \HTth may contain rowspan and colspan-attributes. They should include an integer.
    \HTtd[rowspan=2,colspan=2,style={vertical-align: middle; text-align: center}]{<content>}

    This cell would be stretched over two columns and two rows, its contents would be centered vertically and horizontally.

Example:

\begin{htmltab}[class=box]
  \begin{thead}
    \HTtr[style={text-align: center}]{%
       \HTtd[style={text-align: center; vertical-align: bottom}]{<Table head column 1>}
       \HTtd{<Table head column 2>}
       \HTtd{<Table head column 3>}
    }
  \end{thead}
  \begin{tfoot}
    \HTtr[colspan=3]{%
       \HTtd{<Table foot column 1–3>}
    }
  \end{tfoot}
  \begin{tbody}
    \HTtr{%
       \HTtd[rowspan=2]{<Table body row  1-2 column 1>}
       \HTtd{<Table body row   1 column 2>}
       \HTtd{<Table body row  1 column 3>}
    }
    \HTtr{%
       \HTtd{<Table body row  2 column 2>}
       \HTtd{<Table body row  2 column 3>}
    }
    \HTtr{%
       \HTtd{<Table body row  3 column 1>}
       \HTtd{<Table body row  3 column 2>}
       \HTtd{<Table body row  3 column 3>}
    }
  \end{tbody}
\end{htmltab}

Overridable properties and baretabular class

  • Certain CSS properties are not transferred to TeX by default, as these could possibly overwrite the publisher's specifications for table layouts:
    **width on all elements that are not <col>, <colgroup>, or <table>
    • further properties can be configured in the publisher style (e.g. background-color in <thead>, padding-* an td, etc.)
  • the baretabular-Klasse is a special case: If <table> has this class, all CSS properties are effective

Caption, Source and Floating

htmltabs corresponds to the tabular environment in default LaTeX.

The markup of caption, number, source and legend corresponds to tpFigure:

\begin{tpTable}[<Floatpos>]
  \tpCaption{<Caption>}
  \tpSource{<Quelle>}
  \tpLegend{<Legende>}
  \tpNumber{<Zähler>}
  \begin{htmltab}
    …
  \end{htmltab}
\end{tpTable}
  • <Floatpos> represents the TeX float position (t,p,h,b; please see tpFigure)
    • if the optional argument is missing, the table is placed at the location in the content
  • Please note that the table can only be continued over pages, if it's not floating. This means if it is not wrapped in a tpTable environment or if tpTable exists but without optional argument.

Rotated Tables

Markup in Word

In order for a table to be rotated by 90 degrees, either the text direction of the first cell must be rotated in Word or an empty paragraph with the table_rotated paragraph style must appear in front of the table.

Markup in LaTeX

In TeX the table is marked with the attribute orientation="landscape" in the optional argument e.g.

\begin{tpTable*}[orientation="landscape"]
…
\end{tpTable*}

The specification of float-pos is always overwritten with "p", so the attribute can (and should) be omitted for rotated tables. This works the same way with figures.

Continue tables over several pages

In order to continue tables over several pages (with a repeating table header), the table must be preceded by an empty paragraph with the paragraph style table_pagewrap.

Von Martin Kraetke vor mehr als 2 Jahren aktualisiert · 5 Revisionen