Book Image

LaTeX Cookbook

By : Stefan Kottwitz
Book Image

LaTeX Cookbook

By: Stefan Kottwitz

Overview of this book

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.
Table of Contents (19 chapters)
LaTeX Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Producing a leaflet


Flyers are a common way to promote an event or to inform about a product. In particular, a folded leaflet is very 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, which we will use now. Let's start filling it with some content. Let's take a look at the following steps:

  1. Start with the leaflet document class. Choose a base font size of 10 pt, and set the option notumble, which keeps the back side printed in the same direction:

    \documentclass[10pt,notumble]{leaflet}
  2. Use an extended font encoding:

    \usepackage[T1]{fontenc}
  3. If you want a nondefault font, load it, this time we chose the Linux Libertine font:

    \usepackage{libertine}
  4. Switch to sans serif as the default font family:

    \renewcommand{\familydefault}{\sfdefault}
  5. For better text justification, load the microtype package:

    \usepackage{microtype}
  6. Load the graphicx package to include a picture:

    \usepackage{graphicx}
  7. Switch off the page numbering:

    \pagenumbering{gobble}
  8. Begin the document:

    \begin{document}
  9. Set the title, author's name, 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}}
    \maketitle
  10. Include a centered image. Here, we chose the CTAN lion:

    \begin{center}
      \includegraphics[width=\linewidth]{ctanlion.pdf}
    \end{center}
  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 starting with \item:

    \begin{itemize}
      \item a fast internet connection fow downloading,
      \item media such as DVDs and USB sticks with
        the latest \TeX\,
      \item \TeX\ books for bying with a discount,
      \item chat with \TeX\ experts.
    \end{itemize}
  13. End the page. Fill in more text on the next page of the leaflet, which will be printed on the back side of the paper, next to each other:

    \clearpage
    Fill in text for page 2 (on the back side)
    \clearpage
    Fill in text for page 3 (on the back side)
    \clearpage
    Fill in text for page 4 (on the back side)
    \clearpage
  14. Now, pages 5 and 6 of the leaflet come to the front side of the paper. Use the \section command to insert a heading:

    \section{Schedule}
  15. You can add a timetable using a tabular environment. Using the @{} option, we suppress spacing at the left and right:

    \begin{tabular}{@{}rl@{}}
      6 pm    & Welcome \\
      7:30 pm & Live install presentation \\
      8 pm    & Book authors available for talks and signing \\
      9:30 pm & Bar closing
    \end{tabular}
  16. End the paragraph with an empty line, continue writing the text, and finally end the document:

    From 6pm to 10pm: install support and free \TeX\ copies on DVD on our welcome desk.
    \section{Accomodation}
    Hotel, Meals, Travel information here
    \section{Sponsors}
    Information about our local \TeX\ user group
    and Open Source projects sponsor
    \clearpage
    \section{Contact}
    Names, Phone numbers, email addresses
    \end{document}
  17. Compile and take a look at the first page:

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

How it works...

In the first line, we loaded the leaflet package with a font size of 10 pt. The notumble option suppresses the default behavior, that is, printing the back side upside down.

The next three lines contain our font settings. We used the Linux Libertine font and specified the 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.

The remaining part of the preamble is as follows:

  • We loaded the microtype package, which improves the justification capabilities with tiny font adjustments. This is especially useful in a situation with narrow columns, such as in this case.

  • We loaded the graphicx package, so we are able to include images such as a logo or a geographic map.

  • We hid the page numbers. The \gobble command is a TeX command that removes the following command or control sequence, so the page number will simply be absorbed.

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

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

The remaining text is straightforward and shows some useful layout details, as follows:

  • Centering using the center environment:

    \begin{center}
    ...
    \end{center}
  • Arranging points in a bulleted list using an itemize environment

  • Setting up a tabular environment for text, which should be aligned in columns

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

There's more...

The leaflet class provides some options and commands for customization.

Fold marks and cut lines

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

\documentclass[10pt,notumble,nofoldmark]{leaflet}

You can draw a vertically dotted line with a scissors symbol 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:

\CutLine{3}

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

Adjusting the margins

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

\setmargins{top}{bottom}{left}{right}

Adding a background image

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

\AddToBackground{pagenumber}{\includegraphics{filename}}

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

Instead of the \includegraphics command, you can use other positioning commands, including our drawing code. Here, the Absolute positioning of text recipe in Chapter 2, Tuning the Text, will be useful.

Changing the sectioning font

The font size of section headers is already a bit smaller than that of standard classes. If you would like to change the size, shape, or color of the headings, you can redefine the \sectfont macro. For example, if we enable using color with the \usepackage{xcolor} command, we can write the following line of code:

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

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

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