LaTeX/ Aufbau eines Dokuments

Aus Wikibooks
Zur Navigation springen Zur Suche springen


Der Sinn, einen Text zu verfassen, besteht hauptsächlich darin, dem Leser Ideen, Informationen oder Wissen zu vermitteln. Wenn der Text gut strukturiert ist, wird der Leser diesen besser verstehen. Spiegelt die drucktechnische Form die logische und semantische Struktur des Textes wider, kann der Leser die Struktur besser sehen und erfassen.

Im Gegensatz zu anderen Satz-Systemen muss LaTeX nur die logische und semantische Struktur des Textes bekannt gegeben werden. Von da an leitet LaTeX die drucktechnische Form des Textes anhand dieser Vorgaben und mehrerer Dokument-Klassen (document class) und Formattierungs-Vorlagen (style files) ab. Der Nutzer kann seine Dokumente mit Hilfe von verschiedenen hierarchischen Konstrukten wie Kapiteln (chapter), Abschnitten (section), Unterabschnitten (subsection) und Absätzen (paragraph) strukturieren.

Die document-Umgebung[Bearbeiten]

Nachdem die Dokument-Klasse deklariert ist, wird der Text des Dokuments zwischen zwei Kommandos geschrieben, welche den Beginn und das Ende des eigentlichen Dokumentes kennzeichnen.

\documentclass[11pt,a4paper,oneside]{report}
\begin{document}
...
\end{document}

...

Anstatt der drei Punkte würde der eigentliche Text geschrieben. Anfang und Ende des Textes müssen deswegen extra gekennzeichnet werden, da LaTeX hier darauf programmiert werden kann automatisch zusätzliche Aufgaben auszuführen (z.B. ein alternatives Layout verwenden oder einen Index zu erzeugen).


Ein nützlicher Nebeneffekt der Kennzeichnung ist, dass man Kommentare oder temporären Text unterhalb des \end{document} -Befehls speichern kann ohne dass LaTeX diesen zu verarbeiten versucht.

...
\end{document}
Vergiss nicht die weiteren Kapitel von Stephen King!

...

Die Präambel[Bearbeiten]

Die Präambel beinhaltet alles vom Beginn des Latex-Quelltests bis zum \begin{document}-Befehl. Normalerweise stehen hier Befehle, die sich auf das gesamte Dokument auswirken.

% simple.tex - Ein einfacher Artikel um die Dokumentstruktur darzustellen. \documentclass{article} \usepackage{mathptmx} \begin{document}

Die erste Zeile ist ein Kommentar (mit dem Prozentzeichen % ausgezeichnet). Der \documentclass-Befehl benötigt ein Argument, das in diesem Fall article ist, weil das die Art des zu erstellenden Dokuments darstellt. Es ist ebenfalls möglich eigene Dokumentarten zu erstellen, wie es oft von Zeitschriftenverlagen getan wird, die einfach eine class-Datei bereitstellen, die Latex anweisen, wie der Inhalt dargestellt werden soll. Momentan reicht jedoch die Standard-Artikelklasse aus. \usepackage ist ein sehr wichtiger Befehl, welcher Latex dazu bringt externe Makros zu verwenden. In diesem Fall verwenden wir mathptmx, was bedeutet, dass Latex die Postscript Times type 1 Schrift nutzen wird anstatt der standardmäßigen ComputerModern Schrift. Schließlich kommt noch das \begin{document}, welches streng genommen eigentlich kein Teil der Präambel ist. Aber es wird dennoch hier platziert, weil es das Ende der Präambel impliziert, da somit das eigentlich Dokument beginnt.

Top Matter[Bearbeiten]

Am Anfang der meisten Dokumente gibt es Informationen über das Dokument an sich, wie Titel und Datum, wie auch Informationen über die Autoren, wie Name, Adresse, E-Mail Adresse usw. Diese Arten von Informationen werden meist in LaTeX mit top matter bezeichnet. Auch, wenn es nicht explizit so genannt wird (es auch keinen \topmatter Befehl gibt), wird dieser Begriff häufig in der LaTeX Dokumentation verwendet.

Dazu ein einfaches Beispiel:

\documentclass[11pt,a4paper,oneside]{report}

\begin{document}
\title{How to Structure a LaTeX Document}
\author{Andrew Roberts}
\date{December 2004}
\maketitle
\end{document}
How to Structure a LaTeX Document

Andrew Roberts

December 3, 2004

