Move source code listings chapter after graphics and tables.
This commit is contained in:
parent
aa15f951a2
commit
4073b4992b
2
onpoint
2
onpoint
@ -1 +1 @@
|
|||||||
Subproject commit 24119fc714d85a572a09660a5a11953d96ea9a2d
|
Subproject commit 34f46b2328daf35dbff58bddda42657b70a9167b
|
||||||
@ -1,292 +1,110 @@
|
|||||||
@slide(layout=chapter-slide)
|
@slide(layout=chapter-slide)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Quelltext-Listings
|
Grafiken
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Unsere Optionen
|
Grafiken abbilden <span class="emoji">🖼️</span>
|
||||||
|
|
||||||
@content
|
@content
|
||||||
Es gibt zwei verbreitete Wege, Quelltext in LaTeX-Dokumenten zu zeigen.
|
Um Grafiken darzustellen, muss das Paket `graphicx` eingebunden werden.
|
||||||
|
|
||||||
* ++ **`minted`** erstellt **sehr hübsche** Quelltext-Listings, aber es benötigt **etwas mehr Konfiguration** und funktioniert nicht auf allen Betriebssystemen zuverlässig.
|
|
||||||
* ++ **`listings`** ist eine **einfach zu nutzende** (aber nicht so hübsche) Alternative für diejenigen, die Probleme mit `minted` haben.
|
|
||||||
|
|
||||||
++ Die Befehle beider Pakete sind sehr ähnlich.
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview)
|
|
||||||
|
|
||||||
@title
|
|
||||||
Installation <span class="emoji">🖥️</span>
|
|
||||||
|
|
||||||
@content
|
|
||||||
`minted` benötigt die Programmiersprache Python. Nach der **[Installation von Python](https://www.python.org/)** kann das zugehörige Paket **[`Pygments`](http://pygments.org/)** in der Eingabeaufforderung installiert werden durch:
|
|
||||||
|
|
||||||
``` {.lang-sh .hljs}
|
|
||||||
pip install Pygments
|
|
||||||
```
|
|
||||||
|
|
||||||
Anschließend muss das Paket `minted` (oder `listings`) nur noch eingebunden werden:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.lang-tex .hljs}
|
||||||
\usepackage{minted}
|
\begin{figure}
|
||||||
\usepackage{listings}
|
\includegraphics{<dateipfad>}
|
||||||
|
\caption[<kurztitel (abbildungsver-
|
||||||
|
zeichnis)>]{<bildunterschrift>}
|
||||||
|
\end{figure}
|
||||||
```
|
```
|
||||||
|
|
||||||
@preview
|
Bildgröße angeben:
|
||||||
{ .thin-padding }
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
``` {.lang-tex .hljs}
|
||||||
|
\includegraphics[width=0.5\textwidth,
|
||||||
@title
|
height=5cm]{<dateipfad>}
|
||||||
Anpassungen beim Kompilieren
|
```
|
||||||
|
|
||||||
@content
|
|
||||||
<div class="box warning">
|
|
||||||
Um Dokumente mit Quelltext-Listings kompilieren zu können, muss die Flag `--shell-escape` an den Compiler übergeben werden.<br />
|
|
||||||
<strong>Dies ist nur bei vertrauenswürdigen Dokumenten empfehlenswert.</strong>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
In TeXstudio muss diese unter **`Optionen → TeXstudio konfigurieren → Befehle`** (`TeXstudio → Einstellungen` unter macOS) bei PdfLaTeX vor `%.tex` ergänzt werden:
|
|
||||||
|
|
||||||
<code>pdflatex -synctex=1 -interaction=nonstopmode **\-\-shell-escape** %.tex</code>
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Ein Hinweis zu unserem Skript
|
Positionierung auf der Seite
|
||||||
|
|
||||||
@content
|
@content
|
||||||
Unsere Übungsmaterialien erlauben es, zwischen `minted` und `listings` zu wählen.
|
|
||||||
Von Haus aus nutzen wir `listings`.
|
|
||||||
Um `minted` zu aktivieren muss eine Datei namens `listings-mode.tex` mit dem folgenden Inhalt im Wurzelverzeichnis unseres Projekts erstellt werden:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.lang-tex .hljs}
|
||||||
\newcommand\listingsmode{minted}
|
\begin{figure}[<positionskürzel>]
|
||||||
```
|
```
|
||||||
|
|
||||||
Kompiliert erneut und die Listings sollten durch `minted` erstellt worden sein.
|
LaTeX positioniert Grafiken automatisch. Durch Kürzel können wir unsere Präferenzen (auch in Kombination) angeben.
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview-with-category)
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th style="min-width:4em">Kürzel</th>
|
||||||
|
<th>Position</th>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>h</td>
|
||||||
|
<td>hier, wenn es dir recht ist</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>t</td>
|
||||||
|
<td>oberer Seitenrand (top)</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>b</td>
|
||||||
|
<td>unterer Seitenrand (bottom)</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>p</td>
|
||||||
|
<td>auf einer eigenen Seite (page)</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>H</td>
|
||||||
|
<td>Hier, verdammt noch mal! <br />(benötigt Paket `float`)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
@category
|
|
||||||
minted
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Code im LaTeX-Quelltext
|
Zentrierte Anordnung
|
||||||
|
|
||||||
@content
|
@content
|
||||||
++ In einer eigenen Umgebung:
|
``` {.lang-tex .hljs}
|
||||||
|
\begin{figure}[<position>]
|
||||||
``` {.lang-tex .hljs .fragment}
|
\begin{center}
|
||||||
\section*{Haskell-Magie}
|
\includegraphics{<dateipfad>}
|
||||||
Quadrate aller geraden % …
|
\end{center}
|
||||||
\begin{minted}{haskell}
|
\end{figure}
|
||||||
[x^2 | x <- [1..200], even x]
|
|
||||||
\end{minted}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
++ Inline im Quelltext:
|
Alternativ:
|
||||||
|
|
||||||
``` {.lang-tex .hljs .fragment}
|
|
||||||
\section*{Ein HTML-Beispiel}
|
|
||||||
Eine Überschrift wird so ausgezeichnet:
|
|
||||||
\mint{html}|<h2>LaTeX im Studium</h2>|.
|
|
||||||
```
|
|
||||||
|
|
||||||
@preview
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
minted
|
|
||||||
|
|
||||||
@title
|
|
||||||
Externer Code
|
|
||||||
|
|
||||||
@content
|
|
||||||
Um Redundanz zu vermeiden, ist es manchmal praktisch, den Quelltext direkt aus der Quelldatei einzulesen.
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.lang-tex .hljs}
|
||||||
\section*{Einfache Java-Anwendung}
|
\begin{figure}[<position>]
|
||||||
\inputminted{java}{Test.java}
|
\centering
|
||||||
|
\includegraphics{<dateipfad>}
|
||||||
|
\end{figure}
|
||||||
```
|
```
|
||||||
|
|
||||||
``` {.lang-java .hljs data-sourcefile="Test.java"}
|
|
||||||
public class Test {
|
|
||||||
public static void main(/*…*/) {
|
|
||||||
System.out.println(/*…*/);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
@preview
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
minted
|
|
||||||
|
|
||||||
@title
|
|
||||||
Themen und Stile
|
|
||||||
|
|
||||||
@content
|
|
||||||
Durch optionale Parameter können Zeilennummerierung, Umbrüche und Farben ausgewählt werden. Außerdem sind zahlreiche Themes verfügbar.
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
|
||||||
\usemintedstyle{monokai}
|
|
||||||
\begin{minted}[
|
|
||||||
linenos=true,
|
|
||||||
breaklines=true,
|
|
||||||
]{javascript}
|
|
||||||
% ...
|
|
||||||
\end{minted}
|
|
||||||
```
|
|
||||||
|
|
||||||
<span class="emoji">🔗</span> **[Einführung](https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted)** und **[offizielle Dokumentation](https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf)**
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
listings
|
|
||||||
|
|
||||||
@title
|
|
||||||
Code im LaTeX-Quelltext
|
|
||||||
|
|
||||||
@content
|
|
||||||
In einer eigenen Umgebung:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
|
||||||
\section*{Haskell-Magie}
|
|
||||||
Quadrate aller geraden % …
|
|
||||||
\begin{lstlisting}[language=Haskell]
|
|
||||||
[x^2 | x <- [1..200], even x]
|
|
||||||
\end{lstlisting}
|
|
||||||
```
|
|
||||||
|
|
||||||
Das Paket `listings` stellt keinen Befehl für inline-Listings zur Verfügung.
|
|
||||||
|
|
||||||
@preview
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
listings
|
|
||||||
|
|
||||||
@title
|
|
||||||
Externer Code
|
|
||||||
|
|
||||||
@content
|
|
||||||
Praktischerweise bietet auch `listings` einen Befehl zum Einfügen externen Codes:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
|
||||||
\section*{Einfache Java-Anwendung}
|
|
||||||
\lstinputlisting[language=Java]{Test.java}
|
|
||||||
```
|
|
||||||
|
|
||||||
``` {.lang-java .hljs data-sourcefile="Test.java"}
|
|
||||||
public class Test {
|
|
||||||
public static void main(/*…*/) {
|
|
||||||
System.out.println(/*…*/);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
@preview
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
listings
|
|
||||||
|
|
||||||
@title
|
|
||||||
Themen und Stile
|
|
||||||
|
|
||||||
@content
|
|
||||||
`listings` stellt keine eigenen Themes zur Verfügung. Dies kann aber durch die vielen Konfigurationsoptionen ausgeglichen werden.
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
|
||||||
\begin{lstlisting}[
|
|
||||||
language=Java,
|
|
||||||
basicstyle=\footnotesize\ttfamily,
|
|
||||||
breaklines=true,
|
|
||||||
keywordstyle=\color{ForestGreen},
|
|
||||||
commentstyle=\color{DarkGray},
|
|
||||||
literate={ö}{{\"o}}1
|
|
||||||
]
|
|
||||||
% …
|
|
||||||
\end{lstlisting}
|
|
||||||
```
|
|
||||||
|
|
||||||
Für die Erstellung eigener Themes ist der Befehl `\lstset` nützlich.
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
listings
|
|
||||||
|
|
||||||
@title
|
|
||||||
Weitere Materialien
|
|
||||||
|
|
||||||
@content
|
|
||||||
* [Einführung](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide) in das Paket
|
|
||||||
* offizielle [Dokumentation](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide)
|
|
||||||
* das Paket [`xcolor`](https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX) für Farben
|
|
||||||
* zwei [Themes](https://github.com/jez/latex-solarized) im solarized-Stil für `listings`
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=task)
|
@slide(layout=task)
|
||||||
|
|
||||||
@task-number
|
@task-number
|
||||||
10
|
11
|
||||||
|
|
||||||
@title
|
@title
|
||||||
`minted`
|
Grafiken einfügen
|
||||||
|
|
||||||
@content
|
@content
|
||||||
* Im Ordner `exercises/source-code-listings` findet ihr eine Datei namens `Source.java`.
|
* Im Ordner `exercises/graphics` findet ihr eine Bilddatei namens `latex-logo.png`.
|
||||||
* **Bindet** den Java-Quelltext in der Datei `source-code-listings.tex` **ein**. (Beachtet, dass der Dateipfad relativ zu `main.tex` ist.)
|
* Fügt sie **genau** unterhalb dieser Aufgabenstellung im Skript ein.
|
||||||
* Aktiviert das **Syntax-Highlighting** durch Angabe der Sprache Java.
|
* Das Bild soll **zentriert** auf der Seite eingebunden werden.
|
||||||
* **Nummeriert** die Zeilen und aktiviert **Umbrüche**.
|
* Fügt außerdem eine **Bildunterschrift** ein.
|
||||||
* Nutzt das **Theme** `native`.
|
* Passt die **Größe** des Bildes an Breite der Seite (`\textwidth`) an.
|
||||||
* Ändert die **Hintergrundfarbe** des Themes zu Dunkelblau.
|
|
||||||
* Bindet jetzt nur die **Zeilen 5 bis 7** ein.
|
|
||||||
* Entfernt die **Leerzeichen** am Anfang der Zeilen durch die passende Option (Tipp: Die Dokumentation spricht hier von `gobble`).
|
|
||||||
|
|
||||||
Seht bei Fragen in der Dokumentation des Paketes `minted` nach.
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=task)
|
|
||||||
|
|
||||||
@task-number
|
|
||||||
10
|
|
||||||
|
|
||||||
@title
|
|
||||||
`listings`
|
|
||||||
|
|
||||||
@content
|
|
||||||
* Im Ordner `exercises/source-code-listings` findet ihr eine Datei namens `Source.java`.
|
|
||||||
* **Bindet** den Java-Quelltext in der Datei `source-code-listings.tex` **ein**. (Beachtet, dass der Dateipfad relativ zu `main.tex` ist.)
|
|
||||||
* Aktiviert das **Syntax-Highlighting** durch Angabe der Sprache Java.
|
|
||||||
* **Nummeriert** die Zeilen und aktiviert **Umbrüche**.
|
|
||||||
* Setzt mit dem Parameter `basicstyle` eine dicktengleiche Schrift (`\ttfamily \small`).
|
|
||||||
* Ändert die Schlüsselwortfarbe zu Blau.
|
|
||||||
* Verbergt die Sonderzeichen, die **Leerzeichen in Zeichenketten** markieren.
|
|
||||||
|
|
||||||
Seht bei Fragen in der Dokumentation des Paketes `listings` nach.
|
|
||||||
|
|||||||
@ -1,289 +1,110 @@
|
|||||||
@slide(layout=chapter-slide)
|
@slide(layout=chapter-slide)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Source code listings
|
Graphics
|
||||||
|
|
||||||
@slide(layout=content-only)
|
|
||||||
|
|
||||||
@title
|
|
||||||
Our options
|
|
||||||
|
|
||||||
@content
|
|
||||||
There are two popular ways to display source code in a LaTeX document.
|
|
||||||
|
|
||||||
* ++ **`minted`** renders **very pretty** source code listings, but it requires some **extra configuration** and might not work on every operating system.
|
|
||||||
* ++ **`listings`** is an **easy-to-use** (but not as pretty) option for those having troubles with `minted`.
|
|
||||||
|
|
||||||
++ Their commands are very similar.
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview)
|
|
||||||
|
|
||||||
@title
|
|
||||||
Installation <span class="emoji">🖥️</span>
|
|
||||||
|
|
||||||
@content
|
|
||||||
`minted` requires the Python programming language. As soon as **[Python is installed](https://www.python.org/)**, we can download the corresponding Python package **[`Pygments`](http://pygments.org/)** using a command prompt:
|
|
||||||
|
|
||||||
``` {.lang-sh .hljs}
|
|
||||||
pip install Pygments
|
|
||||||
```
|
|
||||||
|
|
||||||
Add the LaTeX packages for `minted` or `listings` and we are good to go:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
|
||||||
\usepackage{minted}
|
|
||||||
\usepackage{listings}
|
|
||||||
```
|
|
||||||
|
|
||||||
@preview
|
|
||||||
{ .thin-padding }
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
|
||||||
|
|
||||||
@title
|
|
||||||
Compiler settings
|
|
||||||
|
|
||||||
@content
|
|
||||||
<div class="box warning">
|
|
||||||
We need to pass the additional flag `--shell-escape` to our compiler in order to use `minted`.<br />
|
|
||||||
<strong>Do this only for documents you trust!</strong>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
In TeXstudio, go to **`Options → Configure TeXstudio → Commands`** (`TeXstudio → Settings` on macOS) and add the flag in the PdfLaTeX row before `%.tex`:
|
|
||||||
|
|
||||||
<code>pdflatex -synctex=1 -interaction=nonstopmode **\-\-shell-escape** %.tex</code>
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
A note on our script
|
Including graphics <span class="emoji">🖼️</span>
|
||||||
|
|
||||||
@content
|
@content
|
||||||
Our exercise material allows you to choose between `minted` and `listings`.
|
To display graphics, we need the `graphicx` package.
|
||||||
By default, we use `listings`.
|
|
||||||
To activate `minted`, create a file called `listings-mode.tex` in the project's root directory and add the following line:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.lang-tex .hljs}
|
||||||
\newcommand\listingsmode{minted}
|
\begin{figure}
|
||||||
|
\includegraphics{<file path>}
|
||||||
|
\caption[<short caption (table of
|
||||||
|
figures)>]{<full caption>}
|
||||||
|
\end{figure}
|
||||||
```
|
```
|
||||||
|
|
||||||
After compiling again, your listings should be rendered by `minted`.
|
Specifying the size:
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
minted
|
|
||||||
|
|
||||||
@title
|
|
||||||
In-situ listings
|
|
||||||
|
|
||||||
@content
|
|
||||||
++ Within a dedicated environment:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs .fragment}
|
|
||||||
\section*{Haskell Magic}
|
|
||||||
Squares of all even % …
|
|
||||||
\begin{minted}{haskell}
|
|
||||||
[x^2 | x <- [1..200], even x]
|
|
||||||
\end{minted}
|
|
||||||
```
|
|
||||||
|
|
||||||
++ Directly inline:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs .fragment}
|
|
||||||
\section*{An HTML Example}
|
|
||||||
A headline is denoted the following way:
|
|
||||||
\mint{html}|<h2>LaTeX at University</h2>|
|
|
||||||
```
|
|
||||||
|
|
||||||
@preview
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
minted
|
|
||||||
|
|
||||||
@title
|
|
||||||
External source code
|
|
||||||
|
|
||||||
@content
|
|
||||||
We can avoid redundancy by including source code directly from its source file.
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.lang-tex .hljs}
|
||||||
\section*{Simple Java Application}
|
\includegraphics[width=0.5\textwidth,
|
||||||
\inputminted{java}{Test.java}
|
height=5cm]{<file path>}
|
||||||
```
|
```
|
||||||
|
|
||||||
``` {.lang-java .hljs data-sourcefile="Test.java"}
|
|
||||||
public class Test {
|
|
||||||
public static void main(/*…*/) {
|
|
||||||
System.out.println(/*…*/);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
@preview
|
@slide(layout=content-only)
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
minted
|
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Themes and styles
|
Layout on the page
|
||||||
|
|
||||||
@content
|
@content
|
||||||
Optional parameters allow us to activate line numbers, automated line breaks, and syntax highlighting based on numerous color schemes.
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.lang-tex .hljs}
|
||||||
\usemintedstyle{monokai}
|
\begin{figure}[<position code>]
|
||||||
\begin{minted}[
|
|
||||||
linenos=true,
|
|
||||||
breaklines=true,
|
|
||||||
]{javascript}
|
|
||||||
% ...
|
|
||||||
\end{minted}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<span class="emoji">🔗</span> **[introduction](https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted)** and **[official documentation](https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf)**
|
LaTeX places graphics automatically. With position codes, we can express our preferences (they can be combined as well).
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview-with-category)
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th style="min-width:4em">code</th>
|
||||||
|
<th>position</th>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>h</td>
|
||||||
|
<td>here, if you don’t mind</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>t</td>
|
||||||
|
<td>top of the page</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>b</td>
|
||||||
|
<td>bottom of the page</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>p</td>
|
||||||
|
<td>on its own page</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="fragment">
|
||||||
|
<td>H</td>
|
||||||
|
<td>Here, for God’s sake! <br />(`float` package required)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
@category
|
|
||||||
listings
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
In-situ listings
|
Centred alignment
|
||||||
|
|
||||||
@content
|
@content
|
||||||
Within a dedicated environment:
|
``` {.lang-tex .hljs}
|
||||||
|
\begin{figure}[<position>]
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics{<path-to-file>}
|
||||||
|
\end{center}
|
||||||
|
\end{figure}
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively:
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.lang-tex .hljs}
|
||||||
\section*{Haskell Magic}
|
\begin{figure}[<position>]
|
||||||
Squares of all even % …
|
\centering
|
||||||
\begin{lstlisting}[language=Haskell]
|
\includegraphics{<path-to-file>}
|
||||||
[x^2 | x <- [1..200], even x]
|
\end{figure}
|
||||||
\end{lstlisting}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The `listings` package does not provide an inline command.
|
|
||||||
|
|
||||||
@preview
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
listings
|
|
||||||
|
|
||||||
@title
|
|
||||||
External source code
|
|
||||||
|
|
||||||
@content
|
|
||||||
Conveniently, also `listings` offers an import command:
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
|
||||||
\section*{Simple Java Application}
|
|
||||||
\lstinputlisting[language=Java]{Test.java}
|
|
||||||
```
|
|
||||||
|
|
||||||
``` {.lang-java .hljs data-sourcefile="Test.java"}
|
|
||||||
public class Test {
|
|
||||||
public static void main(/*…*/) {
|
|
||||||
System.out.println(/*…*/);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
@preview
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
listings
|
|
||||||
|
|
||||||
@title
|
|
||||||
Themes and styles
|
|
||||||
|
|
||||||
@content
|
|
||||||
`listings` does not provide any themes by default, but can be configured extensively.
|
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
|
||||||
\begin{lstlisting}[
|
|
||||||
language=Java,
|
|
||||||
basicstyle=\footnotesize\ttfamily,
|
|
||||||
breaklines=true,
|
|
||||||
keywordstyle=\color{ForestGreen},
|
|
||||||
commentstyle=\color{DarkGray},
|
|
||||||
literate={ö}{{\"o}}1
|
|
||||||
]
|
|
||||||
% …
|
|
||||||
\end{lstlisting}
|
|
||||||
```
|
|
||||||
|
|
||||||
Have a look at the `\lstset` command for creating your own themes.
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only-with-category)
|
|
||||||
|
|
||||||
@category
|
|
||||||
listings
|
|
||||||
|
|
||||||
@title
|
|
||||||
Further resources
|
|
||||||
|
|
||||||
@content
|
|
||||||
* [introduction](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide) to the package
|
|
||||||
* official [documentation](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide)
|
|
||||||
* [`xcolor` package](https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX) for colors
|
|
||||||
* two [solarized themes](https://github.com/jez/latex-solarized) for `listings`
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=task)
|
@slide(layout=task)
|
||||||
|
|
||||||
@task-number
|
@task-number
|
||||||
10
|
11
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Listings with `minted`
|
Inserting graphics
|
||||||
|
|
||||||
@content
|
@content
|
||||||
* In the directory `exercises/source-code-listings` you can find a file named `Source.java`.
|
* In the directory `exercises/graphics` you can find an image file named `latex-logo.png`.
|
||||||
* **Include** it in the file `source-code-listings.tex`. (Keep in mind that the file path is relative to the main LaTeX document, i. e., to `main.tex`.)
|
* **Include** the figure in `exercises/graphics/graphics.tex` and place it **exactly** where you include it.
|
||||||
* Activate **syntax highlighting** by stating the programming language Java.
|
* The image shall be **centered**.
|
||||||
* **Number** the code lines and add **line breaks**.
|
* Additionally, add a **caption** for the figure.
|
||||||
* Use the **theme** `native`.
|
* Adapt the **width** of the image to the width of the text (`\textwidth`).
|
||||||
* Change the **background colour** to dark blue.
|
|
||||||
* Now only include **lines 5 to 7**.
|
|
||||||
* Delete the **spaces** at the beginning of the lines. (Hint: The documentation speaks of `autogobble`).
|
|
||||||
|
|
||||||
If you have questions, try to consult the documentation of the `minted` package.
|
|
||||||
|
|
||||||
@slide(layout=task)
|
|
||||||
|
|
||||||
@task-number
|
|
||||||
10
|
|
||||||
|
|
||||||
@title
|
|
||||||
Listings with `listings`
|
|
||||||
|
|
||||||
@content
|
|
||||||
* In the directory `exercises/source-code-listings` you can find a file named `Source.java`.
|
|
||||||
* **Include** it in the file `source-code-listings.tex`. (Keep in mind that the file path is relative to the main LaTeX document, i. e., to `main.tex`.)
|
|
||||||
* Activate **syntax highlighting** by stating the programming language Java.
|
|
||||||
* **Number** the code lines.
|
|
||||||
* Set the `basicstyle` to a proper mono-spaced font (`\ttfamily \small`)
|
|
||||||
* Change the **keyword color** to blue.
|
|
||||||
* Don't show special characters for **spaces in strings**.
|
|
||||||
|
|
||||||
If you have questions, try to consult the documentation of the `listings` package.
|
|
||||||
|
|||||||
@ -1,110 +1,228 @@
|
|||||||
@slide(layout=chapter-slide)
|
@slide(layout=chapter-slide)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Grafiken
|
Tabellen
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Grafiken abbilden <span class="emoji">🖼️</span>
|
Grundstruktur <span class="emoji">🗒️</span>
|
||||||
|
|
||||||
@content
|
@content
|
||||||
Um Grafiken darzustellen, muss das Paket `graphicx` eingebunden werden.
|
Für typografisch schöne Tabellen nutzen wir das Paket `booktabs`.
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.hljs .lang-tex}
|
||||||
\begin{figure}
|
\usepackage{booktabs}
|
||||||
\includegraphics{<dateipfad>}
|
|
||||||
\caption[<kurztitel (abbildungsver-
|
|
||||||
zeichnis)>]{<bildunterschrift>}
|
|
||||||
\end{figure}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Bildgröße angeben:
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{table}[<position>]
|
||||||
``` {.lang-tex .hljs}
|
\begin{tabular}{<spaltendefinition>}
|
||||||
\includegraphics[width=0.5\textwidth,
|
% Tabelleninhalt
|
||||||
height=5cm]{<dateipfad>}
|
\end{tabular}
|
||||||
|
\caption{<tabellenunterschrift>}
|
||||||
|
\end{table}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Die Positionierung erfolgt analog zu Grafiken.
|
||||||
|
|
||||||
@slide(layout=content-only)
|
|
||||||
|
@slide(layout=content-and-preview)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Positionierung auf der Seite
|
Spaltendefinitionen
|
||||||
|
|
||||||
@content
|
@content
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
``` {.lang-tex .hljs}
|
\begin{tabular}{lrcl}
|
||||||
\begin{figure}[<positionskürzel>]
|
% Tabelleninhalt
|
||||||
|
\end{tabular}
|
||||||
```
|
```
|
||||||
|
|
||||||
LaTeX positioniert Grafiken automatisch. Durch Kürzel können wir unsere Präferenzen (auch in Kombination) angeben.
|
|
||||||
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="min-width:4em">Kürzel</th>
|
<th>Kürzel</th>
|
||||||
<th>Position</th>
|
<th>Bedeutung</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="fragment">
|
<tr class="fragment">
|
||||||
<td>h</td>
|
<td>l</td>
|
||||||
<td>hier, wenn es dir recht ist</td>
|
<td>linksbündige Spalte</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="fragment">
|
<tr class="fragment">
|
||||||
<td>t</td>
|
<td>c</td>
|
||||||
<td>oberer Seitenrand (top)</td>
|
<td>zentrierte Spalte</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="fragment">
|
<tr class="fragment">
|
||||||
<td>b</td>
|
<td>r</td>
|
||||||
<td>unterer Seitenrand (bottom)</td>
|
<td>rechtsbündige Spalte</td>
|
||||||
</tr>
|
|
||||||
<tr class="fragment">
|
|
||||||
<td>p</td>
|
|
||||||
<td>auf einer eigenen Seite (page)</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="fragment">
|
|
||||||
<td>H</td>
|
|
||||||
<td>Hier, verdammt noch mal! <br />(benötigt Paket `float`)</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
++ Vertikale Trennlinien und doppelte horizontale Linien sind unter Typograph\*innen nicht gern gesehen und sollten vermieden werden.
|
||||||
|
|
||||||
|
@preview
|
||||||
|
{.thin-padding}
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-and-preview)
|
||||||
|
|
||||||
|
@title
|
||||||
|
Tabelleninhalt
|
||||||
|
|
||||||
|
@content
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{tabular}{lll}
|
||||||
|
\toprule
|
||||||
|
Spalte 1 & Spalte 2 & Spalte 3 \\
|
||||||
|
\midrule
|
||||||
|
Inhalt a & Inhalt b & Inhalt c \\
|
||||||
|
Inhalt e & Inhalt f & Inhalt g \\
|
||||||
|
Inhalt i & Inhalt j & Inhalt k \\
|
||||||
|
\bottomrule
|
||||||
|
\end{tabular}
|
||||||
|
```
|
||||||
|
* ++ Zellen werden durch ›`&`‹ abgetrennt.
|
||||||
|
* ++ Reihen werden durch ›`\\`‹ beendet.
|
||||||
|
* ++ `\toprule`, `\midrule` und `\bottomrule` strukturieren die Tabelle.
|
||||||
|
|
||||||
|
@preview
|
||||||
|
{.thin-padding}
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=wide-content)
|
||||||
|
|
||||||
|
@title
|
||||||
|
Die gesamte Tabelle
|
||||||
|
|
||||||
|
@content
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{table}[h]
|
||||||
|
\begin{tabular}{lrcl}
|
||||||
|
\toprule
|
||||||
|
Sprache & Autor & Erscheinungsjahr & Aktuelle 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{Bekannte Programmiersprachen}
|
||||||
|
\end{table}
|
||||||
|
```
|
||||||
|
|
||||||
|
<p data-category="Hinweis">Mit `@{}` vor und nach einer Spaltendefinition wird der umgebende Weißraum unterdrückt.</p>
|
||||||
|
|
||||||
|
<p data-category="Beispiel">`\begin{tabular}{@{}lrcl@{}}` beschränkt die Linien auf die Breite des Tabelleninhalts.</p>
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Zentrierte Anordnung
|
Besonders lange Tabellen
|
||||||
|
|
||||||
@content
|
@content
|
||||||
``` {.lang-tex .hljs}
|
Tabellen, die über eine Seite hinaus gehen, werden von `tabular` einfach abgeschnitten. Die Lösung bietet hier das Paket `longtable`:
|
||||||
\begin{figure}[<position>]
|
|
||||||
\begin{center}
|
``` {.hljs .lang-tex}
|
||||||
\includegraphics{<dateipfad>}
|
\usepackage{longtable}
|
||||||
\end{center}
|
|
||||||
\end{figure}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternativ:
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{longtable}{<spaltendefinition>}
|
||||||
``` {.lang-tex .hljs}
|
% Tabelleninhalt
|
||||||
\begin{figure}[<position>]
|
\caption{<tabellenunterschrift>}
|
||||||
\centering
|
\label{<label>}
|
||||||
\includegraphics{<dateipfad>}
|
\end{longtable}
|
||||||
\end{figure}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-only)
|
||||||
|
|
||||||
|
@title
|
||||||
|
Hinweise zu `longtable`
|
||||||
|
|
||||||
|
@content
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{longtable}{<spaltendefinition>}
|
||||||
|
% Tabelleninhalt
|
||||||
|
\caption{<tabellenunterschrift>}
|
||||||
|
\label{<label>}
|
||||||
|
\end{longtable}
|
||||||
|
```
|
||||||
|
* ++ Die `longtable`-Umgebung vereint die `tabular`-Umgebung und die `table`-Umgebung.
|
||||||
|
* ++ Titel und Label können deshalb direkt unter dem Tabelleninhalt stehen.
|
||||||
|
* ++ Sofern das Paket `booktabs` eingebunden ist, stehen seine Features auch in `longtable` zur Verfügung.
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-only)
|
||||||
|
|
||||||
|
@title
|
||||||
|
Besonders breite Tabellen
|
||||||
|
|
||||||
|
@content
|
||||||
|
Sollte die Tabelle einmal zu breit für eine Seite werden, kann sie auch im Querformat dargestellt werden:
|
||||||
|
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
|
\usepackage{rotating}
|
||||||
|
```
|
||||||
|
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{sidewaystable}[<position>]
|
||||||
|
\begin{tabular}{<spaltendef.>}
|
||||||
|
% Tabelleninhalt
|
||||||
|
\end{tabular}
|
||||||
|
\end{sidewaystable}
|
||||||
|
```
|
||||||
|
|
||||||
|
@slide(layout=content-and-preview)
|
||||||
|
|
||||||
|
@title
|
||||||
|
Weiterführendes Beispiel
|
||||||
|
|
||||||
|
@content
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{table}[h]
|
||||||
|
\begin{tabular}{llr}
|
||||||
|
\toprule
|
||||||
|
Struktur & \multicolumn{2}{l}{Zeitkomplexität für Zugriff} \\ \cmidrule(r){2-3}
|
||||||
|
& Average & Worst \\
|
||||||
|
\midrule
|
||||||
|
Stack & $\mathcal{O}(n)$ & $\mathcal{O}(n)$ \\
|
||||||
|
Binärbaum & $\mathcal{O}(log(n))$ & $\mathcal{O}(log(n))$ \\
|
||||||
|
AVL-Baum & $\mathcal{O}(log(n))$ & $\mathcal{O}(log(n))$ \\
|
||||||
|
\bottomrule
|
||||||
|
\end{tabular}
|
||||||
|
\end{table}
|
||||||
|
```
|
||||||
|
|
||||||
|
[<span class="emoji">🔗</span> Dokumentation zu Booktabs](http://packages.oth-regensburg.de/ctan/macros/latex/contrib/booktabs/booktabs.pdf)
|
||||||
|
|
||||||
|
@preview
|
||||||
|
{.thin-padding}
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-only)
|
||||||
|
|
||||||
|
@title
|
||||||
|
Mehr Komfort
|
||||||
|
|
||||||
|
@content
|
||||||
|
Der [Tables Generator](https://tablesgenerator.com/) ist ein wunderbares Werkzeug, um schnell Tabellen verschiedener Formate zu erstellen.
|
||||||
|
|
||||||
|
[](https://tablesgenerator.com/)
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=task)
|
@slide(layout=task)
|
||||||
|
|
||||||
@task-number
|
@task-number
|
||||||
11
|
12
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Grafiken einfügen
|
Tabellen setzen
|
||||||
|
|
||||||
@content
|
@content
|
||||||
* Im Ordner `exercises/graphics` findet ihr eine Bilddatei namens `latex-logo.png`.
|
* Die Liste in der Datei `exercises/tables/tables.tex` enthält Infos zu ein paar Lehrveranstaltung an der Fakultät WIAI.
|
||||||
* Fügt sie **genau** unterhalb dieser Aufgabenstellung im Skript ein.
|
* Wandelt die Liste in eine **Tabelle** um.
|
||||||
* Das Bild soll **zentriert** auf der Seite eingebunden werden.
|
* Die Tabelle soll Spalten für den *Namen*, das *Kürzel* und das *Semester* der Vorlesungen haben.
|
||||||
* Fügt außerdem eine **Bildunterschrift** ein.
|
* Fügt außerdem eine **zentrierte Spalte** ganz links in der Tabelle hinzu, in der ihr die Lehrveranstaltungen **nummeriert**.
|
||||||
* Passt die **Größe** des Bildes an Breite der Seite (`\textwidth`) an.
|
|
||||||
|
|||||||
@ -1,110 +1,229 @@
|
|||||||
@slide(layout=chapter-slide)
|
@slide(layout=chapter-slide)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Graphics
|
Tables
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Including graphics <span class="emoji">🖼️</span>
|
Basic structure <span class="emoji">🗒️</span>
|
||||||
|
|
||||||
@content
|
@content
|
||||||
To display graphics, we need the `graphicx` package.
|
For typographically pleasing tables, we use the `booktabs` package.
|
||||||
|
|
||||||
``` {.lang-tex .hljs}
|
``` {.hljs .lang-tex}
|
||||||
\begin{figure}
|
\usepackage{booktabs}
|
||||||
\includegraphics{<file path>}
|
|
||||||
\caption[<short caption (table of
|
|
||||||
figures)>]{<full caption>}
|
|
||||||
\end{figure}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Specifying the size:
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{table}[<position>]
|
||||||
``` {.lang-tex .hljs}
|
\begin{tabular}{<column definition>}
|
||||||
\includegraphics[width=0.5\textwidth,
|
% table content
|
||||||
height=5cm]{<file path>}
|
\end{tabular}
|
||||||
|
\caption{<caption>}
|
||||||
|
\end{table}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Positioning works just like with graphics.
|
||||||
|
|
||||||
@slide(layout=content-only)
|
|
||||||
|
@slide(layout=content-and-preview)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Layout on the page
|
Column definitions
|
||||||
|
|
||||||
@content
|
@content
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
``` {.lang-tex .hljs}
|
\begin{tabular}{lrcl}
|
||||||
\begin{figure}[<position code>]
|
% table content
|
||||||
|
\end{tabular}
|
||||||
```
|
```
|
||||||
|
|
||||||
LaTeX places graphics automatically. With position codes, we can express our preferences (they can be combined as well).
|
|
||||||
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="min-width:4em">code</th>
|
<th>letter</th>
|
||||||
<th>position</th>
|
<th>meaning</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="fragment">
|
<tr class="fragment">
|
||||||
<td>h</td>
|
<td>l</td>
|
||||||
<td>here, if you don’t mind</td>
|
<td>left-justified column</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="fragment">
|
<tr class="fragment">
|
||||||
<td>t</td>
|
<td>c</td>
|
||||||
<td>top of the page</td>
|
<td>centred column</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="fragment">
|
<tr class="fragment">
|
||||||
<td>b</td>
|
<td>r</td>
|
||||||
<td>bottom of the page</td>
|
<td>right-justified column</td>
|
||||||
</tr>
|
|
||||||
<tr class="fragment">
|
|
||||||
<td>p</td>
|
|
||||||
<td>on its own page</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="fragment">
|
|
||||||
<td>H</td>
|
|
||||||
<td>Here, for God’s sake! <br />(`float` package required)</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</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)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Centred alignment
|
Particularly long tables
|
||||||
|
|
||||||
@content
|
@content
|
||||||
``` {.lang-tex .hljs}
|
Tables that exceed one page are simply cut off by `tabular`. A solution is offered by the `longtable` package:
|
||||||
\begin{figure}[<position>]
|
|
||||||
\begin{center}
|
``` {.hljs .lang-tex}
|
||||||
\includegraphics{<path-to-file>}
|
\usepackage{longtable}
|
||||||
\end{center}
|
|
||||||
\end{figure}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively:
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{longtable}{<column definition>}
|
||||||
``` {.lang-tex .hljs}
|
% table content
|
||||||
\begin{figure}[<position>]
|
\caption{<caption>}
|
||||||
\centering
|
\label{<label>}
|
||||||
\includegraphics{<path-to-file>}
|
\end{longtable}
|
||||||
\end{figure}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
@content
|
||||||
|
If you need a table to be wider than a page, you can display it in landscape orientation:
|
||||||
|
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
|
\usepackage{rotating}
|
||||||
|
```
|
||||||
|
|
||||||
|
``` {.hljs .lang-tex}
|
||||||
|
\begin{sidewaystable}[<position>]
|
||||||
|
\begin{tabular}{<column def.>}
|
||||||
|
% table content
|
||||||
|
\end{tabular}
|
||||||
|
\end{sidewaystable}
|
||||||
|
```
|
||||||
|
|
||||||
|
@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}(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)
|
@slide(layout=task)
|
||||||
|
|
||||||
@task-number
|
@task-number
|
||||||
11
|
12
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Inserting graphics
|
Typesetting tables
|
||||||
|
|
||||||
@content
|
@content
|
||||||
* In the directory `exercises/graphics` you can find an image file named `latex-logo.png`.
|
* The list in file `exercises/tables/tables.tex` stores information on a few modules of the WIAI faculty.
|
||||||
* **Include** the figure in `exercises/graphics/graphics.tex` and place it **exactly** where you include it.
|
* Transform the list into a **table**.
|
||||||
* The image shall be **centered**.
|
* The table shall have colums for the *name*, the *abbreviation* (Kürzel) and the *semester* of the lectures.
|
||||||
* Additionally, add a **caption** for the figure.
|
* Add a **column** with **center-aligned text** on the left side of the table in order to **number** the lectures.
|
||||||
* Adapt the **width** of the image to the width of the text (`\textwidth`).
|
* Add a **caption** for the table.
|
||||||
|
|||||||
@ -1,228 +1,292 @@
|
|||||||
@slide(layout=chapter-slide)
|
@slide(layout=chapter-slide)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Tabellen
|
Quelltext-Listings
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Grundstruktur <span class="emoji">🗒️</span>
|
Unsere Optionen
|
||||||
|
|
||||||
@content
|
@content
|
||||||
Für typografisch schöne Tabellen nutzen wir das Paket `booktabs`.
|
Es gibt zwei verbreitete Wege, Quelltext in LaTeX-Dokumenten zu zeigen.
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
* ++ **`minted`** erstellt **sehr hübsche** Quelltext-Listings, aber es benötigt **etwas mehr Konfiguration** und funktioniert nicht auf allen Betriebssystemen zuverlässig.
|
||||||
\usepackage{booktabs}
|
* ++ **`listings`** ist eine **einfach zu nutzende** (aber nicht so hübsche) Alternative für diejenigen, die Probleme mit `minted` haben.
|
||||||
```
|
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
++ Die Befehle beider Pakete sind sehr ähnlich.
|
||||||
\begin{table}[<position>]
|
|
||||||
\begin{tabular}{<spaltendefinition>}
|
|
||||||
% Tabelleninhalt
|
|
||||||
\end{tabular}
|
|
||||||
\caption{<tabellenunterschrift>}
|
|
||||||
\end{table}
|
|
||||||
```
|
|
||||||
|
|
||||||
Die Positionierung erfolgt analog zu Grafiken.
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview)
|
@slide(layout=content-and-preview)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Spaltendefinitionen
|
Installation <span class="emoji">🖥️</span>
|
||||||
|
|
||||||
@content
|
@content
|
||||||
``` {.hljs .lang-tex}
|
`minted` benötigt die Programmiersprache Python. Nach der **[Installation von Python](https://www.python.org/)** kann das zugehörige Paket **[`Pygments`](http://pygments.org/)** in der Eingabeaufforderung installiert werden durch:
|
||||||
\begin{tabular}{lrcl}
|
|
||||||
% Tabelleninhalt
|
``` {.lang-sh .hljs}
|
||||||
\end{tabular}
|
pip install Pygments
|
||||||
```
|
```
|
||||||
|
|
||||||
<table>
|
Anschließend muss das Paket `minted` (oder `listings`) nur noch eingebunden werden:
|
||||||
<tr>
|
|
||||||
<th>Kürzel</th>
|
|
||||||
<th>Bedeutung</th>
|
|
||||||
</tr>
|
|
||||||
<tr class="fragment">
|
|
||||||
<td>l</td>
|
|
||||||
<td>linksbündige Spalte</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="fragment">
|
|
||||||
<td>c</td>
|
|
||||||
<td>zentrierte Spalte</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="fragment">
|
|
||||||
<td>r</td>
|
|
||||||
<td>rechtsbündige Spalte</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
++ Vertikale Trennlinien und doppelte horizontale Linien sind unter Typograph\*innen nicht gern gesehen und sollten vermieden werden.
|
``` {.lang-tex .hljs}
|
||||||
|
\usepackage{minted}
|
||||||
|
\usepackage{listings}
|
||||||
|
```
|
||||||
|
|
||||||
@preview
|
@preview
|
||||||
{.thin-padding}
|
{ .thin-padding }
|
||||||
|
|
||||||
|
@slide(layout=content-only)
|
||||||
@slide(layout=content-and-preview)
|
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Tabelleninhalt
|
Anpassungen beim Kompilieren
|
||||||
|
|
||||||
@content
|
@content
|
||||||
``` {.hljs .lang-tex}
|
<div class="box warning">
|
||||||
\begin{tabular}{lll}
|
Um Dokumente mit Quelltext-Listings kompilieren zu können, muss die Flag `--shell-escape` an den Compiler übergeben werden.<br />
|
||||||
\toprule
|
<strong>Dies ist nur bei vertrauenswürdigen Dokumenten empfehlenswert.</strong>
|
||||||
Spalte 1 & Spalte 2 & Spalte 3 \\
|
</div>
|
||||||
\midrule
|
|
||||||
Inhalt a & Inhalt b & Inhalt c \\
|
In TeXstudio muss diese unter **`Optionen → TeXstudio konfigurieren → Befehle`** (`TeXstudio → Einstellungen` unter macOS) bei PdfLaTeX vor `%.tex` ergänzt werden:
|
||||||
Inhalt e & Inhalt f & Inhalt g \\
|
|
||||||
Inhalt i & Inhalt j & Inhalt k \\
|
<code>pdflatex -synctex=1 -interaction=nonstopmode **\-\-shell-escape** %.tex</code>
|
||||||
\bottomrule
|
|
||||||
\end{tabular}
|
|
||||||
|
@slide(layout=content-only)
|
||||||
|
|
||||||
|
@title
|
||||||
|
Ein Hinweis zu unserem Skript
|
||||||
|
|
||||||
|
@content
|
||||||
|
Unsere Übungsmaterialien erlauben es, zwischen `minted` und `listings` zu wählen.
|
||||||
|
Von Haus aus nutzen wir `listings`.
|
||||||
|
Um `minted` zu aktivieren muss eine Datei namens `listings-mode.tex` mit dem folgenden Inhalt im Wurzelverzeichnis unseres Projekts erstellt werden:
|
||||||
|
|
||||||
|
```{.lang-tex .hljs}
|
||||||
|
\newcommand\listingsmode{minted}
|
||||||
|
```
|
||||||
|
|
||||||
|
Kompiliert erneut und die Listings sollten durch `minted` erstellt worden sein.
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-and-preview-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
minted
|
||||||
|
|
||||||
|
@title
|
||||||
|
Code im LaTeX-Quelltext
|
||||||
|
|
||||||
|
@content
|
||||||
|
++ In einer eigenen Umgebung:
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs .fragment}
|
||||||
|
\section*{Haskell-Magie}
|
||||||
|
Quadrate aller geraden % …
|
||||||
|
\begin{minted}{haskell}
|
||||||
|
[x^2 | x <- [1..200], even x]
|
||||||
|
\end{minted}
|
||||||
|
```
|
||||||
|
|
||||||
|
++ Inline im Quelltext:
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs .fragment}
|
||||||
|
\section*{Ein HTML-Beispiel}
|
||||||
|
Eine Überschrift wird so ausgezeichnet:
|
||||||
|
\mint{html}|<h2>LaTeX im Studium</h2>|.
|
||||||
```
|
```
|
||||||
* ++ Zellen werden durch ›`&`‹ abgetrennt.
|
|
||||||
* ++ Reihen werden durch ›`\\`‹ beendet.
|
|
||||||
* ++ `\toprule`, `\midrule` und `\bottomrule` strukturieren die Tabelle.
|
|
||||||
|
|
||||||
@preview
|
@preview
|
||||||
{.thin-padding}
|

|
||||||
|
|
||||||
|
|
||||||
@slide(layout=wide-content)
|
@slide(layout=content-and-preview-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
minted
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Die gesamte Tabelle
|
Externer Code
|
||||||
|
|
||||||
@content
|
@content
|
||||||
``` {.hljs .lang-tex}
|
Um Redundanz zu vermeiden, ist es manchmal praktisch, den Quelltext direkt aus der Quelldatei einzulesen.
|
||||||
\begin{table}[h]
|
|
||||||
\begin{tabular}{lrcl}
|
``` {.lang-tex .hljs}
|
||||||
\toprule
|
\section*{Einfache Java-Anwendung}
|
||||||
Sprache & Autor & Erscheinungsjahr & Aktuelle Version \\
|
\inputminted{java}{Test.java}
|
||||||
\midrule
|
|
||||||
C++ & Bjarne Stroustrup & 1985 & C++ 17 \\
|
|
||||||
Java & James Gosling & 1998 & 13 \\
|
|
||||||
Python & Guido van Rossum & 1991 & 3.8.0 \\
|
|
||||||
\bottomrule
|
|
||||||
\end{tabular}
|
|
||||||
\caption{Bekannte Programmiersprachen}
|
|
||||||
\end{table}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<p data-category="Hinweis">Mit `@{}` vor und nach einer Spaltendefinition wird der umgebende Weißraum unterdrückt.</p>
|
``` {.lang-java .hljs data-sourcefile="Test.java"}
|
||||||
|
public class Test {
|
||||||
<p data-category="Beispiel">`\begin{tabular}{@{}lrcl@{}}` beschränkt die Linien auf die Breite des Tabelleninhalts.</p>
|
public static void main(/*…*/) {
|
||||||
|
System.out.println(/*…*/);
|
||||||
|
}
|
||||||
@slide(layout=content-only)
|
}
|
||||||
|
|
||||||
@title
|
|
||||||
Besonders lange Tabellen
|
|
||||||
|
|
||||||
@content
|
|
||||||
Tabellen, die über eine Seite hinaus gehen, werden von `tabular` einfach abgeschnitten. Die Lösung bietet hier das Paket `longtable`:
|
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\usepackage{longtable}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\begin{longtable}{<spaltendefinition>}
|
|
||||||
% Tabelleninhalt
|
|
||||||
\caption{<tabellenunterschrift>}
|
|
||||||
\label{<label>}
|
|
||||||
\end{longtable}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
|
||||||
|
|
||||||
@title
|
|
||||||
Hinweise zu `longtable`
|
|
||||||
|
|
||||||
@content
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\begin{longtable}{<spaltendefinition>}
|
|
||||||
% Tabelleninhalt
|
|
||||||
\caption{<tabellenunterschrift>}
|
|
||||||
\label{<label>}
|
|
||||||
\end{longtable}
|
|
||||||
```
|
|
||||||
* ++ Die `longtable`-Umgebung vereint die `tabular`-Umgebung und die `table`-Umgebung.
|
|
||||||
* ++ Titel und Label können deshalb direkt unter dem Tabelleninhalt stehen.
|
|
||||||
* ++ Sofern das Paket `booktabs` eingebunden ist, stehen seine Features auch in `longtable` zur Verfügung.
|
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
|
||||||
|
|
||||||
@title
|
|
||||||
Besonders breite Tabellen
|
|
||||||
|
|
||||||
@content
|
|
||||||
Sollte die Tabelle einmal zu breit für eine Seite werden, kann sie auch im Querformat dargestellt werden:
|
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\usepackage{rotating}
|
|
||||||
```
|
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\begin{sidewaystable}[<position>]
|
|
||||||
\begin{tabular}{<spaltendef.>}
|
|
||||||
% Tabelleninhalt
|
|
||||||
\end{tabular}
|
|
||||||
\end{sidewaystable}
|
|
||||||
```
|
|
||||||
|
|
||||||
@slide(layout=content-and-preview)
|
|
||||||
|
|
||||||
@title
|
|
||||||
Weiterführendes Beispiel
|
|
||||||
|
|
||||||
@content
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\begin{table}[h]
|
|
||||||
\begin{tabular}{llr}
|
|
||||||
\toprule
|
|
||||||
Struktur & \multicolumn{2}{l}{Zeitkomplexität für Zugriff} \\ \cmidrule(r){2-3}
|
|
||||||
& Average & Worst \\
|
|
||||||
\midrule
|
|
||||||
Stack & $\mathcal{O}(n)$ & $\mathcal{O}(n)$ \\
|
|
||||||
Binärbaum & $\mathcal{O}(log(n))$ & $\mathcal{O}(log(n))$ \\
|
|
||||||
AVL-Baum & $\mathcal{O}(log(n))$ & $\mathcal{O}(log(n))$ \\
|
|
||||||
\bottomrule
|
|
||||||
\end{tabular}
|
|
||||||
\end{table}
|
|
||||||
```
|
|
||||||
|
|
||||||
[<span class="emoji">🔗</span> Dokumentation zu Booktabs](http://packages.oth-regensburg.de/ctan/macros/latex/contrib/booktabs/booktabs.pdf)
|
|
||||||
|
|
||||||
@preview
|
@preview
|
||||||
{.thin-padding}
|

|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
minted
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Mehr Komfort
|
Themen und Stile
|
||||||
|
|
||||||
@content
|
@content
|
||||||
Der [Tables Generator](https://tablesgenerator.com/) ist ein wunderbares Werkzeug, um schnell Tabellen verschiedener Formate zu erstellen.
|
Durch optionale Parameter können Zeilennummerierung, Umbrüche und Farben ausgewählt werden. Außerdem sind zahlreiche Themes verfügbar.
|
||||||
|
|
||||||
[](https://tablesgenerator.com/)
|
``` {.lang-tex .hljs}
|
||||||
|
\usemintedstyle{monokai}
|
||||||
|
\begin{minted}[
|
||||||
|
linenos=true,
|
||||||
|
breaklines=true,
|
||||||
|
]{javascript}
|
||||||
|
% ...
|
||||||
|
\end{minted}
|
||||||
|
```
|
||||||
|
|
||||||
|
<span class="emoji">🔗</span> **[Einführung](https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted)** und **[offizielle Dokumentation](https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf)**
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-and-preview-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
listings
|
||||||
|
|
||||||
|
@title
|
||||||
|
Code im LaTeX-Quelltext
|
||||||
|
|
||||||
|
@content
|
||||||
|
In einer eigenen Umgebung:
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs}
|
||||||
|
\section*{Haskell-Magie}
|
||||||
|
Quadrate aller geraden % …
|
||||||
|
\begin{lstlisting}[language=Haskell]
|
||||||
|
[x^2 | x <- [1..200], even x]
|
||||||
|
\end{lstlisting}
|
||||||
|
```
|
||||||
|
|
||||||
|
Das Paket `listings` stellt keinen Befehl für inline-Listings zur Verfügung.
|
||||||
|
|
||||||
|
@preview
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-and-preview-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
listings
|
||||||
|
|
||||||
|
@title
|
||||||
|
Externer Code
|
||||||
|
|
||||||
|
@content
|
||||||
|
Praktischerweise bietet auch `listings` einen Befehl zum Einfügen externen Codes:
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs}
|
||||||
|
\section*{Einfache Java-Anwendung}
|
||||||
|
\lstinputlisting[language=Java]{Test.java}
|
||||||
|
```
|
||||||
|
|
||||||
|
``` {.lang-java .hljs data-sourcefile="Test.java"}
|
||||||
|
public class Test {
|
||||||
|
public static void main(/*…*/) {
|
||||||
|
System.out.println(/*…*/);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
@preview
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-only-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
listings
|
||||||
|
|
||||||
|
@title
|
||||||
|
Themen und Stile
|
||||||
|
|
||||||
|
@content
|
||||||
|
`listings` stellt keine eigenen Themes zur Verfügung. Dies kann aber durch die vielen Konfigurationsoptionen ausgeglichen werden.
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs}
|
||||||
|
\begin{lstlisting}[
|
||||||
|
language=Java,
|
||||||
|
basicstyle=\footnotesize\ttfamily,
|
||||||
|
breaklines=true,
|
||||||
|
keywordstyle=\color{ForestGreen},
|
||||||
|
commentstyle=\color{DarkGray},
|
||||||
|
literate={ö}{{\"o}}1
|
||||||
|
]
|
||||||
|
% …
|
||||||
|
\end{lstlisting}
|
||||||
|
```
|
||||||
|
|
||||||
|
Für die Erstellung eigener Themes ist der Befehl `\lstset` nützlich.
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-only-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
listings
|
||||||
|
|
||||||
|
@title
|
||||||
|
Weitere Materialien
|
||||||
|
|
||||||
|
@content
|
||||||
|
* [Einführung](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide) in das Paket
|
||||||
|
* offizielle [Dokumentation](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide)
|
||||||
|
* das Paket [`xcolor`](https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX) für Farben
|
||||||
|
* zwei [Themes](https://github.com/jez/latex-solarized) im solarized-Stil für `listings`
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=task)
|
@slide(layout=task)
|
||||||
|
|
||||||
@task-number
|
@task-number
|
||||||
12
|
10
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Tabellen setzen
|
`minted`
|
||||||
|
|
||||||
@content
|
@content
|
||||||
* Die Liste in der Datei `exercises/tables/tables.tex` enthält Infos zu ein paar Lehrveranstaltung an der Fakultät WIAI.
|
* Im Ordner `exercises/source-code-listings` findet ihr eine Datei namens `Source.java`.
|
||||||
* Wandelt die Liste in eine **Tabelle** um.
|
* **Bindet** den Java-Quelltext in der Datei `source-code-listings.tex` **ein**. (Beachtet, dass der Dateipfad relativ zu `main.tex` ist.)
|
||||||
* Die Tabelle soll Spalten für den *Namen*, das *Kürzel* und das *Semester* der Vorlesungen haben.
|
* Aktiviert das **Syntax-Highlighting** durch Angabe der Sprache Java.
|
||||||
* Fügt außerdem eine **zentrierte Spalte** ganz links in der Tabelle hinzu, in der ihr die Lehrveranstaltungen **nummeriert**.
|
* **Nummeriert** die Zeilen und aktiviert **Umbrüche**.
|
||||||
|
* Nutzt das **Theme** `native`.
|
||||||
|
* Ändert die **Hintergrundfarbe** des Themes zu Dunkelblau.
|
||||||
|
* Bindet jetzt nur die **Zeilen 5 bis 7** ein.
|
||||||
|
* Entfernt die **Leerzeichen** am Anfang der Zeilen durch die passende Option (Tipp: Die Dokumentation spricht hier von `gobble`).
|
||||||
|
|
||||||
|
Seht bei Fragen in der Dokumentation des Paketes `minted` nach.
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=task)
|
||||||
|
|
||||||
|
@task-number
|
||||||
|
10
|
||||||
|
|
||||||
|
@title
|
||||||
|
`listings`
|
||||||
|
|
||||||
|
@content
|
||||||
|
* Im Ordner `exercises/source-code-listings` findet ihr eine Datei namens `Source.java`.
|
||||||
|
* **Bindet** den Java-Quelltext in der Datei `source-code-listings.tex` **ein**. (Beachtet, dass der Dateipfad relativ zu `main.tex` ist.)
|
||||||
|
* Aktiviert das **Syntax-Highlighting** durch Angabe der Sprache Java.
|
||||||
|
* **Nummeriert** die Zeilen und aktiviert **Umbrüche**.
|
||||||
|
* Setzt mit dem Parameter `basicstyle` eine dicktengleiche Schrift (`\ttfamily \small`).
|
||||||
|
* Ändert die Schlüsselwortfarbe zu Blau.
|
||||||
|
* Verbergt die Sonderzeichen, die **Leerzeichen in Zeichenketten** markieren.
|
||||||
|
|
||||||
|
Seht bei Fragen in der Dokumentation des Paketes `listings` nach.
|
||||||
|
|||||||
@ -1,229 +1,289 @@
|
|||||||
@slide(layout=chapter-slide)
|
@slide(layout=chapter-slide)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Tables
|
Source code listings
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Basic structure <span class="emoji">🗒️</span>
|
Our options
|
||||||
|
|
||||||
@content
|
@content
|
||||||
For typographically pleasing tables, we use the `booktabs` package.
|
There are two popular ways to display source code in a LaTeX document.
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
* ++ **`minted`** renders **very pretty** source code listings, but it requires some **extra configuration** and might not work on every operating system.
|
||||||
\usepackage{booktabs}
|
* ++ **`listings`** is an **easy-to-use** (but not as pretty) option for those having troubles with `minted`.
|
||||||
```
|
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\begin{table}[<position>]
|
|
||||||
\begin{tabular}{<column definition>}
|
|
||||||
% table content
|
|
||||||
\end{tabular}
|
|
||||||
\caption{<caption>}
|
|
||||||
\end{table}
|
|
||||||
```
|
|
||||||
|
|
||||||
Positioning works just like with graphics.
|
|
||||||
|
|
||||||
|
++ Their commands are very similar.
|
||||||
|
|
||||||
@slide(layout=content-and-preview)
|
@slide(layout=content-and-preview)
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Column definitions
|
Installation <span class="emoji">🖥️</span>
|
||||||
|
|
||||||
@content
|
@content
|
||||||
``` {.hljs .lang-tex}
|
`minted` requires the Python programming language. As soon as **[Python is installed](https://www.python.org/)**, we can download the corresponding Python package **[`Pygments`](http://pygments.org/)** using a command prompt:
|
||||||
\begin{tabular}{lrcl}
|
|
||||||
% table content
|
``` {.lang-sh .hljs}
|
||||||
\end{tabular}
|
pip install Pygments
|
||||||
```
|
```
|
||||||
|
|
||||||
<table>
|
Add the LaTeX packages for `minted` or `listings` and we are good to go:
|
||||||
<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.
|
``` {.lang-tex .hljs}
|
||||||
|
\usepackage{minted}
|
||||||
|
\usepackage{listings}
|
||||||
|
```
|
||||||
|
|
||||||
@preview
|
@preview
|
||||||
{.thin-padding}
|
{ .thin-padding }
|
||||||
|
|
||||||
|
@slide(layout=content-only)
|
||||||
@slide(layout=content-and-preview)
|
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Table content
|
Compiler settings
|
||||||
|
|
||||||
@content
|
@content
|
||||||
``` {.hljs .lang-tex}
|
<div class="box warning">
|
||||||
\begin{tabular}{lll}
|
We need to pass the additional flag `--shell-escape` to our compiler in order to use `minted`.<br />
|
||||||
\toprule
|
<strong>Do this only for documents you trust!</strong>
|
||||||
Column 1 & Column 2 & Column 3 \\
|
</div>
|
||||||
\midrule
|
|
||||||
Content a & Content b & Content c \\
|
In TeXstudio, go to **`Options → Configure TeXstudio → Commands`** (`TeXstudio → Settings` on macOS) and add the flag in the PdfLaTeX row before `%.tex`:
|
||||||
Content e & Content f & Content g \\
|
|
||||||
Content i & Content j & Content k \\
|
<code>pdflatex -synctex=1 -interaction=nonstopmode **\-\-shell-escape** %.tex</code>
|
||||||
\bottomrule
|
|
||||||
\end{tabular}
|
|
||||||
|
@slide(layout=content-only)
|
||||||
|
|
||||||
|
@title
|
||||||
|
A note on our script
|
||||||
|
|
||||||
|
@content
|
||||||
|
Our exercise material allows you to choose between `minted` and `listings`.
|
||||||
|
By default, we use `listings`.
|
||||||
|
To activate `minted`, create a file called `listings-mode.tex` in the project's root directory and add the following line:
|
||||||
|
|
||||||
|
```{.lang-tex .hljs}
|
||||||
|
\newcommand\listingsmode{minted}
|
||||||
|
```
|
||||||
|
|
||||||
|
After compiling again, your listings should be rendered by `minted`.
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-and-preview-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
minted
|
||||||
|
|
||||||
|
@title
|
||||||
|
In-situ listings
|
||||||
|
|
||||||
|
@content
|
||||||
|
++ Within a dedicated environment:
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs .fragment}
|
||||||
|
\section*{Haskell Magic}
|
||||||
|
Squares of all even % …
|
||||||
|
\begin{minted}{haskell}
|
||||||
|
[x^2 | x <- [1..200], even x]
|
||||||
|
\end{minted}
|
||||||
|
```
|
||||||
|
|
||||||
|
++ Directly inline:
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs .fragment}
|
||||||
|
\section*{An HTML Example}
|
||||||
|
A headline is denoted the following way:
|
||||||
|
\mint{html}|<h2>LaTeX at University</h2>|
|
||||||
```
|
```
|
||||||
* ++ Columns are separated by ’`&`’.
|
|
||||||
* ++ Rows are ended by ‘`\\`’.
|
|
||||||
* ++ `\toprule`, `\midrule` and `\bottomrule` structure the table.
|
|
||||||
|
|
||||||
@preview
|
@preview
|
||||||
{.thin-padding}
|

