Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
LaTeX Beginner's Guide - Second Edition

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

Product type Book
Published in Oct 2021
Publisher Packt
ISBN-13 9781801078658
Pages 354 pages
Edition 2nd Edition
Languages
Author (1):
Stefan Kottwitz Stefan Kottwitz
Profile icon Stefan Kottwitz

Table of Contents (16) Chapters

Preface Chapter 1: Getting Started with LaTeX Chapter 2: Formatting Text and Creating Macros Chapter 3: Designing Pages Chapter 4: Creating Lists Chapter 5: Including Images Chapter 6: Creating Tables Chapter 7: Using Cross-References Chapter 8: Listing Contents and References Chapter 9: Writing Math Formulas Chapter 10: Using Fonts Chapter 11: Developing Large Documents Chapter 12: Enhancing Your Documents Further Chapter 13: Troubleshooting Chapter 14: Using Online Resources Other Books You May Enjoy

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.

Using hyperlinks and bookmarks

There's a sophisticated package called hyperref that does nearly all basic hyperlinking automatically. Let's check it out.

Adding hyperlinks

We shall load the hyperref package and inspect its effect:

  1. Open the preamble.tex file, which we used in the previous chapter. At the end, add this line:
    \usepackage{hyperref}
  2. Save this document under the same name.
  3. Open our Book of Equations from the previous chapter; we called it equations.tex.
  4. Compile the document twice without making any changes. Let's see how the document now appears; here, we can see red boxes indicating hyperlinks:

Figure 12.1 – A table of contents with hyperlinks and bookmarks

Cross-references, such as references to equation numbers, also have red boxes:

Figure 12.2 – References to equations with hyperlinks

By just loading the hyperref package, our document has significantly changed...

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 2021 Publisher: Packt ISBN-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.
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 $15.99/month. Cancel anytime}