Home Business & Other LaTeX Cookbook - Second Edition

LaTeX Cookbook - Second Edition

By Stefan Kottwitz
books-svg-icon Book
eBook $39.99 $27.98
Print $49.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $39.99 $27.98
Print $49.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Chapter 1: Exploring Various Document Classes
About this book
The second edition of LaTeX Cookbook offers improved and additional examples especially for users in science and academia, with a focus on new packages for creating graphics with LaTeX. This edition also features an additional chapter on ChatGPT use to improve content, streamline code, and automate tasks, thereby saving time. This book is a practical guide to utilizing the capabilities of modern document classes and exploring the functionalities of the newest LaTeX packages. Starting with familiar document types like articles, books, letters, posters, leaflets, and presentations, it contains detailed tutorials for refining text design, adjusting fonts, managing images, creating tables, and optimizing PDFs. It also covers elements such as the bibliography, glossary, and index. You’ll learn to create graphics directly within LaTeX, including diagrams and plots, and explore LaTeX’s application across various fields like mathematics, physics, chemistry, and computer science. The book’s website offers online compilable code, an example gallery, and supplementary information related to the book, including the author’s LaTeX forum, where you can get personal support. By the end of this book, you’ll have the skills to optimize productivity through practical demonstrations of effective LaTeX usage in diverse scenarios.
Publication date:
February 2024


Exploring Various Document Classes

Documents vary in shape and size, with distinct formats, sections, and designs. You can use LaTeX for any kind of document type. This chapter is packed with recipes suitable for an assortment of document types.

Specifically, we will cover the following:

  • Preparing your LaTeX tools
  • Writing a short text
  • Developing a thesis
  • Designing a book
  • Creating a presentation
  • Designing a curriculum vitae (CV)
  • Writing a letter
  • Producing a leaflet
  • Building a large poster

Throughout this chapter, you will get step-by-step instructions, tips, and tricks to help you create each document type easily. By the end of this chapter, you’ll have a solid foundation in creating a wide range of documents using LaTeX.

All example code is available on GitHub for download. You can find all examples of this chapter at https://latex-cookbook.net/chapter-01, where you can also compile them online.


Preparing your LaTeX tools

LaTeX has been around for many years. Over time, developers and authors contributed numerous extensions to its code base.

Such an extension could be one of the following:

  • Document class: A base file that is the frame of your document. It provides various formatting styles and usually comes with meaningful default settings, which can be changed via options when loading it. It often provides commands for authors to modify settings.
  • Package: A style file with a specific purpose that you can load in addition to the document class. Packages can be combined. Most of the time, we load many of them by executing the \usepackage command.
  • Bundle: A set of closely related packages or classes. In our next recipe, Writing a short text, we will get to know some bundles.
  • Template: A document with dummy text that you can take as a starting point and fill in your headings, texts, formulas, and images. We will look at templates in another recipe, Developing a thesis.

Those add-ons are incredibly valuable. They are one reason for the enduring success of LaTeX. We all agree that learning LaTeX can be challenging with its steep learning curve. However, if you don’t reinvent the wheel and start with a good template or class and a quality set of packages, you can quickly achieve great results.

The purpose of this book is to assist you in this regard.

Getting ready

To be able to work with LaTeX, you need to have the following installed on your computer:

  • TeX and LaTeX software, called a TeX distribution
  • A LaTeX editor, though you could use any text editor
  • A PDF viewer for seeing the final output

If you already have those installed, great! In that case, you can skip the following paragraphs and immediately proceed to the first recipe.

A PDF reader is probably already installed on your computer, such as Adobe Reader or the Preview app on the Mac. Furthermore, most editors come with an integrated PDF previewer. So, let’s have a look at TeX software and editors.

TeX and LaTeX distributions

There are TeX and LaTeX software collections ready to use and easy to install. Their websites provide install and update information. You may choose the download site for your system:

  • TeX Live: On https://tug.org/texlive, you can find download information and installation instructions for the cross-platform TeX distribution, which runs on Windows, Linux, Mac OS X, and other Unixes. It is supported by the TeX Users Group (TUG).
  • MacTeX: This is based on TeX Live and has been significantly customized for Mac OS X. Essential information is available at https://tug.org/mactex.
  • MiKTeX: A download and documentation for the Windows-specific distribution can be found at https://miktex.org.

If you own a Mac, I suggest selecting MacTeX. Otherwise, I recommend using TeX Live because the TUG provides excellent development and support.

Describing the setup is outside the scope of this book. For TeX Live, you can find a step-by-step explanation with screenshots in the LaTeX Beginner’s Guide by Packt Publishing. Generally, you can find detailed setup instructions when you visit the aforementioned internet addresses.

Finally, on Linux systems, such as Ubuntu, Debian, Red Hat, Fedora, and SUSE versions, a TeX Live-based software package is usually available via the operating system repositories. While it’s usually not as up to date as an installation via the TeX Live website or a TeX Live DVD, it’s straightforward to install using the Linux package manager you deploy to install any software there.

I strongly recommend choosing a complete LaTeX installation containing all available software, packages, and fonts. At the time of writing, it typically requires around 8 GB of disk space, but it guarantees you won’t encounter any missing packages or dependencies later.

LaTeX editors

There are many LaTeX editors, from small and quick to feature-rich editors. The TeX distributions already provide the fine editor TeXworks, which I use myself. You set it up with TeX or a package manager on Linux, and it can be downloaded from https://tug.org/texworks.

You can find a collection of LaTeX editors and additional software at https://latex.net/software. You may look for alternative editors running on your operating system there.

Using LaTeX online

A complete online cloud solution for LaTeX saves you from installing LaTeX software yourself. The most advanced one is called Overleaf and comes with an online LaTeX editor that runs in a web browser, so you can use it even on tablets and smartphones for storing, editing, and compiling even large LaTeX projects. You can find it at https://www.overleaf.com. While registration is necessary, basic access to the platform is free. Some advanced features require purchasing a subscription, but it’s worth noting that many universities and institutions partner with Overleaf and provide enhanced licenses for their students and employees.

The LaTeX Beginner’s Guide explores Overleaf in more detail; you can find this section online at https://latexguide.org/overleaf.

If you need help setting up and using LaTeX or an editor, you can visit a LaTeX web forum such as https://latex.org. In Chapter 12, Getting Support on the Internet, you can find their addresses and how to use them. You can also meet me there and ask me and our fellow forum users any LaTeX-related questions.

Once you have done the installation or online setup, you can start with a LaTeX recipe from the following sections.

See also

Many LaTeX tutorials available on the internet can help you with the first steps. I recommend looking at the following:

  • https://learnlatex.org covers the most essential LaTeX basics in short lessons in 10 languages. It is very modern and comes with an online compiler for its examples.
  • https://texdoc.org/pkg/lshort is the web link for The not so short introduction to LaTeX2e, a famous introductory text. It has been translated into more than 20 languages, available at https://ctan.org/pkg/lshort.
  • https://www.overleaf.com/learn takes you to the Overleaf knowledge base with various guides and many articles about LaTeX.
  • https://en.wikibooks.org/wiki/LaTeX takes you to the LaTeX Wikibook, a collaboratively created extensive guide.
  • https://www.dickimaw-books.com/latex/novices contains the free introductory book LaTeX for Complete Novices by Nicola L. C. Talbot. It is somewhat dated but OK for the first steps.
  • https://latex2e.org hosts the Unofficial reference manual for LaTeX, an excellent resource whenever you need to know how to use specific LaTeX commands, environments, arguments, and syntax in general.
  • https://latexguide.org is the website for the LaTeX Beginner’s Guide, with a sample chapter, all code examples by chapter, reviews, and additional information in case you’re considering buying a modern book on paper or in electronic format.

If you still need to learn LaTeX, read one of the guides, and you will then be well prepared to get the best out of this book.


Writing a short text

While LaTeX is excellent for large documents, it’s as useful for smaller ones, and you get all the features to work with. Writing down homework or producing a seminar handout, for example, doesn’t need book-like chapters, and the layout would not be very spacy. So, we will choose a document class that suits it best.