Die \title, \author, and \date Befehle sind eigentlich selbst erklärend. Du packst einfach den Titel, Autor Namen und das Datum in die geschweiften Klammern nach dem jeweiligen Befehlaufruf. Die Angabe des Titels und Autors sind normalerweise verpflichtend (außer du möchtest keinen automatischen Titel von Latex generiert bekommen); Wenn du den Befehl \date auslässt, verwendet LaTeX das heutige Datum stattdessen. Die top matter werden immer mit dem Befehl \maketitle abgeschlossen, womit LaTeX weiß, dass diese vollständig sind, und es die Titelseite entsprechend den Informationen und der Klasse, der das Dokument angehört, generieren kann. Sollte LaTeX/Vorlage:Befehl weggelassen werden, wird die Titelseite nicht generiert.

Here is a more complicated example:

\title{How to Structure a \LaTeX{} Document}
\author{Andrew Roberts\\
  School of Computing,\\
  University of Leeds,\\
  Leeds,\\
  United Kingdom,\\
  LS2 1HE\\
  \texttt{andyr@comp.leeds.ac.uk}}
\date{\today}
\maketitle
How to Structure a LaTeX Document

Andrew Roberts
School of Computing,
University of Leeds,
Leeds,
United Kingdom,
LS2 1HE
andyr@comp.leeds.ac.uk}

December 3, 2004

as you can see, you can use commands as arguments of \title and the others. The double backslash (\\) is the LaTeX command for forced linebreak. LaTeX normally decides by itself where to break lines, and it's usually right, but sometimes you need to cut a line short, like here, and start a new one.

If there are two authors separate them with the \and command:

\title{Our Fun Document}
\author{Jane Doe \and John Doe} 
\date{\today}
\maketitle

Jane Doe               John Doe

December 3, 2012

If you are provided with a class file from a publisher, or if you use the AMS article class (amsart), then you can use several different commands to enter author information. The email address is at the end, and the \texttt commands formats the email address using a mono-spaced font. The built-in command called \today will be replaced with the current date when processed by LaTeX. But you are free to put whatever you want as a date, in no set order. If braces are left empty, then the date is omitted.

Using this approach, you can create only basic output whose layout is very hard to change. If you want to create your title freely, see the Title Creation section.

Abstract[Bearbeiten]

As most research papers have an abstract, there are predefined commands for telling LaTeX which part of the content makes up the abstract. This should appear in its logical order, therefore, after the top matter, but before the main sections of the body. This command is available for the document classes article and report, but not book.

\documentclass{article} \begin{document} \begin{abstract} Your abstract goes here... ... \end{abstract} ... \end{document}

By default, LaTeX will use the word "Abstract" as a title for your abstract, if you want to change it into anything else, e.g. "Executive Summary", add the following line in the preamble:

\renewcommand{\abstractname}{Executive Summary}

Sectioning Commands[Bearbeiten]

The commands for inserting sections are fairly intuitive. Of course, certain commands are appropriate to different document classes. For example, a book has chapters but an article doesn't. Here is an edited version of some of the structure commands in use from simple.tex.

\section{Introduction} This section's content... \section{Structure} This section's content... \subsection{Top Matter} This subsection's content... \subsubsection{Article Information} This subsubsection's content...

As you can see, the commands are fairly intuitive. Notice that you do not need to specify section numbers. LaTeX will sort that out for you! Also, for sections, you do not need to markup which content belongs to a given block, using \begin and \end commands, for example. LaTeX provides 7 levels of depth for defining sections:

Command Level Comment
\part{part} -1 not in letters
\chapter{chapter} 0 only books and reports
\section{section} 1 not in letters
\subsection{subsection} 2 not in letters
\subsubsection{subsubsection} 3 not in letters
\paragraph{paragraph} 4 not in letters
\subparagraph{subparagraph} 5 not in letters

All the titles of the sections are added automatically to the table of contents (if you decide to insert one). But if you make manual styling changes to your heading, for example a very long title, or some special line-breaks or unusual font-play, this would appear in the Table of Contents as well, which you almost certainly don't want. LaTeX allows you to give an optional extra version of the heading text which only gets used in the Table of Contents and any running heads, if they are in effect. This optional alternative heading goes in [square brackets] before the curly braces:

\section[Effect on staff turnover]{An analysis of the effect of the revised recruitment policies on staff turnover at divisional headquarters}

Section numbering[Bearbeiten]

Numbering of the sections is performed automatically by LaTeX, so don't bother adding them explicitly, just insert the heading you want between the curly braces. Parts get roman numerals (Part I, Part II, etc.); chapters and sections get decimal numbering like this document, and appendices (which are just a special case of chapters, and share the same structure) are lettered (A, B, C, etc.). You can change the depth to which section numbering occurs, so you can turn it off selectively. By default it is set to 2. If you only want parts, chapters, and sections numbered, not subsections or subsubsections etc., you can change the value of the secnumdepth counter using the \setcounter command, giving the depth level from the previous table. For example, if you want to change it to "1":

