Tables » Historie » Revision 3
« Zurück |
Revision 3/8
(Vergleich)
| Weiter »
Martin Kraetke, 22.12.2021 18:02
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: lengthpadding, with or without-top,-left,-right,-bottom: lengthborder, with or without-top,-left,-right,-bottom; with or without-width,-style,-color- if
-width/-style/-colorand-top/-left/-right/-bottomis omitted:- one value:
style - two values:
width style - three values:
width style color. Applies to all sides of the element.
- one value:
- if
border-style:solid,dashed,dotted,none,doubleborder-color: TeX color name (needs to be defined first with\definecolor{<name>}{<color-space>}{<color-declaration>}) or hex value\#rrggbbborder-width: length
If there is no side with-top/-left/-right/-bottomgiven, several values are possible:- if there is one value it applies to all sides
- two values:
top/bottomandleft/right - three values:
topandleft/rightandbottom - four values:
topandrightandbottomandleft
border-collapse:none,collapsevertical-align:top,middle,bottombackground-color: Hintergrundfarbe. TeX color name or hex value\#rrggbbcolor: text color. TeX color name or hex value\#rrggbbfont-size: font size.xx-small,x-small,small,normal,large,x-large,xx-largefont-weight: font weight.bold,normalfont-family: font family. use values for generic font-families, e.g.sans-serif,serif,monospacefont-style: font style:normal,italicfont-variant: font variant:normal,small-capstext-align:right,center,left,justifiedhyphen:none(no hyphenation),auto(TeX-hyphenation)
class=<name>corresponds to the class attribute in HTML.- the
\HTcol-Element can yield awidthattribute 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=10andwidth=30mean, 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.
Htmltabcan also havewidth, 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).\HTtdand\HTthmay containrowspanandcolspan-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:
**widthon all elements that are not<col>,<colgroup>, or<table>- further properties can be configured in the publisher style (e.g.
background-colorin<thead>,padding-*antd, etc.)
- further properties can be configured in the publisher style (e.g.
- 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
tpTableenvironment or iftpTableexists 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.
Tabellen auf mehrere Seiten umbrechen¶
Um Tabellen auf mehrere Seiten (mit sich wiederholendem Tabellenkopf zu umbrechen, muss der Tabelle ein leerer Absatz mit dem Absatzformat table_pagewrap vorangestellt werden.
Von Martin Kraetke vor fast 4 Jahren aktualisiert · 3 Revisionen