Class bundles cover commonly used document types. Every LaTeX installation contains a base bundle with standard classes. There is a class file for articles, one for books, one for reports, one for letters, and more. It is stable stuff; it has stayed the same for many years. It can be sufficient if you don’t care about the latest style. It would run even on a 10-year-old LaTeX installation.

In this recipe, we will use a class of the KOMA-Script bundle. This is a set of document classes and packages designed initially to replace the standard classes and provide more features. In contrast to the stable base bundle, KOMA-Script has been extensively developed in recent years. It has become feature-rich and has an excellent user interface. Parts of its functionality are provided in packages that can be used together with other classes as well. You can identify KOMA-Script classes and packages by the scr prefix. This prefix stands for Script, which was the initial name of this bundle.

How to do it...

We will start with a complete small document, already using various features. This can be your template, where you can fill in your own text later.

While we go through the document step by step, you may open the complete code directly with your editor, so you don’t need to type it. It is contained in the code bundle available on the book’s page at https://www.packtpub.com and https://latex-cookbook.net:

  1. Create a .tex document in the editor of your choice. Start with a document class. We will use the scrartcl KOMA-Script class with A4 paper size, a base font size of 12 pt, and inter-paragraph space instead of default paragraph indentation:
  2. Begin the document:
  3. By running this command, you let LaTeX print a table of contents:
  4. Start a section without numbering:
  5. Add some text:
    This document will be our starting point for simple
    documents. It is suitable for a single page or up to
    a couple of dozen pages.
    The text will be divided into sections.
  6. Start an automatically numbered section with some text:
    \section{The first section}
    This first text will contain
  7. Add a bulleted list using an itemize environment. Each list item starts with an \item command. Using the \ref{label} command, we will already refer to labels we will create later:
      \item a table of contents,
      \item a bulleted list,
      \item headings and some text and math in section,
      \item referencing such as to section
        \ref{sec:maths} and equation (\ref{eq:integral}).
  8. Continue with the text, and start another numbered section:
    We can use this document as a template for filling
    in our own content.
    \section{Some maths}
  9. Set a label so that we can refer to this point when we would like to refer to this section:
  10. Continue with the text. We start using some math expressions in the text. We mark them by enclosing them in parentheses with a prefixing backslash as follows:
    When we write a scientific or technical document, we
    usually include math formulas. To get a brief glimpse
    of the look of maths, we will look at an integral
    approximation of a function \( f(x) \) as a sum with
    weights \( w_i \):
  11. Write a math equation using the equation environment. Again, place a label:
      \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
      \sum_{i=0}^n w_i f(x_i)
  12. End the document:
  13. Compile the document. Do it twice so that the references work. The first page of the output will be as follows:
Figure 1.1 – A document with sections, math, and referencing

Figure 1.1 – A document with sections, math, and referencing

How it works...

In the first line, we loaded the scrartcl document class. In square brackets, we set options for specifying an A4 paper size with the oneside option for one-sided printing and a font size of 11 pt. Finally, we chose to have a full line between paragraphs in the output to distinguish paragraphs easily by adding the parskip=full option.

The default setting is no space between paragraphs but a small indentation at the beginning of a paragraph. Remove the parskip option to see it. We chose a paragraph skip because many people are used to it when working with emails, while indentation costs line space, a precious resource on small electronic devices.

Without further ado, we began the text with a table of contents.

While the \section command starts numbered sections, we can have an unnumbered section by the starred \section* version. However, we used the \addsec KOMA-Script command for the first unnumbered section. That’s because contrary to \section*, the \addsec command generates an entry in the table of contents.

The empty line in step 5 tells LaTeX to make a paragraph break. Note that a simple line break in the LaTeX code doesn’t cause a line break or paragraph break in the output.

As bulleted lists are an excellent way to present points clearly, we used an itemize environment in step 7. Environments start with a \begin command and are finished by an \end command.


If you want a numbered list, use the enumerate environment.

An equation environment has been used to display an automatically numbered formula. We used a \label command to set an invisible anchor mark so that we could refer to it using its label name by the \ref command and get the equation number in the output.

Choosing label identifiers

It is a good practice to use prefixes to identify kinds of labels, such as eq:name for equations, fig:name for figures, tab:name for tables, and so on. Avoid special characters in names, such as accented characters.

In step 10, small formulas within text lines have been enclosed in \( ... \), which provides inline math mode. Dollar symbols, such as $ ... $, can be used instead, making typing easier. However, the parentheses clarify where the math mode starts and ends, which may be beneficial when many math expressions are scattered in the text, and the “dollar syntax” is old TeX syntax.

Why did we have to compile it twice? When you use the \label command, LaTeX writes that position to the .aux file. In the next compiler run, the \ref command can read this and put the correct reference into the text.

For further information on math typesetting, refer to Chapter 10, Writing Advanced Mathematics, specifically to the Fine-tuning a formula recipe.

See also

The part of the document before \begin{document} is called the preamble. It contains global settings. Adding a few lines to our document preamble can improve and modify our document’s general appearance. Chapter 2, Tuning the Text, starts with beneficial additions to the preamble that are also useful with small documents.

In Chapter 3, Adjusting Fonts, you can find recipes for changing an entire document’s fonts or specific elements.

For further customization tasks, such as modifying page layout, adding headers and footers, and changing sectioning title font, refer to the Designing a book recipe in the current chapter. We will look at such settings on the occasion of a book example.


Developing a thesis

When you write a large document such as a thesis, you have two main choices: choose a ready-made template or set up your own document environment. If you have little time and need to start your thesis fast, a template can come to the rescue.

Beware of outdated and questionable templates found somewhere on the internet. Look first at the date and at user opinions, such as in web forums. The age of a template is not a problem in itself, as LaTeX can run it the same way when it’s been written. However, LaTeX developed, and better solutions came up over time. Legacy code may not benefit from it.

Some universities provide their own template. That may be OK because requirements would be met for sure; just check if it can be improved – for example, by replacing obsolete packages with recommended successors.

An excellent source for checking the quality of a template is the guide to obsolete commands and packages in LaTeX2e; people call it l2tabu. You can open the English version by typing texdoc l2tabuen at Command Prompt or at https://texdoc.org/pkg/l2tabuen.

To be clear, the LaTeX base is stable and solid, but there are changes in community-contributed packages.

In the previous recipe, Writing a short text, we took a bottom-up approach and built a document from scratch, adding what we desired. Now, we will go top-down: let’s use and understand a complete template, removing what we don’t need.

As we need to choose a template now, let’s take a real gem. The ClassicThesis package by Prof. André Miede is a thesis template of excellent quality. The design follows the book classic The Elements of Typographic Style by Robert Bringhurst; we will see some particular points later in this recipe. Its implementation is thoughtful and modern. Initially written in 2006, it’s also maintained today and shipped with TeX distributions.

Getting ready

Though the ClassicThesis package may already be installed on your TeX system, named classicthesis.sty, the whole template is an archive of files that should go into your working directory.

Download the ClassicThesis archive from the following Comprehensive TeX Archive Network (CTAN) address: https://ctan.org/pkg/classicthesis.

Instead of fetching single files, choose to download them as a .zip file. Unzip it to where you keep your personal documents in its own directory. This directory will be your thesis directory.

This package provides a ready-made structured filesystem of the main document, style file, settings file, and document parts such as abstract, foreword, and chapters in dedicated files. You can edit all files and fill in your own text.

The ClassicThesis.tex file is the main document. Its filler text is the template’s manual; this allows us to compile it immediately to look at the output design. Also, you can verify that your TeX installation can handle it if you need to install additional packages.

How to do it...

After unzipping, your directory will have this structure:

Figure 1.2 – The directory structure of the ClassicThesis template

Figure 1.2 – The directory structure of the ClassicThesis template

