Jump to content

LaTeX

From SDQ-Wiki
This page is a translated version of the page LaTeX and the translation is 100% complete.

Templates

Recommended Software

Online Platforms

Overleaf is a platform that allows users to create LaTeX documents directly in their browser.

  • Overleaf can be used free of charge in the Professional version by all KIT students and employees. [1]
  • Overleaf also provides a Git interface, allowing projects to be edited locally.
  • SDQ's document templates are available in the Overleaf Gallery.

Distributions

  • TeX Live: Distribution for various operating systems
  • MiKTeX: Distribution for Windows
  • MacTeX: Distribution for macOS

Editors

Tutorials and Help

BibTeX

For creating bibliographic references and bibliographies

Tips and Tricks

Avoiding Common Pitfalls

There are outdated macros and packages for LaTeX that should no longer be used. These and other deprecated practices are listed in the LaTeX2ε sins register. We have formulated additional guidelines for avoiding such common pitfalls here.

 Never End Paragraphs with \\

  • Paragraphs in LaTeX source code are separated by two line breaks in the source code. Only then are the template's paragraph formatting rules (spacing/indentation) applied.
  • The \\ command inserts a line break within a paragraph without introducing spacing or indentation. This disrupts the paragraph layout and should therefore never be used.

See also: https://de.overleaf.com/learn/latex/Line_breaks_and_blank_spaces#Reference_guide

 Avoid Using [h] for Float Environments

  • The [h] option should be avoided in float environments such as figure and table.
    • This option makes it more difficult for LaTeX's algorithms to find a good placement [2].
    • If you want to bypass automatic float placement entirely, it is better to use minipage together with \captionof [3].

Figures

Creation

  • For diagrams such as graphs, UML diagrams, and similar illustrations, TikZ is the most elegant solution, but it requires a significant learning effort.

Including Figures

  • Diagrams and tables created with external software should be included in a vector format.
    • Export them as PDF and include them in the document.
    • If the software only supports SVG export, they can easily be converted to PDF using Inkscape.

Referencing

  • In float environments such as figure and table, \caption{} must be called before \label{}. Otherwise, the wrong number may be referenced.
  • The hyperref package is recommended:
    • References in the generated PDF document become clickable.
    • The \autoref{} command automatically inserts the correct type of cross-reference, e.g. \autoref{introduction} → Section 2, \autoref{classdiagram} → Figure 2.

Spell Checking

  • Some LaTeX editors support automatic spell checking, which should be enabled by default.
  • Larger LaTeX documents can also be converted into Word documents using Pandoc, allowing users to take advantage of the extensive spelling and grammar checking features of LibreOffice or similar software.
  • In general, the guidelines for written work and the recommendations on scientific writing should always be followed.

Hyphenation and Line Breaks

In some cases, words are not recognized by the hyphenation algorithm and are therefore not hyphenated. This can result in unsightly gaps or words extending beyond the margins.

Hyphens

Words containing hyphens (e.g. Travelling-Salesman Problem) should be written using the extdash package as follows: Travelling\-/Salesman\-/Problem.

Typewriter Text (texttt)

Text within \texttt{} is not hyphenated by default because no line-break characters are defined for it. Instead, a custom macro can be used [4]:

\newcommand\code[1]{\texttt{\hyphenchar\font=45\relax #1}}

Tables Spanning Multiple Pages (longtable)

The "longtable" package can be used to create tables that span multiple pages. It is important to place the \captions and \labels in the correct positions and to ensure that the table header is repeated on each subsequent page.

\begin{longtable}{lll}
  \caption{Table caption (for the list of tables)} \\
  \toprule
  \emph{Header1} & \emph{Header2} & \emph{Header3} \\
  \midrule
  \label{tab:myTable}
  \endfirsthead
  \caption*{Table caption (for subsequent pages)}\\
  \toprule
  \emph{Header1} & \emph{Header2} & \emph{Header3} \\
  \midrule
  \endhead
  \multicolumn{3}{r}{{...}continues on next page} \\
  \endfoot
  \endlastfoot
  % table content goes here
  \bottomrule
\end{longtable}

The example shows a three-column longtable with a table header and a repeated header (ctd.). Only one (!) table entry appears in the list of tables. The note at the end of the table ("continues on next page") is, of course, optional, but it helps guide the reader.

Changing the Page Layout

Some publishers (e.g. ACM) require the Letter paper size (216 mm × 279 mm or 11 in × 8.5 in). This can easily be achieved using the `geometry` package.

\setlength{\paperheight}{11in}
\setlength{\paperwidth}{8.5in}
\usepackage[pass]{geometry}

Adding Visible Notes, Comments, or TODOs

The following commands can be used to insert notes, comments, or TODO markers into the PDF. They can also be hidden again by simply toggling a single setting in one place.

There are many packages available to address this issue. The following solution has worked well for us. Feel free to add other solutions here.

Using ifdraft, draftwatermark, and mdframed

Include the following packages:

%% 
%% for draft mode
%%
\usepackage{ifthen}
\usepackage{ifdraft}

\ifdraft{
\usepackage{draftwatermark}
\SetWatermarkAngle{50}
\SetWatermarkLightness{0.9}
\SetWatermarkScale{1}
}{}
\usepackage[framemethod=latex,backgroundcolor=green!15!white]{mdframed}

After \begin{document}, define the commands to be used for notes. You can also define a separate command for each author, with a distinct color for each one.

\newcommand{\todonote}[1]{\ifdraft{\begin{mdframed}[backgroundcolor=red!15!white]
\textbf{\textcolor{red}{TODO: }} #1
\end{mdframed}}{}}

To switch the document to draft mode, simply add draft to the options of the documentclass or enable it in the editor, for example, as shown below for an ACM paper:

\documentclass[sigconf, natbib=false, draft]{acmart}

You can then add a note to the text using \todonote{my comment}.

Links