Reader small image

You're reading from  LaTeX Beginner's Guide - Second Edition

Product typeBook
Published inOct 2021
PublisherPackt
ISBN-139781801078658
Edition2nd Edition
Tools
Right arrow
Author (1)
Stefan Kottwitz
Stefan Kottwitz
author image
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.
Read more about Stefan Kottwitz

Right arrow

Chapter 12: Enhancing Your Documents Further

By now, you're capable of writing structured documents in fine typographical quality, and you can meet high expectations for classic publications such as books, journal articles, or a university thesis.

Perhaps you would like to publish your PDF documents online. Such electronic documents or e-books usually require navigation such as hyperlinks and a bookmark index.

This chapter shall provide us with the tools for such enhancements. We shall figure out how to perform the following:

  • Using hyperlinks and bookmarks
  • Designing headings
  • Coloring our documents

Let's implement this by using LaTeX packages that are dedicated to these subjects.

Technical requirements

You can use a local LaTeX installation, or you can compile the example code online at https://latexguide.org/chapter-12.

The code is available on GitHub: https://github.com/PacktPublishing/LaTeX-Beginner-s-Guide-Second-Edition/tree/main/Chapter_12_-_Enhancing_Your_Documents_Further.

In this chapter, we will use the following packages: bm, colortbl, hyperref, titlesec, and xcolor. Since we're going to continue working with the code of the previous chapter, we require the same packages as in Chapter 11, Developing Large Documents.

We will also briefly look at the bookmark package.

Designing headings

In Chapter 2, Formatting Text and Creating Macros, we encountered the problem of customizing headings. There has to be a consistent way to modify the font of headings, their spacing, and their numbering for the whole document. Fortunately, there's a handy package for that, and it's called titlesec. We shall use it now to design chapter and section headings.

We'll return to the example that we used in this chapter. Our goal is to create headings with this appearance:

  • Centered titles
  • Smaller font size
  • Less space above and below
  • With a sans serif font, which is a good choice for bold headings

Let's start:

  1. Open the preamble.tex file, which we have already used in this chapter. Insert this line to load the titlesec package:
    \usepackage{titlesec}
  2. Add this command to specify the layout and font of the chapter headings:
    \titleformat{\chapter}[display]
      {\normalfont\sffamily\Large\bfseries\centering...

Coloring our documents

We could enhance our text further with colors. We haven't dealt with it yet, because most people use LaTeX to write serious books and articles or business letters where too much color may harm the appearance. But why not try something fancy? For instance, diagrams and tables in presentations are often colorful.

We just need to load the xcolor package:

\usepackage{xcolor}

From now on, we have to use a command to set the text color:

\color{name} 

This command is a declaration that switches to the color that is named. Just try \color{blue}.

The corresponding command form to color a piece of text is as follows:

\textcolor{name}{text}

\textcolor adds grouping implicitly; it works like this:

{\color{name} text}

For coloring text snippets, \textcolor is the better choice, while \color would be a good choice for longer pieces of text enclosed by an environment or braces.

The xcolor package offers a lot of ready-mixed colors; you...

Summary

In this chapter, we enhanced our document with a hypertext structure including colored links and bookmarks for navigation. We can now edit the PDF metadata, customize our headings' styles, and use colors.

During our work, we may encounter errors and warnings. That's common for advanced LaTeX users as well. The following chapter will prepare us for troubleshooting.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
LaTeX Beginner's Guide - Second Edition
Published in: Oct 2021Publisher: PacktISBN-13: 9781801078658
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime

Author (1)

author image
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.
Read more about Stefan Kottwitz