4.9 KiB
@slide(layout=chapter-slide)
@number 10
@title Tables
@slide(layout=content-only)
@title Basic structure 🗒️
@content
For typographically pleasing tables, we use the booktabs package.
\usepackage{booktabs}
\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
\begin{tabular}{lrcl}
% table content
\end{tabular}
| letter | meaning |
|---|---|
| l | left-justified column |
| c | centred column |
| r | right-justified column |
++ Vertical separator lines and double horizontal lines are frowned upon by typographers and should be avoided.
@slide(layout=content-and-preview)
@title Table content
@content
\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,\midruleand\bottomrulestructure the table.
@slide(layout=wide-content)
@title The entire table
@content
\begin{table}[h]
\begin{tabular}{lrcl}
\toprule
Language & Author & Year & Filename extension \\
\midrule
C++ & Bjarne Stroustrup & 1985 & .cpp \\
Java & James Gosling & 1998 & .java \\
Python & Guido van Rossum & 1991 & .py \\
\bottomrule
\end{tabular}
\caption{Well-known programming languages}
\end{table}
`@{}` to the left and right of a column definition removes the padding of the corresponding column.
`\begin{tabular}{@{}lrcl@{}}` limits the row separators to the width of the table content
@slide(layout=content-only)
@title More comfort
@content The Tables Generator is a wonderful tool to quickly create tables of different formats.
@slide(layout=task)
@task-number 10
@title Typesetting tables
@content
- The list in file
exercises/tables/tables.texstores information on a few modules of the WIAI faculty. - Transform the list into a table.
- The table shall have colums for the name, the abbreviation (Kürzel) and the semester of the lectures.
- Add a column with center-aligned text on the left side of the table in order to number the lectures.
- Add a caption for the table.
@slide(layout=extra-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:
\usepackage{longtable}
\begin{longtable}{<column definition>}
% table content
\caption{<caption>}
\label{<label>}
\end{longtable}
@slide(layout=extra-content-only)
@title
Notes on longtable
@content
\begin{longtable}{<column definition>}
% table content
\caption{<caption>}
\label{<label>}
\end{longtable}
- The
longtableenvironment merges thetabularandtableenvironments. - Caption and label can therefore be inserted directly under the table content.
- As long as the
booktabspackage is used, its features are also provided inlongtable.
@slide(layout=extra-content-only)
@title Particularly wide tables
@content If you need a table to be wider than a page, you can display it in landscape orientation:
\usepackage{rotating}
\begin{sidewaystable}[<position>]
\begin{tabular}{<column def.>}
% table content
\end{tabular}
\end{sidewaystable}
@slide(layout=extra-content-and-preview)
@title An advanced example
@content
\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}(n)$ \\
AVL tree & $\mathcal{O}(log(n))$ & $\mathcal{O}(log(n))$ \\
\bottomrule
\end{tabular}
\end{table}