\setcounter{secnumdepth}{1}

A related counter is tocdepth, which specifies what depth to take the Table of Contents to. It can be reset in exactly the same way as secnumdepth. For example:

\setcounter{tocdepth}{3}

To get an unnumbered section heading which does not go into the Table of Contents, follow the command name with an asterisk before the opening curly brace:

\subsection*{Introduction}

All the divisional commands from \part* to \subparagraph* have this "starred" version which can be used on special occasions for an unnumbered heading when the setting of secnumdepth would normally mean it would be numbered.

If you want the unnumbered section to be in the table of contents anyway, use the \addcontentsline command like this:

\section*{Introduction} \addcontentsline{toc}{section}{Introduction}

Note if you use pdf bookmarks you will need to add a phantom section so that bookmark will lead to the correct place in the document:

\phantomsection \addcontentsline{toc}{section}{Introduction} \section*{Introduction}

For chapters you will also need to clear the page (this will also correct page numbering in the ToC):

\cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{Bibliography} \bibliographystyle{unsrt} \bibliography{my_bib_file}

The value where the section numbering starts from can be set with the following command:

\setcounter{section}{4}

The next section after this command will now be numbered 5.

Appendices[Bearbeiten]

The separate numbering of appendices is also supported by LaTeX. The \appendix macro can be used to indicate that following sections or chapters are to be numbered as appendices.

In the report or book classes this gives:

\appendix \chapter{First Appendix}

For the article class use:

\appendix \section{First Appendix}

Ordinary paragraphs[Bearbeiten]

Paragraphs of text come after section headings. Simply type the text and leave a blank line between paragraphs. The blank line means "start a new paragraph here": it does not mean you get a blank line in the typeset output. For formatting paragraph indents and spacing between paragraphs, refer to the Formatting section.

Table of contents[Bearbeiten]

All auto-numbered headings get entered in the Table of Contents (ToC) automatically. You don't have to print a ToC, but if you want to, just add the command \tableofcontents at the point where you want it printed (usually after the Abstract or Summary).

Entries for the ToC are recorded each time you process your document, and reproduced the next time you process it, so you need to re-run LaTeX one extra time to ensure that all ToC pagenumber references are correctly calculated. We've already seen how to use the optional argument to the sectioning commands to add text to the ToC which is slightly different from the one printed in the body of the document. It is also possible to add extra lines to the ToC, to force extra or unnumbered section headings to be included.

The commands \listoffigures and \listoftables work in exactly the same way as \tableofcontents to automatically list all your tables and figures. If you use them, they normally go after the \tableofcontents command. The \tableofcontents command normally shows only numbered section headings, and only down to the level defined by the tocdepth counter, but you can add extra entries with the \addcontentsline command. For example if you use an unnumbered section heading command to start a preliminary piece of text like a Foreword or Preface, you can write:

\subsection*{Preface} \addcontentsline{toc}{subsection}{Preface}

This will format an unnumbered ToC entry for "Preface" in the "subsection" style. You can use the same mechanism to add lines to the List of Figures or List of Tables by substituting lof or lot for toc.

To change the title of the TOC, you have to paste this command \renewcommand{\contentsname}{<New table of contents title>} in your document preamble. The List of Figures (LoF) and List of Tables (LoT) names can be changed by replacing the \contentsname with \listfigurename for LoF and \listtablename for LoT.

Depth[Bearbeiten]

The default ToC will list headings of level 3 and above. To change how deep the table of contents displays automatically the following command can be used in the preamble:

\setcounter{tocdepth}{4}

This will make the table of contents include everything down to paragraphs. The levels are defined above on this page.

The Bibliography[Bearbeiten]

Any good research paper will have a whole list of references. There are two ways to insert your references into LaTeX:

  • you can embed them within the document itself. It's simpler, but it can be time-consuming if you are writing several papers about similar subjects so that you often have to cite the same books.
  • you can store them in an external BibTeX file and then link them via a command to your current document and use a Bibtex style to define how they appear. This way you can create a small database of the references you might use and simply link them, letting LaTeX work for you.

In order to know how to add the bibliography to your document, see the Bibliography Management section.

Go-previous.svg Zurück zu Grundlagen | Go-up.svg Hoch zum Inhaltsverzeichnis | Go-next.svg Vor zu Fehler und Warnungen