- LaTeX Cookbook
- Stefan Kottwitz
- 919字
- 2021-07-09 21:25:02
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:
- 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}
- Load the
lettrine
package:\usepackage{lettrine}
- Begin the document:
\begin{document}
- 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.
- End the document:
\end{document}
- Compile the document. Now look at the shape of our paragraph:
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.
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.
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:
- 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 filecoloredlettrine.ins
with LaTeX. This produces a file namedcoloredlettrine.sty
, which you can place in your TeX installation or your document folder. - 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
andEBGaramond-InitialsF2.otf
software. On a Mac, double click the file to see the contents and then click the install button shown. - 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}
- Choose XeLaTeX for typesetting, compile, and have a look:
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.
- Learning Real-time Processing with Spark Streaming
- Java面向?qū)ο笏枷肱c程序設(shè)計(jì)
- vSphere High Performance Cookbook
- 圖解Java數(shù)據(jù)結(jié)構(gòu)與算法(微課視頻版)
- 算法基礎(chǔ):打開(kāi)程序設(shè)計(jì)之門
- TypeScript圖形渲染實(shí)戰(zhàn):基于WebGL的3D架構(gòu)與實(shí)現(xiàn)
- MySQL數(shù)據(jù)庫(kù)基礎(chǔ)實(shí)例教程(微課版)
- Modular Programming in Java 9
- 大學(xué)計(jì)算機(jī)基礎(chǔ)實(shí)驗(yàn)指導(dǎo)
- C++20高級(jí)編程
- 深入理解C指針
- 深度實(shí)踐KVM:核心技術(shù)、管理運(yùn)維、性能優(yōu)化與項(xiàng)目實(shí)施
- 精通Spring:Java Web開(kāi)發(fā)與Spring Boot高級(jí)功能
- Android編程權(quán)威指南(第4版)
- ASP.NET本質(zhì)論