234 lines
5.0 KiB
Markdown
234 lines
5.0 KiB
Markdown
@slide(layout=chapter-slide)
|
||
|
||
@title
|
||
Tables
|
||
|
||
|
||
@slide(layout=content-only)
|
||
|
||
@title
|
||
Basic structure <span class="emoji">🗒️</span>
|
||
|
||
@content
|
||
For typographically pleasing tables, we use the `booktabs` package.
|
||
|
||
``` {.hljs .lang-tex}
|
||
\usepackage{booktabs}
|
||
```
|
||
|
||
``` {.hljs .lang-tex}
|
||
\begin{table}[<position>]
|
||
\begin{tabular}{<column definition>}
|
||
% table content
|
||
\end{tabular}
|
||
\caption{<caption>}
|
||
\end{table}
|
||
```
|
||
|
||
Positioning works just like with graphics.
|
||
|
||
|
||
@slide(layout=content-and-preview)
|
||
|
||
@title
|
||
Column definitions
|
||
|
||
@content
|
||
``` {.hljs .lang-tex}
|
||
\begin{tabular}{lrcl}
|
||
% table content
|
||
\end{tabular}
|
||
```
|
||
|
||
<table>
|
||
<tr>
|
||
<th>letter</th>
|
||
<th>meaning</th>
|
||
</tr>
|
||
<tr class="fragment">
|
||
<td>l</td>
|
||
<td>left-justified column</td>
|
||
</tr>
|
||
<tr class="fragment">
|
||
<td>c</td>
|
||
<td>centred column</td>
|
||
</tr>
|
||
<tr class="fragment">
|
||
<td>r</td>
|
||
<td>right-justified column</td>
|
||
</tr>
|
||
</table>
|
||
|
||
++ Vertical separator lines and double horizontal lines are frowned upon by typographers and should be avoided.
|
||
|
||
@preview
|
||
{.thin-padding}
|
||
|
||
|
||
@slide(layout=content-and-preview)
|
||
|
||
@title
|
||
Table content
|
||
|
||
@content
|
||
``` {.hljs .lang-tex}
|
||
\begin{tabular}{lll}
|
||
\toprule
|
||
Column 1 & Column 2 & Column 3 \\
|
||
\midrule
|
||
Content a & Content b & Content c \\
|
||
Content e & Content f & Content g \\
|
||
Content i & Content j & Content k \\
|
||
\bottomrule
|
||
\end{tabular}
|
||
```
|
||
* ++ Columns are separated by ’`&`’.
|
||
* ++ Rows are ended by ‘`\\`’.
|
||
* ++ `\toprule`, `\midrule` and `\bottomrule` structure the table.
|
||
|
||
@preview
|
||
{.thin-padding}
|
||
|
||
|
||
@slide(layout=wide-content)
|
||
|
||
@title
|
||
The entire table
|
||
|
||
@content
|
||
``` {.hljs .lang-tex}
|
||
\begin{table}[h]
|
||
\begin{tabular}{lrcl}
|
||
\toprule
|
||
Language & Author & Year & Version \\
|
||
\midrule
|
||
C++ & Bjarne Stroustrup & 1985 & C++ 17 \\
|
||
Java & James Gosling & 1998 & 13 \\
|
||
Python & Guido van Rossum & 1991 & 3.8.0 \\
|
||
\bottomrule
|
||
\end{tabular}
|
||
\caption{Well-known programming languages}
|
||
\end{table}
|
||
```
|
||
|
||
<p data-category="Note">`@{}` to the left and right of a column definition removes the padding of the corresponding column.</p>
|
||
|
||
<p data-category="Example">`\begin{tabular}{@{}lrcl@{}}` limits the row separators to the width of the table content</p>
|
||
|
||
|
||
@slide(layout=content-only)
|
||
|
||
@title
|
||
Particularly long tables
|
||
|
||
@content
|
||
Tables that exceed one page are simply cut off by `tabular`. A solution is offered by the `longtable` package:
|
||
|
||
``` {.hljs .lang-tex}
|
||
\usepackage{longtable}
|
||
```
|
||
|
||
``` {.hljs .lang-tex}
|
||
\begin{longtable}{<column definition>}
|
||
% table content
|
||
\caption{<caption>}
|
||
\label{<label>}
|
||
\end{longtable}
|
||
```
|
||
|
||
|
||
@slide(layout=content-only)
|
||
|
||
@title
|
||
Notes on `longtable`
|
||
|
||
@content
|
||
``` {.hljs .lang-tex}
|
||
\begin{longtable}{<column definition>}
|
||
% table content
|
||
\caption{<caption>}
|
||
\label{<label>}
|
||
\end{longtable}
|
||
```
|
||
* ++ The `longtable` environment merges the `tabular` and `table` environments.
|
||
* ++ Caption and label can therefore be inserted directly under the table content.
|
||
* ++ As long as the `booktabs` package is used, its features are also provided in `longtable`.
|
||
|
||
|
||
@slide(layout=content-only)
|
||
|
||
@title
|
||
Particularly wide tables
|
||
|
||
@todo
|
||
Gegen sidewaystable aus rotating austauschen
|
||
|
||
@content
|
||
If you need a table to be wider than a page, you can use a page in landscape orientation:
|
||
|
||
``` {.hljs .lang-tex}
|
||
\usepackage{lscape}
|
||
```
|
||
|
||
``` {.hljs .lang-tex}
|
||
\begin{landscape}
|
||
\begin{table}[<position>]
|
||
\begin{tabular}{<column def.>}
|
||
% table content
|
||
\end{tabular}
|
||
\end{table}
|
||
\end{landscape}
|
||
```
|
||
|
||
@slide(layout=content-and-preview)
|
||
|
||
@title
|
||
An advanced example
|
||
|
||
@content
|
||
``` {.hljs .lang-tex}
|
||
\begin{table}[h]
|
||
\begin{tabular}{llr}
|
||
\toprule
|
||
Structure & \multicolumn{2}{l}{Access time complexity} \\ \cmidrule(r){2-3}
|
||
& Average & Worst \\
|
||
\midrule
|
||
Stack & $\mathcal{O}(n)$ & $\mathcal{O}(n)$ \\
|
||
Binary tree & $\mathcal{O}(log(n))$ & $\mathcal{O}(log(n))$ \\
|
||
AVL tree & $\mathcal{O}(log(n))$ & $\mathcal{O}(log(n))$ \\
|
||
\bottomrule
|
||
\end{tabular}
|
||
\end{table}
|
||
```
|
||
|
||
[<span class="emoji">🔗</span> Booktabs documentation](http://packages.oth-regensburg.de/ctan/macros/latex/contrib/booktabs/booktabs.pdf)
|
||
|
||
@preview
|
||
{.thin-padding}
|
||
|
||
|
||
@slide(layout=content-only)
|
||
|
||
@title
|
||
More comfort
|
||
|
||
@content
|
||
The [Tables Generator](https://tablesgenerator.com/) is a wonderful tool to quickly create tables of different formats.
|
||
|
||
[](https://tablesgenerator.com/)
|
||
|
||
|
||
@slide(layout=task)
|
||
|
||
@task-number
|
||
11
|
||
|
||
@title
|
||
Typesetting tables
|
||
|
||
@content
|
||
* Include the files `seitenaufbau.tex` and `schriften.tex`.
|
||
* ++ Table 6 in section 7 illustrates the predefined font sizes. Insert an additional **right-justified column** in which you number the number the sizes consecutively.
|
||
* ++ Add a **table header** separated from the rest of the table by a `\midrule`. The column headings may be something like “no.,” “command,” and “example.”
|
||
|