Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
LaTeX Cookbook
LaTeX Cookbook

LaTeX Cookbook: Over 90 hands-on recipes for quickly preparing LaTeX documents to solve various challenging tasks

Arrow left icon
Profile Icon Stefan Kottwitz
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (5 Ratings)
Paperback Oct 2015 378 pages 1st Edition
eBook
€28.99 €41.99
Paperback
€52.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Stefan Kottwitz
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (5 Ratings)
Paperback Oct 2015 378 pages 1st Edition
eBook
€28.99 €41.99
Paperback
€52.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€28.99 €41.99
Paperback
€52.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

LaTeX Cookbook

Chapter 2. Tuning the Text

This chapter contains the following recipes:

  • Inputting accented characters
  • Improving justification and hyphenation
  • Converting numbers to words
  • Putting text into a colorful box
  • Visualizing the layout
  • Visualizing boxes of letters and symbols
  • Typesetting in a grid
  • Absolute positioning of text
  • Starting a paragraph with an oversized letter
  • Fitting text to a shape
  • Creating a pull quote

Introduction

The previous chapter presented recipes for creating whole documents. You may use them as starting points. Now, we will focus on customizing text details. The upcoming sections broadly deal with the following:

  • Manipulating text
  • Positioning and arranging text
  • Shaping paragraphs

We are not yet dealing with fonts. This topic deserves a whole chapter, and will be covered in Chapter 3, Adjusting Fonts.

We will start with some very useful basics, cover some helpful things, and end the chapter with recipes that show off what LaTeX can do beyond rectangular paragraphs.

Inputting accented characters

By default, LaTeX works with simple ASCII characters. For accented characters, such as in the German word "schön", you need to type sch\"on into your editor. The babel command with the ngerman option simplifies the syntax to sch"on. But there is an easier way.

How to do it...

We will activate extended input character support as follows:

  1. Check your editor's configuration and find out its input encoding setting. utf8 (UTF-8 means Unicode) is standard for Linux, Mac OS X, and some Windows editors. However, some Windows editors still work with latin1 or cp1250/cp1252, while some older Macs use applemac.
  2. Load the inputenc package with the corresponding option, like so:
    \usepackage[utf8]{inputenc}
  3. Now you can directly type characters such as a, ü, ö, é, and è in to your document.

Tip

If you need help with editor settings, you can post a question in the forum at http://latex-community.org/forum/. This web site provides support...

Improving justification and hyphenation

Sometimes, you may get warnings like overfull \hbox, or you may notice words hanging in the margin. This is a sign that LaTeX has had serious problems with justification. Now, we will take a look at how to improve that.

How to do it...

