官术网_书友最值得收藏!

Starting a paragraph with an over-sized letter

In older texts, such as in books of fairy tales, we sometimes see the first paragraph in a text starting with a huge letter, while the following text flows around it. This is called a drop cap or an initial. We will now use this design for our own text.

How to do it...

We will use the lettrine package, which provides a command for this purpose. Follow these steps:

  1. Start a document with any document class. Here, we chose the book class. We will use A6 paper size, simply because this makes the recipe easy to show with little text:
    \documentclass{book}
    \usepackage[a6paper]{geometry}
  2. Load the lettrine package:
    \usepackage{lettrine}
  3. Begin the document:
    \begin{document}
  4. Start a paragraph with the command \lettrine{letter}{further introduction}, as follows:
    \lettrine{O}{nce upon a time}, professional writer used
    a mechanical machine called a typewriter. It commonly
    printed fixed-width characters. Emphasizing was done by
    writing all capitals, and by underlining.
  5. End the document:
    \end{document}
  6. Compile the document. Now look at the shape of our paragraph:
    How to do it...

How it works...

For this simple example, we used the basic book class. We loaded the geometry package to get a handy A6 paper size. The final command in the preamble loaded the lettrine package, which provides exactly the design we were looking for. The command \lettrine{O}{nce upon a time} prints one big letter O, followed by the text in the second pair of braces, which is printed in small caps. The other text flows around the large letter.

There's more...

The design of the dropped capitals can be customized. Let's take a look at some options.

Changing the drop cap size

By default, the dropped capital will cover two lines. You can change the number of lines by setting the optional argument lines as follows:

\lettrine[lines=3]{O}{nce upon a time}

Now a huge O covers three lines. Furthermore, you can enlarge it by setting the loversize option, standalone or in combination with the previously seen option:

\lettrine[lines=3,loversize=0.2]{O}{nce upon a time}

The loversize option can be set to a value larger than -1 and smaller than or equal to 1, and means the resize factor. That is, a value of 0.1 means enlarging by 10 percent.

The lettrine package provides a key=value interface. More options are available to control further aspects, such as the gap between the drop cap and the following text, and vertical shifting. You can also let drop caps hang into the margin. These features are explained in the manual. You can open it using texdoc lettrine in Command prompt, or at http://texdoc.net/pkg/lettrine.

Tip

In case of repeated use:

For making later adjustments easier and consistent, it's recommended that you create a macro via the \newcommand command, using the \lettrine command inside. It's better than repeatedly typing the \lettrine commands with options.

Coloring the initial

The simplest way of getting colored drop caps is by using the well-known commands of the color or xcolor package, as follows:

\usepackage{xcolor}
...
\lettrine{\textcolor{red}{A}}{nother} time

Tip

A full list of available colors and names is contained in the xcolor manual. You can open it by typing the texdoc xcolor command in Command Prompt, or you can find it online at http://texdoc.net/pkg/xcolor. You may need to set an option to access certain predefined names, such as svgnames, dvipsnames, or x11names.

The package coloredlettrine provides an even fancier way. It provides bicolor initials based on the EB Garamond font. Internally, the initials are split into two fonts. One provides the background ornaments, the other the actual letters. This allows separate coloring. We will use the OpenType version of the EB Garamond font. OpenType requires compilation with XeLaTeX or LuaLaTeX. Many LaTeX editors support them too.

At the time of writing, the package was still in development. There was just a small set of initials available. That's why we will refer to the development sources. Let's take a look at the following steps:

  1. Download the package files from https://github.com/raphink/coloredlettrine. There should be a .ins file and a .dtx file. Put them together into the same folder. Compile the file coloredlettrine.ins with LaTeX. This produces a file named coloredlettrine.sty, which you can place in your TeX installation or your document folder.
  2. Get the latest version of the EB Garamond font from https://bitbucket.org/georgd/eb-garamond/downloads and install it. Specifically, unzip the downloaded file and install at least the EBGaramond-InitialsF1.otf and EBGaramond-InitialsF2.otf software. On a Mac, double click the file to see the contents and then click the install button shown.
  3. The package coloredlettrine contains an example that you can compile. Here, let's modify our example from the recipe's start:
    \documentclass{book}
    \usepackage[a6paper]{geometry}
    \usepackage{coloredlettrine}
    \renewcommand{\EBLettrineBackColor}{SlateBlue}
    \setcounter{DefaultLines}{3}
    \renewcommand{\DefaultLraise}{0.3}
    \renewcommand{\DefaultFindent}{0.3em}
    \renewcommand{\DefaultNindent}{0pt}
    \begin{document}
    \coloredlettrine{O}{nce upon a time}, professional
    writer used a mechanical machine called a typewriter.
    It commonly printed fixed-width characters. Emphasizing
    was done by writing all capitals, and by underlining.
    
    \coloredlettrine{T}{oday}, we prefer variable-width
    letters. Now it is common to gently emphasize using italic,
    or heavier using bold.
    \end{document}
  4. Choose XeLaTeX for typesetting, compile, and have a look:
    Coloring the initial

The command \coloredlettrine can be used exactly like the \lettrine command since it is just a wrapper for it. You can redefine the macros \EBLettrineBackColor and \EBLettrineFrontColor to choose the color.

In this example, we set default values for lettrine parameters, which we would otherwise have needed to provide as key=value options, as explained earlier in this recipe. This way can save you from defining your own macro. It is described in the manual, which you can open with the texdoc lettrine command at the command prompt, or find online at http://texdoc.net/pkg/lettrine.

主站蜘蛛池模板: 海门市| 丰县| 临夏县| 札达县| 额尔古纳市| 普洱| 苍南县| 南昌市| 凤山县| 乌鲁木齐县| 临汾市| 嘉义县| 宁河县| 元氏县| 和田市| 阿克陶县| 中卫市| 栾城县| 永平县| 许昌县| 义乌市| 兴安盟| 托里县| 兴文县| 金湖县| 桦川县| 海淀区| 清镇市| 西峡县| 杂多县| 恩施市| 岐山县| 都昌县| 房产| 个旧市| 高青县| 盖州市| 安顺市| 黄大仙区| 应城市| 大田县|