Tables » Historie » Revision 2
« Zurück |
Revision 2/5
(Vergleich)
| Weiter »
Martin Kraetke, 22.12.2021 17:58
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/-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.
- one value:
- if
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
andleft/right
- three values:
top
andleft/right
andbottom
- four values:
top
andright
andbottom
andleft
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 awidth
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
andwidth=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 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
).\HTtd
and\HTth
may containrowspan
andcolspan
-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-*
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
tpTable
environment or iftpTable
exists but without optional argument.
Gedrehte Tabellen¶
Auszeichnung in Word¶
Damit eine Tabelle um 90 Grad gedreht wird, muss entweder in Word die Textrichtung der ersten Zelle gedreht werden oder vor der Tabelle ein leerer Absatz mit dem Absatzformat table_rotated
stehen.
Auszeichnung in LaTeX¶
Im TeX wird das ganze mit dem Attribut orientation="landscape"
im optionalen Argument der Gleitungebung gekennzeichnet, z.B.
\begin{tpTable*}[orientation="landscape"]
…
\end{tpTable*}
Die Angabe von float-pos wird dabei immer mit "p" überschrieben, demnach kann (und sollte) das Attribut bei gedrehten Tabellen entfallen. Dasselbe funktioniert genau so auch mit Bildern.
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 3 Jahren aktualisiert · 2 Revisionen