|
||||||
|
|
||||||
|
|
||||||
@slide(layout=wide-content)
|
@slide(layout=content-and-preview-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
minted
|
||||||
|
|
||||||
@title
|
@title
|
||||||
The entire table
|
External source code
|
||||||
|
|
||||||
@content
|
@content
|
||||||
``` {.hljs .lang-tex}
|
We can avoid redundancy by including source code directly from its source file.
|
||||||
\begin{table}[h]
|
|
||||||
\begin{tabular}{lrcl}
|
``` {.lang-tex .hljs}
|
||||||
\toprule
|
\section*{Simple Java Application}
|
||||||
Language & Author & Year & Version \\
|
\inputminted{java}{Test.java}
|
||||||
\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>
|
``` {.lang-java .hljs data-sourcefile="Test.java"}
|
||||||
|
public class Test {
|
||||||
<p data-category="Example">`\begin{tabular}{@{}lrcl@{}}` limits the row separators to the width of the table content</p>
|
public static void main(/*…*/) {
|
||||||
|
System.out.println(/*…*/);
|
||||||
|
}
|
||||||
@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
|
|
||||||
|
|
||||||
@content
|
|
||||||
If you need a table to be wider than a page, you can display it in landscape orientation:
|
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\usepackage{rotating}
|
|
||||||
```
|
|
||||||
|
|
||||||
``` {.hljs .lang-tex}
|
|
||||||
\begin{sidewaystable}[<position>]
|
|
||||||
\begin{tabular}{<column def.>}
|
|
||||||
% table content
|
|
||||||
\end{tabular}
|
|
||||||
\end{sidewaystable}
|
|
||||||
```
|
|
||||||
|
|
||||||
@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}(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
|
@preview
|
||||||
{.thin-padding}
|

|
||||||
|
|
||||||
|
|
||||||
@slide(layout=content-only)
|
@slide(layout=content-only-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
minted
|
||||||
|
|
||||||
@title
|
@title
|
||||||
More comfort
|
Themes and styles
|
||||||
|
|
||||||
@content
|
@content
|
||||||
The [Tables Generator](https://tablesgenerator.com/) is a wonderful tool to quickly create tables of different formats.
|
Optional parameters allow us to activate line numbers, automated line breaks, and syntax highlighting based on numerous color schemes.
|
||||||
|
|
||||||
[](https://tablesgenerator.com/)
|
``` {.lang-tex .hljs}
|
||||||
|
\usemintedstyle{monokai}
|
||||||
|
\begin{minted}[
|
||||||
|
linenos=true,
|
||||||
|
breaklines=true,
|
||||||
|
]{javascript}
|
||||||
|
% ...
|
||||||
|
\end{minted}
|
||||||
|
```
|
||||||
|
|
||||||
|
<span class="emoji">🔗</span> **[introduction](https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted)** and **[official documentation](https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf)**
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-and-preview-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
listings
|
||||||
|
|
||||||
|
@title
|
||||||
|
In-situ listings
|
||||||
|
|
||||||
|
@content
|
||||||
|
Within a dedicated environment:
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs}
|
||||||
|
\section*{Haskell Magic}
|
||||||
|
Squares of all even % …
|
||||||
|
\begin{lstlisting}[language=Haskell]
|
||||||
|
[x^2 | x <- [1..200], even x]
|
||||||
|
\end{lstlisting}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `listings` package does not provide an inline command.
|
||||||
|
|
||||||
|
@preview
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-and-preview-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
listings
|
||||||
|
|
||||||
|
@title
|
||||||
|
External source code
|
||||||
|
|
||||||
|
@content
|
||||||
|
Conveniently, also `listings` offers an import command:
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs}
|
||||||
|
\section*{Simple Java Application}
|
||||||
|
\lstinputlisting[language=Java]{Test.java}
|
||||||
|
```
|
||||||
|
|
||||||
|
``` {.lang-java .hljs data-sourcefile="Test.java"}
|
||||||
|
public class Test {
|
||||||
|
public static void main(/*…*/) {
|
||||||
|
System.out.println(/*…*/);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
@preview
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-only-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
listings
|
||||||
|
|
||||||
|
@title
|
||||||
|
Themes and styles
|
||||||
|
|
||||||
|
@content
|
||||||
|
`listings` does not provide any themes by default, but can be configured extensively.
|
||||||
|
|
||||||
|
``` {.lang-tex .hljs}
|
||||||
|
\begin{lstlisting}[
|
||||||
|
language=Java,
|
||||||
|
basicstyle=\footnotesize\ttfamily,
|
||||||
|
breaklines=true,
|
||||||
|
keywordstyle=\color{ForestGreen},
|
||||||
|
commentstyle=\color{DarkGray},
|
||||||
|
literate={ö}{{\"o}}1
|
||||||
|
]
|
||||||
|
% …
|
||||||
|
\end{lstlisting}
|
||||||
|
```
|
||||||
|
|
||||||
|
Have a look at the `\lstset` command for creating your own themes.
|
||||||
|
|
||||||
|
|
||||||
|
@slide(layout=content-only-with-category)
|
||||||
|
|
||||||
|
@category
|
||||||
|
listings
|
||||||
|
|
||||||
|
@title
|
||||||
|
Further resources
|
||||||
|
|
||||||
|
@content
|
||||||
|
* [introduction](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide) to the package
|
||||||
|
* official [documentation](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide)
|
||||||
|
* [`xcolor` package](https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX) for colors
|
||||||
|
* two [solarized themes](https://github.com/jez/latex-solarized) for `listings`
|
||||||
|
|
||||||
|
|
||||||
@slide(layout=task)
|
@slide(layout=task)
|
||||||
|
|
||||||
@task-number
|
@task-number
|
||||||
12
|
10
|
||||||
|
|
||||||
@title
|
@title
|
||||||
Typesetting tables
|
Listings with `minted`
|
||||||
|
|
||||||
@content
|
@content
|
||||||
* The list in file `exercises/tables/tables.tex` stores information on a few modules of the WIAI faculty.
|
* In the directory `exercises/source-code-listings` you can find a file named `Source.java`.
|
||||||
* Transform the list into a **table**.
|
* **Include** it in the file `source-code-listings.tex`. (Keep in mind that the file path is relative to the main LaTeX document, i. e., to `main.tex`.)
|
||||||
* The table shall have colums for the *name*, the *abbreviation* (Kürzel) and the *semester* of the lectures.
|
* Activate **syntax highlighting** by stating the programming language Java.
|
||||||
* Add a **column** with **center-aligned text** on the left side of the table in order to **number** the lectures.
|
* **Number** the code lines and add **line breaks**.
|
||||||
* Add a **caption** for the table.
|
* Use the **theme** `native`.
|
||||||
|
* Change the **background colour** to dark blue.
|
||||||
|
* Now only include **lines 5 to 7**.
|
||||||
|
* Delete the **spaces** at the beginning of the lines. (Hint: The documentation speaks of `autogobble`).
|
||||||
|
|
||||||
|
If you have questions, try to consult the documentation of the `minted` package.
|
||||||
|
|
||||||
|
@slide(layout=task)
|
||||||
|
|
||||||
|
@task-number
|
||||||
|
10
|
||||||
|
|
||||||
|
@title
|
||||||
|
Listings with `listings`
|
||||||
|
|
||||||
|
@content
|
||||||
|
* In the directory `exercises/source-code-listings` you can find a file named `Source.java`.
|
||||||
|
* **Include** it in the file `source-code-listings.tex`. (Keep in mind that the file path is relative to the main LaTeX document, i. e., to `main.tex`.)
|
||||||
|
* Activate **syntax highlighting** by stating the programming language Java.
|
||||||
|
* **Number** the code lines.
|
||||||
|
* Set the `basicstyle` to a proper mono-spaced font (`\ttfamily \small`)
|
||||||
|
* Change the **keyword color** to blue.
|
||||||
|
* Don't show special characters for **spaces in strings**.
|
||||||
|
|
||||||
|
If you have questions, try to consult the documentation of the `listings` package.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user