You can start with any document. We will optimize it with settings in the preamble. If you don't have one at hand, you can take one from the code package for this book, specifically for the first chapter, or download one at http://latex-cookbook.net. Let's proceed:

  1. Load the package babel with your document languages as options. Use the preferred language as the last option:
    \usepackage[ngerman,english]{babel}
  2. If you would like to use handy shortcuts of the ngerman package with English too, add the following lines of code:
    \useshorthands{"}
    \addto\extrasenglish{\languageshorthands{ngerman}}
  3. Load the fontenc package with the T1 option set:
    \usepackage[T1]{fontenc}
  4. Load the microtype package for improved micro-typography...

Converting numbers to words

Numbers are sometimes written in words rather than using numerals. LaTeX is capable of automatically converting numbers to words. This is especially useful for values which originate from LaTeX counters, such as page or section numbers.

How to do it...

Load the fmtcount package and use its commands for conversion:

  1. Start with any document class, such as article:
    \documentclass{article}
  2. Load the fmtcount package:
    \usepackage{fmtcount}
  3. Begin the document:
    \begin{document}
  4. Write some text. Use the following instructions:
    • Whenever you'd like to convert a number to a word, use the command \numberstringnum.
    • To print a counter value as a word, use \numberstring.
    • For a similar purpose, but in ordinal form, use \ordinalstringnum or \ordinalstring. Let's take a look at the following commands:
      This document should have \numberstringnum{32}
      pages, now we are on page \numberstring{page}
      in the \ordinalstring{section} section.
  5. End the document:
    \end{document}
  6. Compile the document...

Putting text into a colorful box

You often see important content put into a colored box, especially on posters and slides, although it's used in other documents, too. In this recipe, we will put a little text and also whole paragraphs into a colored box. They can also have titles.

How to do it...

We will use the tcolorbox package. It is based on pgf, so you need to have that package installed as well.

We will create a box with the defaults, a titled box with split content, and boxes placed inline that fit the width of the content. Proceed as follows:

  1. Create a small document based on any document class. The article package is a simple choice. Load the blindtext package to generate dummy text. This time, we will use the pangram option to create short pangrams as dummy text. The blindtext package requires the babel package, so we load it before. We also set English as the language. Furthermore, load the tcolorbox package. Our base document looks like this:
    \documentclass{article}
    \usepackage...

Visualizing the layout

At the time of designing a document, one may like to have an exact view of the dimensions and position of the text body, the header and footer, and the space for the margin notes. LaTeX can print help lines for you so you can examine the layout and use it to position extra elements.

How to do it...

Load the showframe package. This means the following steps:

  1. Open your document or a sample for testing. Here, we will use the very first document from Chapter 1, The Variety of Document Types.
  2. Add the following line at the end of your preamble:
    \usepackage{showframe}
  3. Compile the document. You will see frames around text body, margin note area, and header and footer:
    How to do it...
  4. Examining the layout can give you ideas about making adjustments, such as changing the margins or other page dimensions. If you don't need these help lines any more, you can disable the package by commenting out \usepackage{showframe} or by deleting it.

How it works...

We simply loaded the showframe package. It...

Introduction


The previous chapter presented recipes for creating whole documents. You may use them as starting points. Now, we will focus on customizing text details. The upcoming sections broadly deal with the following:

  • Manipulating text

  • Positioning and arranging text

  • Shaping paragraphs

We are not yet dealing with fonts. This topic deserves a whole chapter, and will be covered in Chapter 3, Adjusting Fonts.

We will start with some very useful basics, cover some helpful things, and end the chapter with recipes that show off what LaTeX can do beyond rectangular paragraphs.

Inputting accented characters


By default, LaTeX works with simple ASCII characters. For accented characters, such as in the German word "schön", you need to type sch\"on into your editor. The babel command with the ngerman option simplifies the syntax to sch"on. But there is an easier way.

How to do it...

We will activate extended input character support as follows:

  1. Check your editor's configuration and find out its input encoding setting. utf8 (UTF-8 means Unicode) is standard for Linux, Mac OS X, and some Windows editors. However, some Windows editors still work with latin1 or cp1250/cp1252, while some older Macs use applemac.

  2. Load the inputenc package with the corresponding option, like so:

    \usepackage[utf8]{inputenc}
  3. Now you can directly type characters such as a, ü, ö, é, and è in to your document.

Tip

If you need help with editor settings, you can post a question in the forum at http://latex-community.org/forum/. This web site provides support forums for various LaTeX editors.

How it works...

Improving justification and hyphenation


Sometimes, you may get warnings like overfull \hbox, or you may notice words hanging in the margin. This is a sign that LaTeX has had serious problems with justification. Now, we will take a look at how to improve that.

How to do it...

You can start with any document. We will optimize it with settings in the preamble. If you don't have one at hand, you can take one from the code package for this book, specifically for the first chapter, or download one at http://latex-cookbook.net. Let's proceed:

  1. Load the package babel with your document languages as options. Use the preferred language as the last option:

    \usepackage[ngerman,english]{babel}
  2. If you would like to use handy shortcuts of the ngerman package with English too, add the following lines of code:

    \useshorthands{"}
    \addto\extrasenglish{\languageshorthands{ngerman}}
  3. Load the fontenc package with the T1 option set:

    \usepackage[T1]{fontenc}
  4. Load the microtype package for improved micro-typography:

    \usepackage...

Converting numbers to words


Numbers are sometimes written in words rather than using numerals. LaTeX is capable of automatically converting numbers to words. This is especially useful for values which originate from LaTeX counters, such as page or section numbers.

How to do it...

Load the fmtcount package and use its commands for conversion:

  1. Start with any document class, such as article:

    \documentclass{article}
  2. Load the fmtcount package:

    \usepackage{fmtcount}
  3. Begin the document:

    \begin{document}
  4. Write some text. Use the following instructions:

    • Whenever you'd like to convert a number to a word, use the command \numberstringnum.

    • To print a counter value as a word, use \numberstring.

    • For a similar purpose, but in ordinal form, use \ordinalstringnum or \ordinalstring. Let's take a look at the following commands:

      This document should have \numberstringnum{32}
      pages, now we are on page \numberstring{page}
      in the \ordinalstring{section} section.
  5. End the document:

    \end{document}
  6. Compile the document. All numbers...

Putting text into a colorful box


You often see important content put into a colored box, especially on posters and slides, although it's used in other documents, too. In this recipe, we will put a little text and also whole paragraphs into a colored box. They can also have titles.

How to do it...

We will use the tcolorbox package. It is based on pgf, so you need to have that package installed as well.

We will create a box with the defaults, a titled box with split content, and boxes placed inline that fit the width of the content. Proceed as follows:

  1. Create a small document based on any document class. The article package is a simple choice. Load the blindtext package to generate dummy text. This time, we will use the pangram option to create short pangrams as dummy text. The blindtext package requires the babel package, so we load it before. We also set English as the language. Furthermore, load the tcolorbox package. Our base document looks like this:

    \documentclass{article}
    \usepackage[english...

Visualizing the layout


At the time of designing a document, one may like to have an exact view of the dimensions and position of the text body, the header and footer, and the space for the margin notes. LaTeX can print help lines for you so you can examine the layout and use it to position extra elements.

How to do it...

Load the showframe package. This means the following steps:

  1. Open your document or a sample for testing. Here, we will use the very first document from Chapter 1, The Variety of Document Types.

  2. Add the following line at the end of your preamble:

    \usepackage{showframe}
  3. Compile the document. You will see frames around text body, margin note area, and header and footer:

  4. Examining the layout can give you ideas about making adjustments, such as changing the margins or other page dimensions. If you don't need these help lines any more, you can disable the package by commenting out \usepackage{showframe} or by deleting it.

How it works...

We simply loaded the showframe package. It prints...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Work with modern document classes, such as KOMA-Script classes
  • Explore the latest LaTeX packages, including TikZ, pgfplots, and biblatex
  • An example-driven approach to creating stunning graphics directly within LaTeX

Description

LaTeX is a high-quality typesetting software and is very popular, especially among scientists. Its programming language gives you full control over every aspect of your documents, no matter how complex they are. LaTeX's huge amount of customizable templates and supporting packages cover most aspects of writing with embedded typographic expertise. With this book you will learn to leverage the capabilities of the latest document classes and explore the functionalities of the newest packages. The book starts with examples of common document types. It provides you with samples for tuning text design, using fonts, embedding images, and creating legible tables. Common document parts such as the bibliography, glossary, and index are covered, with LaTeX's modern approach.You will learn how to create excellent graphics directly within LaTeX, including diagrams and plots quickly and easily. Finally, you will discover how to use the new engines XeTeX and LuaTeX for advanced programming and calculating with LaTeX. The example-driven approach of this book is sure to increase your productivity.

Who is this book for?

If you already know the basics of LaTeX and you like to get fast, efficient solutions, this is the perfect book for you. If you are an advanced reader, you can use this book's example-driven format to take your skillset to the next level. Some familiarity with the basic syntax of LaTeX and how to use the editor of your choice for compiling is required.

What you will learn

  • Choose the right document class for your project to customize its features
  • Utilize fonts globally and locally
  • Frame, shape, arrange, and annotate images
  • Add a bibliography, a glossary, and an index
  • Create colorful graphics including diagrams, flow charts, bar charts, trees, plots in 2d and 3d, time lines, and mindmaps
  • Solve typical tasks for various sciences including math, physics, chemistry, electrotechnics, and computer science
  • Optimize PDF output and enrich it with meta data, annotations, popups, animations, and fillin fields
  • Explore the outstanding capabilities of the newest engines and formats such as XeLaTeX, LuaLaTeX, and LaTeX3

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 28, 2015
Length: 378 pages
Edition : 1st
Language : English
ISBN-13 : 9781784395148
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Oct 28, 2015
Length: 378 pages
Edition : 1st
Language : English
ISBN-13 : 9781784395148
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 126.97
LaTeX Beginner's Guide
€37.99
LaTeX Cookbook
€52.99
LaTeX Beginner's Guide
€35.99
Total 126.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. The Variety of Document Types Chevron down icon Chevron up icon
2. Tuning the Text Chevron down icon Chevron up icon
3. Adjusting Fonts Chevron down icon Chevron up icon
4. Working with Images Chevron down icon Chevron up icon
5. Beautiful Designs Chevron down icon Chevron up icon
6. Designing Tables Chevron down icon Chevron up icon
7. Contents, Indexes, and Bibliographies Chevron down icon Chevron up icon
8. Getting the Most out of the PDF Chevron down icon Chevron up icon
9. Creating Graphics Chevron down icon Chevron up icon
10. Advanced Mathematics Chevron down icon Chevron up icon
11. Science and Technology Chevron down icon Chevron up icon
12. Getting Support on the Internet Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(5 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Amazon Customer Jan 26, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A splendid book that should be read if you want to learn latex. The exhibition is clear and minimalist so that learning is fun.
Amazon Verified review Amazon
Zen Lobo Mar 15, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book covering many very advanced types of documents that can be prepared using LaTeX
Amazon Verified review Amazon
D. Lee Dec 27, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book. It provides some good examples but more importantly contained what I needed. It’s also nice because I don’t have to search discussion post hoping to find the information.
Amazon Verified review Amazon
xyah Sep 28, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
todo ok, gracias por todo, en orden y a tiempo. gracias por todo, muy bueno, tks all ok, tks. bien
Amazon Verified review Amazon
Mark Sep 15, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book showcases a great many possible uses of LaTeX, many of them surprising and useful. The "recipes" can quickly be used to setup templates. Even if you don't use the "recipes" for the purpose the author intended, they're easy to apply for other purposes, and showing what you can learn about later. LaTeX is a gradual learning process, easy to start with, but difficult to master. I'm no scientist or academic, but after skimming through sections, and diligently reading others, I feel empowered. At least I know what's possible and where to begin to get started. The greatest obstacle for new users of LaTeX isn't understanding how to learn it, but what they can learn to do with it. This answers that in depth.The authors other book for beginning LaTeX is the best FirstStudy available. And I would recommend this book to top it off. Both of these together have helped to make me a LaTeX enthusiast. Yes, this author has nailed it twice in a row.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.