Now, follow these steps:

  1. Rename or copy the ClassicThesis.tex file and choose your own name, such as MyThesis.tex, but keep it in the same directory.
  2. Open the main document, MyThesis.tex, and look around to get a feeling of the structure. Compile it for testing at least twice to get correct referencing so that you know that this starting point works.
  3. You can review and edit the settings in the main file, MyThesis.tex, and in the classicthesis-config.tex configuration file. On the following pages, we will examine that content.
  4. Open the existing .tex files, such as Abstract.tex and Chapter01.tex, with your editor. Remove the filler text and type in your own text. Add extra chapter files as needed, and include them in the main file, MyThesis.tex, as well. The structure is given; the technical part of the editing is like cloning files and copying lines; all you need to focus on is the actual thesis content now.

Don’t worry if the font or margins don’t please you yet. You can change the layout at any time. Let’s take a closer look now, and then you will know how.

How it works...

We will now look at the functional lines of the main file, MyThesis.tex.

The document preamble starts as follows:

\documentclass[ twoside,openright,titlepage,                numbers=noenddot,headinclude,                footinclude,cleardoublepage=empty,                abstract=on,BCOR=5mm,paper=a4,                fontsize=11pt                ]{scrreprt}\input{classicthesis-config}

The template is built on the scrreprt KOMA-Script class. KOMA-Script as a LaTeX bundle is described in the first recipe of the current chapter, Writing a short text.

You can change the pre-set options to those you need, such as font size or BCOR binding correction. There are many class options for adjusting the layout. You can read about them in the KOMA-Script manual, such as by running texdoc koma-script at the command line or at https://texdoc.org/pkg/koma-script. In our next recipe, Designing a book, we will discuss some of them in more depth.

Loading of packages and all the remaining settings is done in a single file, classicthesis-config.tex. We will look at it later in this recipe.

The document body starts with the following text:


The \frenchspacing command means that there’s only a single space following the punctuation after a sentence. LaTeX puts extra space between sentences by default, or if you enter the \nonfrenchspacing command.

The language is set to American English, which is essential for American hyphenation. Actually, you would need the \selectlanguage command only if you need to switch between languages.

We start with Roman page numbers. The plain page style means we have no page headers for now, while page numbers are centered in the page footer.

Then, we see the front matter, which is the part of the document where the formal parts before the actual content go:


Each commonly required part of the front matter has its own file. Just edit the file as needed, comment out using a % sign at the beginning of a line, or remove what you don’t need. The \cleardoublepage command ends a page but also ensures that the next page starts on the right-hand side. This can mean inserting an empty page if necessary – that is, a double-page break. It would not happen if you changed the twoside option to oneside, so you could keep that \cleardoublepage command, which would act like a \clearpage command when the oneside option was set.

Finally, we get the main matter:

\cleardoublepage\pagestyle{scrheadings}\pagenumbering{arabic}\cleardoublepage\part{Some Kind of Manual}\label{pt:manual}\include{Chapters/Chapter01}\cleardoublepage\ctparttext{You can put some informational part  preamble text here...}\part{The Showcase}\label{pt:showcase}\include{Chapters/Chapter02}\include{Chapters/Chapter03}

In the main matter, the page style is set to scrheadings, and we use Arabic page numbers. The \pagenumbering command resets the page number to 0.

The thesis is divided into parts. Each one is split into chapters. You can omit the \part lines if your highest sectioning level should be the chapter level.

Each chapter gets its own .tex file in the Chapters subdirectory, so you can easily handle a massive text. Furthermore, you could use the \includeonly command to typeset just selected chapters to speed up writing.

Finally, the main document ends with the back matter:


The \appendix command resets the sectioning counters and changes to alphabetic numbering; the following chapters will be numbered by A, B, and so on. As with the front matter, the appendix parts are divided into several files.

Let’s take a look at the configuration file. Open classicthesis-config.tex. It would take too much space in the book, so let’s just see some sample lines:

\newcommand{\myTitle}{A Classic Thesis Style\xspace}\newcommand{\myName}{Andr\'e Miede\xspace}\newcommand{\myUni}{Put data here\xspace}\newcommand{\myLocation}{Darmstadt\xspace}\newcommand{\myTime}{January 2024\xspace}

Here, you can fill in your own data. Besides being printed on the title page, this data will be used as metadata for the generated PDF document. There are more supported macros at this place, such as \mySubtitle, \myProf, and many more. The \xspace command takes care of proper spacing after such a macro, inserting a space when there’s no punctuation mark following it.

There’s more...

As mentioned, this template contains design decisions inspired by the book The Elements of Typographical Style by Robert Bringhurst. The most notable are as follows:

  • It doesn’t use bold fonts – small caps or italics elegantly emphasize what’s important.
  • The text body is not very wide, allowing reading comfortably without the eyes jumping too wide from the right back to the left. So, we have wide margins, which can be used for notes.
  • The table of contents is not stretched to get right-aligned page numbers. To quote the author: “Is your reader interested in the page number, or does she want to sum the numbers up?” That’s why the page number follows the title.

Explore the classicthesis-config.tex file further to make modifications. As in the previous recipe, we apply document-wide changes within the preamble; this file is the place for doing it.

We will take a look at the selected lines of that configuration file.

Getting a right-justified table of contents

The design is not set in stone; you may adjust a lot. Look at the very beginning of classicthesis-config.tex:

\PassOptionsToPackage{  drafting=true,  tocaligned=false,  dottedtoc=false,  eulerchapternumbers=true,  linedheaders=false,  floatperchapter=true,  eulermath=false,  beramono=true,  palatino=true,  style=classicthesis}{classicthesis}

Here, you can find the options for the actual classicthesis package. For example, if you would like to see the page numbers in the table of contents right aligned, set the dottedtoc option to true. These and further options are documented in the template’s manual available by executing the texdoc classicthesis command or at https://texdoc.org/pkg/classicthesis.

Changing the margins

To fulfill requirements on page margins or implement your layout ideas, you can specify exact page dimensions by loading the geometry package. Here’s an example:

\usepackage[inner=1.5cm,outer=3cm,top=2cm,bottom=2cm,  bindingoffset=5mm]{geometry}

Here, you can also provide a value for the space you may lose by the binding and all margins you would like. It’s a good practice to have a visible inner margin set to half the value of the outer one because margins would be added in the middle. For single-sided printing, with oneside options, call the margins left and right.

Place such a line at the end of classicthesis-config.tex so that it will override previously made original settings.

Modifying the layout of captions

In the classicthesis-config.tex file, you can also change the appearance of captions of figures and tables. This is the default setup in that file:


Here, the template loads the caption package. The \RequirePackage command is similar to the \usepackage command except that it can be used before the \documentclass command. The caption package provides many features for fine-tuning captions. With this setting, captions have a smaller font than regular text. By adding simple options, you can further adjust the appearance; for example, by adding the option labelfont=it, you would get italic caption labels. Refer to the caption package manual at https://texdoc.org/pkg/caption to learn more.


While the caption package is a general solution working with most classes, including KOMA-Script, the latter now offers extended integrated caption features.

Centering displayed equations

Another option is responsible for the alignment of displayed equations:


With ClassicThesis, displayed equations will be left aligned. The fleqn option is switching to this alignment. If you want to restore the default behavior centering the equations, remove that first line that passes the option or comment it out. But keep the second line, which loads the amsmath package, as this is the de facto standard package for typesetting mathematics in LaTeX.

See also

You can find many recipes for content elements in the following chapters for your thesis. Especially for a beautiful thesis, elegant tables are of great value, so you may look at the Designing a legible table recipe in Chapter 4, Creating Tables.

At https://latextemplates.com, you can find a collection of excellent templates, including thesis templates.

Overleaf provides hundreds of thesis templates at https://www.overleaf.com/latex/templates/tagged/thesis, including templates of universities, so check out descriptions and tags for your university’s name.


Designing a book

A book can be a large document, so we can take a similar approach to the previous recipe. Refer to that recipe to see how to split your document into handy files and how to organize the directory structure.

Commonly, books are printed two-sided. In contrast to articles, they are divided into chapters, which start on right-hand pages, have pretty spacy headings, and often a page header showing the current chapter title. Readability and good typography are essential, so you would hardly find books with an A4 paper size, double line space, and similar specs, which some institutes expect of a thesis. That’s why we got dedicated book classes with meaningful default settings and features.

How to do it...

As the Writing a short text recipe explains, our choice will be a KOMA-Script class; this time, it has the name scrbook.

Follow these steps:

  1. Start with the scrbook class and suitable options for paper and font size:
  2. Choose a font encoding with the following command; use T1, which is good for European, English, or American texts:
  3. If you want a non-default font, load it; here, we chose Latin Modern:
  4. We will load the blindtext package for getting English dummy texts; it also requires loading the babel package with English settings:
  5. Load the microtype package for better text justification:
  6. By running the following command, you can switch off additional space after sentence punctuation:
  7. Begin the document:
  8. Provide a title, a subtitle, an author name, and a date. You can also set an empty value if you don’t want to have something in that titling field:
    \title{The Book}
    \subtitle{Some more to know}
    \author{The Author}
  9. Let LaTeX print the title page:
  10. Print out the table of contents:
  11. In addition to chapters, we will divide this book into parts, so start one:
    \part{First portion}
  12. Start a chapter with a heading. Having text before another heading comes is nice, so let’s have some:
    \chapter{The beginning}
    Some introductory text comes here.
  13. As in our first recipe, add a section and text and another part with a chapter and sections. Using the \Blindtext command, you can generate long dummy text; use the \blindtext command to get shorter dummy text. The \appendix command switches to alphabetic numbering:
    \section{A first section}
    Dummy text will follow.
    \section{Another section}
    \chapter{An addendum}
    \section{Section within the appendix}
  14. End the document:
  15. Let your editor compile the text to PDF. You will get a 13-page book document with A5 paper size, a title page, part pages, chapter, section headings, and filler text.

    Take a look at a sample page:

Figure 1.3 – Page 7 of the sample book with chapter and section headings

Figure 1.3 – Page 7 of the sample book with chapter and section headings

Note the headings in a sans-serif font. This is an intentional default setting in KOMA-Script classes, which makes the headings lighter than the standard LaTeX big, bold, and serif headings. You know – the traditional look.

Now, you can fill in your own text, add chapters and sections, and add features described later in this recipe.

How it works...

At first, we loaded the scrbook class, made explicitly for writing books. So, it is ready for two-sided printing with meaningful margins and pleasing proportions of headings and text.

Besides the class’s default settings, we chose a font size of 11 pt and A5 paper size, which is handy for a book. The pagesize=auto option is essential here: it ensures that the A5 printing area will be taken over to the PDF page size.

Then, we did the following things, which will be explained in more detail at the beginning of Chapter 2, Tuning the Text:

  • Chose the T1 font encoding when loading the fontenc package
  • Selected the high-quality Latin Modern T1 supporting font set by loading the lmodern package
  • Loaded the babel package with support for English
  • Used the microtype package for getting finer typography

The last package we loaded was blindtext. You don’t need it in your final document; here, it will serve us to provide filler text. Using such dummy text, we can get a better idea of the final result already before writing the actual content.

Finally, we switched to the so-called French spacing, which we already saw in the thesis recipe. Remember – this means that after ending a sentence, we will get a standard interword space, not a wider space.

There’s more...

You can change the layout of the book in many ways. Choose your settings at the beginning, or even better: don’t hesitate and start writing your content – once you get a decent amount of text, you can better see the effect of layout changes. You can do that at any time. Let’s take a look at some design ideas.

Changing the page layout

When a book is bound after printing, this binding can cost space; less of the inner margin may be visible. You can specify a binding correction to compensate for and preserve layout proportions. So, if you see 5 mm less of the inner margin after binding, add BCOR=5mm as a class option at the beginning. A similarly produced book may give you an idea about a good value.

The actual text area has the same ratios as the page itself. This is automatically done by a dividing construction, described in the KOMA-Script manual. That’s really worth reading. You can open it by typing texdoc scrguien at Command Prompt or online at https://texdoc.org/pkg/scrguien. This abbreviation comes from scr for the original package name (Script), gui for guide, and en for English, and obviously from the ancient limit of 8 characters per filename in older filesystems.

Besides those page and text area ratios, the result shows a bottom margin twice as high as the top margin, and an outer margin with the double width of the inner margin. Imagine an opened book: the inner margins together appear with the same space as an outer margin. Sometimes, people make the mistake of thinking that the inner margin should be much bigger because of the binding, but that’s done by raising BCOR as previously. In Chapter 2, Tuning the Text, you can use the Visualizing the layout recipe to inspect and understand the margins.

If you want a more extensive text area, which means narrower margins, you can keep the ratios as described. Just raise the division factor of the mentioned internal construction and take a look to see if it would suit you. For example, set the DIV=10 class option. Higher values are possible. That’s a safe and easy way to preserve sane layout proportions.

To sum up, our example with 5 mm binding loss and pretty narrow margins could start like this:

\documentclass[fontsize=11pt,paper=a5,pagesize=auto,  BCOR=5mm,DIV=12]{scrbook}

Alternatively, you could freely choose text and margin dimensions when requirements by the publisher or institute need to be met. This can be done by loading the classic geometry package with the desired measurements, as we saw in the Writing a thesis recipe:

\usepackage[inner=1.5cm,outer=3cm,top=2cm,bottom=4cm,  bindingoffset=5mm]{geometry}

Designing a title page

You can create your own title page to present more information in a style you desire. Let’s look at an example that shows some handy commands for it.

Remove the \maketitle command. You can do the same with the \title, \subtitle, \author, and \date commands. Instead, put this titlepage environment right after \begin{document}:

\begin{titlepage}  \vspace*{1cm}  {\huge\raggedright The Book\par}  \noindent\hrulefill\par  {\LARGE\raggedleft The Author\par}  \vfill  {\Large\raggedleft Institute\par}\end{titlepage}

The titlepage environment creates a page without a page number on it. We started with some vertical space using the \vspace* command. The \vspace command adds vertical space, which can be of a positive or a negative value. Here, note the star at the end: this way of calling \vspace also works at the beginning of a page, where a simple \vspace instance would be ignored. That default behavior prevents undesired vertical space at the top of a page, which initially may have been intended as space between texts.

We enclosed each line in curly braces. This is also called grouping, and it is used to keep the effect of changes, such as the font size, local within the braces. In each line, we did the following:

  • Switched to a specific font size
  • Chose left or right alignment
  • Wrote out the text
  • Ended with a paragraph break

The \par command is equivalent to an empty line in the input. Sometimes, people use it to keep the code compact, such as here. We must end the paragraph before the font size changes because that size defines the space between lines. Hence, we ended the paragraph before we closed the brace group. It’s good to keep this in mind for when texts are longer.

Our only non-text design element is a modest horizontal line with the \hrulefill command. The preceding \noindent command just prevents an undesired paragraph indentation, so the line really starts at the very left.

\vfill inserts stretching vertical space, so we got the last line pushed down to the title page bottom. If you used several \vfill commands on the same page, the available vertical space would be divided and distributed equally between them.

We took this scenario to show some commands for positioning text on a page. You can experiment with the \vspace and \vfill commands and their horizontal companions, \hspace and \hfill. Just avoid using such commands to “fix” local placement issues in the document when it would be better to adjust a class or package setting document-wide. If at all, don’t make such tweaks until the final stage.


The titlepages package provides 40 example title pages in various designs with complete LaTeX source code. You could choose one, use it, and customize it.

Adding a cover page

The title page, which we produced previously, is an inner page. That’s why it follows the standard page layout with the same inner and outer margins as the body text.

The cover is different; for example, it should have symmetric margins and can be designed individually. To get that deviating layout, it’s recommended to use a separate document for it. Another reason is that it will usually be printed on different paper or cardboard.

So, you can start with an article-like class as in our first recipe, Writing a short text, then use options such as twoside=false or the equivalent oneside option to get symmetric margins. Then, you can position your text as we did with the title page.

Changing the document class

A very well-designed book class is memoir. It is pretty complete in itself, so you don’t need to load many packages: it already integrates many features of other packages, providing similar interfaces. memoir has a monolithic, easy-to-use approach, but it needs to take care of package conflicts. It is not as flexible as choosing the package set by yourself. KOMA-Script, in contrast, provides its features mostly in packages that can also be used with other classes.

  1. Start with memoir by changing the first line to the following:
  2. Remove the \subtitle command, which is not supported.
  3. To have the title on its own page, surround \maketitle with a titlingpage environment:
  4. Typeset and compare.

The memoir class provides an extensive manual that can help you to customize your document. It’s split into two parts. Type texdoc memman at Command Prompt to read the actual manual and texdoc memdesign to read the part on book design, which is an excellent resource independent of the class. Alternatively, you can find these manuals at https://texdoc.org/pkg/memman and https://texdoc.org/pkg/memdesign, respectively.

Another great start with a unique beauty is the tufte-latex class. It comes with a sample-book.tex file, which you can also download from https://ctan.org/tex-archive/macros/latex/contrib/tufte-latex. You could open this book file containing some dummy content and fill in your text. One of its outstanding features is a wide margin for extensive use of side notes and small figures in the margin.

See also

A book may contain additional elements such as an index, a glossary, and a bibliography. Refer to Chapter 8, Producing Contents, Indexes, and Bibliographies, which includes such recipes.

The Overleaf book templates collection at https://www.overleaf.com/latex/templates/tagged/book can also give you a head start.


Creating a presentation

At a conference or a seminar, speakers often use a projector or screen to present written information in addition to the talk. Such a presentation document requires a specific kind of layout and features.

In our recipe, we will use the beamer class, which has been designed specifically for this purpose and provides the following features:

  • A typical landscape slide format, here 128 mm x 96 mm
  • Structured frames with dynamic information, such as sectioning
  • Support for overlays and transition effects
  • Pre-designed themes for easily changing the look
  • An intelligent interface for customizing

How to do it...

We will start with a sample presentation document, which we can extend. Follow the next steps:

  1. Start with the beamer document class:
  2. Choose a theme. Here, we take the theme called Warsaw:
  3. Begin the document:
  4. Provide a title, a subtitle, the author’s name, the institute, and a date:
    \title{Talk on the Subject}
    \subtitle{What this is about}
    \author{Author Name}
    \institute{University of X}
    \date{June 24, 2015}
  5. Make a slide using the frame environment. The first one will contain the title page:
  6. Make a frame for the table of contents titled Outline. Add the pausesections option so that the table of contents will be shown stepwise, section by section:
  7. Start a section and a subsection within:
    \subsection{A subsection}
  8. All visible content goes into a frame environment. So also do lists, which are visually better than normal text in a presentation:
    \begin{frame}{Very Informative Title}
        \item First thing to say.
        \item There is more.
        \item Another short point.
  9. This frame will show an emphasized block with a title:
    \begin{frame}{Another Title With Uppercased Words}
      \begin{alertblock}{A highlighted block}
        Some important information put into a block.
  10. We add another subsection, with a frame with another titled block, and another section with a slide containing a list. We highlight some words using the \alert command. Finally, end the document:
    \subsection{Another subsection}
    \begin{frame}{Informative Title}
      \begin{exampleblock}{An example}
        An example within a block.
      Explanation follows.
        \item Our \alert{main point}
        \item The \alert{second main point}
        Further ideas here.
  11. Compile and have a look at the produced slides:
Figure 1.4 – Presentation slides

Figure 1.4 – Presentation slides

Now, you can adjust the title, author, and date and edit the text in the frames. Then, you can add your own frames with titles and text.

How it works...

We loaded the beamer class and chose the theme with the name Warsaw. You could easily replace it with another theme’s name, compile, and cycle through the themes until you find the best for your occasion. Pre-installed themes are as follows:

  • AnnArbor
  • Antibes
  • Bergen
  • Berkeley
  • Berlin
  • Boadilla
  • boxes
  • CambridgeUS
  • Copenhagen
  • Darmstadt
  • default
  • Dresden
  • EastLansing
  • Frankfurt
  • Goettingen
  • Hannover
  • Ilmenau
  • JuanLesPins
  • Luebeck
  • Madrid
  • Malmoe
  • Marburg
  • Montpellier
  • PaloAlto
  • Pittsburgh
  • Rochester
  • Singapore
  • Szeged
  • Warsaw

We specified the title, subtitle, author, and talk date, which is then printed by \titlepage. We used a frame environment, which we will do for each slide.

The next frame contains the table of contents. We provided an Outline frame title as an argument to the frame in curly braces. For the \tableofcontents command, we added the pausesections option. By doing this, section titles are printed individually with a pause in between. This allows us to explain what the auditory will hear before they read further.

As in a standard LaTeX document, we used the \section and \subsection commands. The heading is not directly printed. The sections and subsections are printed in the frame margin with the current position highlighted.

We used an itemize environment as in a standard LaTeX document to get a bulleted list. The enumerate environment for numbered lists and description environment for descriptive lists also work in beamer frames.

To highlight information, we used so-called block environments. Besides the standard block environment, we can use exampleblock and alertblock to get a different style or color. The chosen theme determines the appearance of those blocks.

A more subtle kind of emphasizing is achieved using the \alert command, as seen in the last frame.

Now, you have a template and tools to build up your presentation.

Here are some more quick tips:

  • Keep time constraints in mind; a frame per minute is a good rule of thumb
  • Use a few sections, logically split into subsections; it’s better to avoid sub-subsections
  • Use self-explaining titles for sectioning and frames
  • Bulleted lists help to keep things simple
  • Consider avoiding numbering things; one rarely cares about a reference to theorem 2.6 during a talk
  • Don’t disrupt the reading flow by footnotes
  • Graphics, such as diagrams, help the auditory in visualizing


Slides should support your talk, not the other way around. Did you already bear up with a presentation where the speaker just read out aloud text from the slides and used fancy transition effects? You can do it better by focusing on well-crafted content.

There’s more...

The beamer class has unique capabilities and extraordinary design. We will explore it further.

Using short titles and names

Besides the title page, the title of the presentation and the author’s name are additionally printed at the bottom of each frame. The exact position depends upon the chosen theme.

However, the space might need to be increased for long titles or names. You can give short versions used at such places, such as by specifying the following text:

\title[Short title]{Long Informative Title}\author[Shortened name]{Author's Complete Name}\date[2024/01/24]{Conference on X at Y, January 24, 2024}

The same is possible for the \institute and \subtitle commands if used.

In the same way, you can provide short names for sections and subsections so that they better fit into their field within the frame margin. Just use the optional argument in square brackets. The \part and \subsubsection commands work similarly if needed.

Uncovering information piecewise

Showing a complete slide at once may be distracting. People may read ahead instead of listening to you. You can take them by the hand by showing the content step by step.

The simplest way is by inserting a \pause command. It can go between anything, such as text, graphics, and blocks. It also works between two \item commands in a bulleted list, though consider not to pause between items but between whole lists. Use it as in the following line of code:

Text\pause more text\pause\includegraphics{filename}

Such a frame is then layered – that is, divided into overlays. They are internally numbered. If you would like to show something at a certain overlay, you can tell the beamer class when to uncover it:


This shows your text on slide 3 of the current frame, and it will stay on the following slides on that frame. Omit the dash for restricting it only to slide 3. You could also list slides (for example, <3,5>), give ranges such as <3-5>, and mix slides (<3,5->).

That syntax works with overlay specification-aware commands. Among them, there are \item, \includegraphics, and even \renewcommand, so you can use them with an overlay specification such as the following:


It should not be too fancy. A presentation still needs a linear structure. Complicated overlays may be handy for showing and hiding annotation to an object while you explain that.

Refer to the beamer manual for further information about using overlays.

Splitting frames into columns

You can arrange text and images in multiple columns on a frame. It’s convenient for images with explaining text. Let’s take a look at a sample:

\begin{frame}  Some text which can use whole frame width  \begin{columns}[t]    \begin{column}{0.45\textwidth}      Sample text in\\      two lines    \end{column}    \begin{column}[T]{0.45\textwidth}      \includegraphics[width=3cm]{filename}    \end{column}  \end{columns}\end{frame}

We started the multi-column area using the columns environment. You can specify t, b, or c alignment options for the column’s top, bottom, or centered alignment. Centered is the default. While t aligns at the baseline of the first line, as usual in LaTeX, there’s a handy additional option, T, which aligns at the very top.

Each column has been made with the column environment. The column width has been given as an argument. It understands the same positioning options, so you can override what you set in the surrounding columns environment. We added [T] here because an image has its baseline at its bottom, and we wanted to change it to the very top.

Showing an outline for each section

You can tell the beamer class to give an outline at the beginning of each section by specifying the following code:

\AtBeginSection{  \begin{frame}{Outline}    \tableofcontents[currentsection]  \end{frame}}

You can also use the \AtBeginSection command for inserting different code. If something should happen for a starred \section* command too, you can insert the corresponding code within an optional argument in square brackets.

Removing navigation symbols

By default, every slide shows small navigation symbols; here, at the bottom of a frame. If you don’t need them, you can save that space and reduce distraction by specifying the following line of code:

\setbeamertemplate{navigation symbols}{}

Changing the font

The default font set with the beamer class is Computer Modern. You can change it to other fonts, as explained in the Writing a short text recipe.

The default shape is sans-serif. Even the math formulas are sans-serif. It can be more readable with a low projector resolution or at some distance than with a serif font.

However, if you would like to change to a serif font, you can load the corresponding font theme in the preamble:


Another available font theme is professionalfonts, which doesn’t change fonts but simply uses the set you bought. Furthermore, there are structurebold, structureitalicserif, and structuresmallcapsserif, which change the font in the structure – that is, in headlines, footlines, and sidebars – to such a shape combination.

Changing the color

The quickest way to change colors is by loading a theme with a thoughtful selection of colors for the various structural elements. Use a single command, such as the following:


Outer color themes provide a color set for the headline, footline, and sidebar. The author then gave sea-animal names: dolphin, whale, and seahorse. Then, there are inner color themes for elements such as color blocks with names of flowers: lily, orchid, and rose. Combine inner and outer color themes as you like.

Finally, there are complete themes covering all structure aspects: albatross, beaver, beetle, crane, dove, fly, monarca, seagull, spruce, and wolverine. They are named after flying animals, except beaver and spruce as external additions.

That’s a lot of names; just cycle through them using the \usecolortheme command to find the color set you like most.

Loading a theme from the internet

With some labor, you can create your very own theme. The extensive beamer manual will guide you. However, you may save much time: beamer is very popular among academic users who already use LaTeX for their papers. So, you can find many themes prepared for universities and institutes but also designed by various beamer users.

You can find an overview at https://latex-beamer.net.

Explore the gallery there, download a theme you like, add your logo, and tweak it. Instructions are on that website.

Providing a handout

You can give your auditory a printed version of slides. Just create a version of your document with the handout option so that no overlays will be used:


Slides are commonly small, so it’s good to print several slides on a single page:

\usepackage{pgfpages}\pgfpagesuselayout{4 on 1}[a4paper,  border shrink=5mm, landscape]

This prints four slides on one A4 page in landscape. You can get bigger prints, two slides on each page, in portrait mode by specifying the following line of code:

\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]

We used the pgfpages package, a utility package coming with the pgf package.

See also

For best quality with included graphics, refer to Chapter 5, Working with Images. In Chapter 6, Creating Graphics, you can find recipes for quickly creating diagrams and charts, which are excellent tools for visualizing data in a presentation.

Beyond common academic documents such as a thesis, papers, books, and slides, you may need to present yourself in the working world. The following recipe will prepare you for applying for a job with style.


Designing a CV

Tabular layouts are prevalent today for a CV. When applying for a job, inform yourself about typical requirements for the content of a CV. You can then create a simple document with tables that are consistent and readable.

You can use a template if it needs to be quick or you would like to base it upon a proven modern layout. We will use the moderncv class and its template in this recipe to quickly produce a CV.

Getting ready

If it’s not already installed on your computer, download and install the moderncv class from CTAN at https://ctan.org/pkg/moderncv. The easiest is to download it as a .zip file from https://mirrors.ctan.org/macros/latex/contrib/moderncv.zip.

If your TeX installation provides a package manager, use it for the installation.

There’s a directory of examples containing templates that you can use. Either locate it in the documentation branch of your TeX directory tree or visit the preceding CTAN link: https://ctan.org/tex-archive/macros/latex/contrib/moderncv.

How to do it...

We will start using a sample file provided by the moderncv bundle. Follow these steps:

  1. Copy the template.tex file into your document directory, rename it, and choose your own name, such as MyCV.tex.
  2. Open that document, MyCV.tex, and look around to understand the template. Luckily, it is full of comments on how to use it. Compile it to ensure that this document works.
  3. Review and edit the class and package options in MyThesis.tex.
  4. Remove the filler text and type in your own data. At the beginning, your document may look like this:
    \title{CV title}
    \address{street and number}{postcode city}{country}
    \cventry{year--year}{Job title}{Employer}{City}{}%
      {General description\newline{}%
      Detailed achievements:%
      \item Achievement 1;
      \item Achievement 2, with sub-achievements:
        \item Sub-achievement (a)
        \item Sub-achievement (b)
    \item Achievement 3.
    \cventry{year--year}{Job title}{Employer}{City}{}
      {Description line 1\newline{}Description line 2}
    \cventry{year--year}{Job title}%
    \cvitemwithcomment{Language 1}{Skill level}{Comment}
    \cvitemwithcomment{Language 2}{Skill level}{Comment}
  5. Compile and have a look at the following result:
Figure 1.5 – A CV

Figure 1.5 – A CV

How it works...

We loaded the moderncv package. We used an 11 pt base font size; 10 pt and 12 pt are also supported. We selected A4 paper; further paper size options are a5paper, b5paper, letterpaper, legalpaper, and executivepaper. You can also add landscape as an option. We chose a sans-serif font, which is fine for such a kind of list; alternatively, you could write roman for a serif font.

We selected the classic style. Other available styles are casual, oldstyle, and banking.

Our color style is blue. Other color options are orange, green, red, purple, gray, and black.

We loaded the geometry package with a scaling factor for reducing the margins.

Using commands such as \name and \address, we entered our personal data.

The \photo command includes our photo; the size options are the height to which it is scaled and the thickness of the frame around the photo. In this recipe, we used the picture.jpg dummy photo contained in the moderncv bundle.

The document body is divided into sections and subsections with a unique design.

Then, the \cventry command makes a typical resume entry for a job or education. Use it as follows:

\cventry[spacing]{years}{job title}  {employer}{localization}{detail}{job description}

You can alternatively use this:

\cventry[spacing]{years}{degree}  {institution}{localization}{grade}{comment}

You can leave the last four arguments empty if you don’t need them.

A simpler line is done using the \cvitem command as follows:

\cvitem[optional spacing length{header}{text}

The \cvitemwithcomment command works similarly, just with another argument printed at the right.

Some more commands and options are explained in the well-documented template.tex file and the moderncv.cls class file itself if you look for deeper information beyond this quick start guide.


Writing a letter

Letters have a specific structure. Commonly, they have an addressee field at a fixed position, which should be visible in the envelope window. It also should show a back address of yourself as the sender. An opening text and a closing phrase are usual elements; you may add fold marks and enclosures.

How to do it...

We will use a KOMA-Script class specifically designed for letters named scrlttr2. Follow the following steps:

  1. Use the scrlttr2 class, activate the address field and fold marks via an option, and align the sender’s address to the right:
    \documentclass[addrfield=true, foldmarks=true,
  2. Provide your name and your address using the \setkomavar command:
    \setkomavar{fromname}{Thomas Smith}
    \setkomavar{fromaddress}{123 Blvd \\ City, CC 12345}
  3. Write a date, either \today for today or any date as text:
  4. Begin the document:
  5. Open a letter environment with the recipient’s address as an argument:
    \begin{letter}{Agency \\ 5th Avenue \\
                   Capital City, CC 12345}
  6. Start with an opening, and let your letter text follow:
    \opening{Dear Sir or Madam,}
    the actual content of the letter follows.
  7. End with closing words:
    \closing{Yours sincerely}
  8. End the letter environment and the document:
  9. Compile the document. Here is the upper part of the output:
Figure 1.6 – A letter template

Figure 1.6 – A letter template

That was pretty easy! You got fully fledged formal letter addressing information, envelope window support, today’s date, phrases, signature, and even fold marks.

Now, you can enter real addresses and actual letter text.

How it works...

When loading the scrlttr2 letter class, we activated the address field, switched on fold marks, and set the options for right aligning the sender’s address.

The scrlttr2 class is quite different from others, so it has a unique interface. Using the \setkomavar command, we set the content of class variables, similar to \renewcommand. Here, we put names and addresses. The KOMA-Script manual explains all available variables. As mentioned in the Developing a thesis recipe, you can open it by executing texdoc koma-script at Command Prompt or online at https://texdoc.org/pkg/koma-script.

We used a letter environment for the actual content, including the opening and closing phrases. The address is a mandatory argument for that environment. You can have several letter environments in a single document.

There’s more...

To improve input and hyphenation and change the font, look at the first recipes in Chapter 2, Tuning the Text.

Let’s take a look at some letter-specific options.

Separating paragraphs

Instead of indenting the beginning of paragraphs, you can visualize a paragraph break with an empty line. For this, add the parskip=full option to the comma-separated list of class options at the beginning.

Use parskip=half for less space.

Changing the signature

If you would like to use a signature different from your specified name for the address, you can modify the corresponding variable content in the preamble:


It would be indented. You can get it left aligned by specifying the following code:


The code just shown also belongs to the preamble.

Adding enclosures

If you would like to add enclosures to your letter, it’s common to mention them. You can do this by inserting an \encl command right before \end{letter}:

\encl{Curriculum vitae, certificates}

You can change the default encl: option if you like by modifying the corresponding variable before calling the \encl command:


We used the \setkomavar* starred version, which modifies the description of a variable instead of its content, which actually is : – that is, a colon followed by a space.


Producing a leaflet

Flyers are a common way to promote an event or to inform about a product. A folded leaflet is particularly handy as a giveaway and to carry around, so let’s see how to produce one.

How to do it...

The intended layout is very different compared to the already shown document types. Fortunately, there’s a document class for it, with the name leaflet. We will use this one now. Let us start filling it with some content:

  1. Start with the leaflet document class. Choose a base font size of 10 pt, and set the notumble option, which keeps the back side printed in the same direction:
    \documentclass[10pt, notumble]{leaflet}
  2. Use an extended font encoding:
  3. If you want a non-default font, load it. This time, we chose the Linux Libertine font:
  4. Switch to sans-serif as the default font family:
  5. For better text justification, load the microtype package:
  6. Load the graphicx package for including a picture:
  7. Switch off the page numbering:
  8. Begin the document:
  9. Set title, author, and date. Then, print the title:
    \title{\textbf{\TeX\ Live Install Party}}
    \author{\Large\textbf{Your \TeX\ team}}
    \date{\textbf{August 11, City Hall Cellar}}
  10. Include a centered image. For a demonstration, we chose the CTAN lion, which you can download at https://ctan.org/lion and convert to PDF:
  11. Add some text:
    We'd like to welcome you to our famous yearly
    \TeX\ install party! Bring your laptop and have free
    cold soft drinks while we assist you in installing
    the latest \TeX\ version on your computer.
    We will provide
  12. A bulleted list can be a good idea for a catchy text. Use an itemize environment for it; each list item starts with an \item command:
      \item a fast internet connection for downloading,
      \item media such as DVDs and USB sticks with
            the latest \TeX,
      \item \TeX\ books for buying with a discount,
      \item chat with \TeX\ experts.
  13. End the page. Fill in more text on the next leaflet pages, which will be printed on the back side of the paper, next to each other:
    Fill in text for page 2 (on the back side)
    Fill in text for page 3 (on the back side)
    Fill in text for page 4 (on the back side)
  14. Now, pages 5 and 6 of the leaflet come to the front side of the paper. Use \section to get a heading:
  15. You can add a timetable using a tabular environment. By inserting @{} in the column format options, we suppress spacing at the left and right:
      6 pm    & Welcome \\
      7:30 pm & Live install presentation \\
      8 pm    & Book authors available for talks
                and signing \\
      9:30 pm & Bar closing
  16. End the paragraph using an empty line, continue with writing text, and finally, end the document:
    From 6pm to 10pm: install support
    and free \TeX\ copies on DVD on our welcome desk.
    Hotel, Meals, Travel information here
    Information about our local \TeX\ user group
    and Open Source projects sponsor
    Names, Phone numbers, email addresses
  17. Compile and have a look at the first page:
Figure 1.7 – A foldable leaflet

Figure 1.7 – A foldable leaflet

The back side still contains just some dummy text, helping to identify the position where the text finally lands on the page.

How it works...

In the first line, we loaded the leaflet class with a font size of 10 pt. The tumble option enables printing the back side upside down, which can be helpful for double-sided printing. This is the default. We used the notumble option instead, which suppresses that default behavior so that the output is better readable on the screen.

The next three lines contain our font settings. We used the Linux Libertine font. We specified T1 font encoding. You can read more about encodings in Chapter 2, Tuning the Text, specifically in the Improving justification and hyphenation recipe. Furthermore, we set the default font family to be sans-serif. I prefer the clean look of sans-serif on a flyer or a leaflet, which usually contains little text in narrow columns.

The remaining part of the preamble is as follows:

  • We loaded the microtype package, which improves the justification capabilities by tiny font adjustments. This is especially useful in a situation with narrow columns, such as in this case.
  • We loaded the graphicx package to include images such as a logo or a geographic map.
  • We hid page numbers. The gobble option stands for \gobble, which is a TeX command that removes the following command or control sequence so that the page number will be absorbed.

Our document body shows the usual sectioning commands and text. You can see that we added an explicit space after the TeX logo with a backslash and a following space. That’s because a space after a macro, such as \TeX, indicates the end of the macro. It doesn’t produce a space in print because punctuation may follow.

To have an image in our template, we used the CTAN lion drawn by Duane Bibby; simply replace it with your own image – a geographic map or a logo, for example.

The remaining text is straightforward and shows some useful layout details, such as the following:

  • Centering using the center environment:
  • Arranging points in a bulleted list by using an itemize environment
  • Setting up a tabular environment for text, which should be aligned in columns

In the \begin{tabular}{@{}rl@{}} line, the rl characters stand for two columns, where the first one is right-aligned and the second one is left-aligned. The @{code} expression inserts a piece of code instead of a space before or after a column, so @{} replaces it with nothing, which means removing it. We’ve got two columns without additional whitespace on the left or the right, saving our previous line space.

There’s more...

The leaflet class provides some options and commands for customization.

Adding fold marks and cut lines

By default, a small folding mark is printed on the backside. If you would like to omit it, add the nofoldmark option when loading the class:


You can draw a vertical dotted line with scissor symbols using the \CutLine command in the preamble with a page number as an argument. The line will go between this one and the preceding page, which is as follows:


It would print a dotted line with two scissor symbols on the back side, between pages 2 and 3, where a folding mark would be placed by default. The \CutLine* starred command version would not print the scissors.

Adjusting the margins

Similar to standard classes, you could use page headers and footers. There are none by default here. Standard commands such as \setlength{\headheight}{...} and \pagestyle could be used. leaflet provides an additional command to declare the margins:


Adding a background image

You can add an image to the background of a certain page:


Use the \AddToBackground* starred version to let it be printed onto the background of the combined page.

Instead of using the \includegraphics command, you could use another positioning, including or drawing code. Here, the Absolute positioning of text recipe in Chapter 2, Tuning the Text, may be helpful.

Changing the sectioning font

The font size of the section headers is already a bit smaller than with standard classes. If you want to change the headings’ size, shape, or color, you can redefine the \sectfont macro. For example, if we also enabled using color by \usepackage{xcolor}, we could write the following code:

\renewcommand{\sectfont}{%  \large\sffamily\bfseries\color{blue}}

This would give a large sans-serif font in bold and with blue color.

For further information regarding fonts, refer to Chapter 3, Adjusting Fonts.


Building a large poster

We know, for example, informational or scientific posters seen at conferences or on walls in universities or institutes.

They mostly have specific characteristics in common:

  • They are large, such as A2, A1, or even A0
  • People may look at them from far away but also very close

In consequence, we have some requirements for typesetting:

  • Page layout dimensions should work with such an enormous size.
  • We need a wide range of font sizes. We should be able to read while standing close, but we also need large, catchy headings.
  • The poster should be partitioned into digestible blocks. Specifically, each block should be at most the usual line width we know from body texts. Too wide lines would make it hard to focus and skip back to the start of the following line. So, block lines should not be much wider than 40 or 50 characters long.
  • Blocks should have distinct headings.
  • Graphic elements such as colors and lines can divide the text into parts.
  • Images should be vector graphics or should have a high resolution.

In this recipe, we would like to create a poster of A0 size in landscape orientation. It will show some blocks containing dummy text as a placeholder, math, and images. As sample images, we will take a flowchart from Chapter 6, Creating Graphics, and a plot from Chapter 10, Writing Advanced Mathematics. There, you can find the source code. You can later replace the dummy text and other parts with your own content.

How to do it...

We will use the tikzposter class. The document is structured in columns and blocks. Follow these steps:

  1. Begin with the document class. A0 is the default paper size. We state landscape orientation as an option:
  2. Choose a theme that provides a set of colors and decorations. We chose the blue Wave theme:
  3. Load the lipsum package to generate dummy text:
  4. For dividing wider blocks into text columns, we load the multicol package. Because of the large paper, we set the column separation and the separation line width to high values:
  5. Start the document:
  6. Declare the author and title, and print it out:
    \title{\LaTeX\ in Use}
    \author{John Doe}
  7. Begin a set of columns:
  8. Start a column with a width of 65% of the available text width:
  9. Define a block with the title Workflow in the first argument; the second argument contains dummy text and an image with a caption:
        \begin{tikzfigure}[\LaTeX\ workflow]

    The tikzposter package provides the tikzfigure environment as a replacement for the figure environment. The optional argument will be the caption of the figure.

  10. We are still in the first column and start a set of subcolumns:
  11. The first subcolumn will take half of the available width – in this case, the width of the left column:
  12. Create a block with a bulleted list and a mathematical equation to see how it looks on a poster. We will also use a colored box and an inner block with a title for the equation:
          Take a coffee, then:
            \item State
            \item Proof
            \item Write in \LaTeX
          \innerblock{Integral approximation}{
              \int_a^b f(x) dx \approx (b-a)
                \sum_{i=0}^n w_i f(x_i)
  13. Add a note that will have a callout shape, pointing into the formula:
        \note[targetoffsetx = 4.5cm, targetoffsety = -5cm,
          angle = -30, connection]{Weight function}
  14. Make another subcolumn, talking the other half of the available width. Insert a block filled with text, and then end the subcolumns environment:
  15. Now that we are back in our primary column environment, make another column, print a block with an image and some text, and then end the columns environment:
      \block{Plotting functions}{
  16. As we ended the columns, a block would use the whole available width. To keep text readable, we will now use the multicol package. We divide the text itself into columns using a multicolumn environment with four columns:
    \block{Conclusion and outlook}{
  17. End the document:
  18. Compile, and take a look:
Figure 1.8 – A colorful poster with a block layout

Figure 1.8 – A colorful poster with a block layout

How it works...

The tikzposter class supports huge paper sizes and large fonts and handles block heights and spacing between columns. We, as the users, just decided about the relative column width.

Several class options are provided. You can add them to the \documentclass command as we did with the preceding landscape option:

  • The paper size can be chosen by a0paper, a1paper, or a2paper. a0paper is the default.
  • Available font sizes are 12pt, 14pt, 17pt, 20pt, and 25pt. The last one is the default.
  • With either landscape or portrait, you can select the orientation. portrait is the default.
  • The standard fleqn option for flush-left equations is supported.
  • The standard leqno option for equation numbering at the left side is also supported.

You can adjust several lengths. Give them as class options in the key=value form with a measurement unit such as mm or cm:

  • margin: The distance between the edge of the poster area and the edge of the paper
  • innermargin: The distance from the outermost edge of the blocks to the edge of the poster
  • colspace: The horizontal distance between consecutive columns
  • subcolspace: The horizontal distance between consecutive columns in a subcolumn environment
  • blockverticalspace: The distance between the bottom of a block and the top of the next block below

A sample call using the exact defaults would be:

\documentclass[a0paper, portrait, 25pt, margin=0mm,  innermargin=15mm, colspace=15mm, subcolspace=8mm,  blockverticalspace=15mm]{tikzposter}

The package makes use of the very capable graphics language, TikZ. We will see more of TikZ in Chapter 6, Creating Graphics. For now, the main benefit is that tikzposter provides a lot of predefined styles and color schemes.

You can use a main layout style with \usetheme{name}. At the time of writing, there were nine themes available:

  • Wave: As seen in this recipe
  • Default (left) and Basic (right):
  • Rays (left) and Simple (right):
  • Envelope (left) and Board (right):
  • Autumn (left) and Desert (right):

Furthermore, predefined styles for color, title, background, notes, blocks, and inner blocks can be chosen and composed. There’s support for creating further styles.

The commands you have seen previously can be used immediately without further options. However, they can be customized via several options.

A complete reference is available by executing texdoc tikzposter at Command Prompt and online at https://texdoc.org/pkg/tikzposter. You can find a style guide, a feature guide, and more at https://bitbucket.org/surmann/tikzposter/downloads.

There’s more...

One of the first poster classes is the a0poster class. It supports A0, A1, A2, and A3 paper sizes. It provides font sizes from 12 pt up to 107 pt. Math formulas are printed in a suitable size. There’s no specific support for graphics, color, or text placement. For this, you would need additional packages such as TikZ.

In a previous recipe, you already saw beamer as a presentation class. The beamerposter package can be used together with it for producing presentations in poster size. It combines the beamer class with a0poster code. So, you can produce large posters with a wide range of font sizes together with beamer’s color and graphics capabilities, such as beamer boxes with titles.

As noted before, you can use the texdoc command or the https://texdoc.org website to access the documentation of the mentioned classes and packages.

About the Author
  • Stefan Kottwitz

    Stefan Kottwitz studied mathematics in Jena and Hamburg. He works as a network and IT security engineer both for Lufthansa Industry Solutions and for Eurowings Aviation. For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX and goLaTeX and the Q&A sites TeXwelt and TeXnique. He runs the TeX graphics gallery sites TeXample, TikZ, and PGFplots, the TeXlive online compiler, the TeXdoc service, and the CTAN software mirror. He is a moderator of the TeX Stack Exchange site and matheplanet. He publishes ideas and news from the TeX world on his blogs LaTeX and TeX. Before this book, he authored the first edition of LaTeX Beginner's Guide in 2011, and LaTeX Cookbook in 2015, both published by Packt.

    Browse publications by this author
LaTeX Cookbook - Second Edition
Unlock this book and the full library FREE for 7 days
Start now