- LaTeX Cookbook
- Stefan Kottwitz
- 746字
- 2021-07-09 21:25:03
Creating a pull quote
To entice people to read a text, we can present a short, attractive excerpt as a quotation. That means we pull out some text. In a two-column layout, it's looks nice to put the quotation into a window in the middle of the page between the two columns, with the regular text flowing around it. It's also a nice way of embedding images.
How to do it...
One possibility is to use the shapepar
package to cut out space from the text, like in the previous recipe. However, it would be a bit challenging doing it twice, once for each column.
The pullquote
package provides a solution. It can typeset a balanced two-column text layout with a cut-out window. This can be filled with text or an image. The shape is arbitrary.
We will use dummy text and highlight a quotation from Donald Knuth, the creator of TeX:
- Download the
pullquote.dtx
file from http://bazaar.launchpad.net/~tex-sx/tex-sx/development/view/head:/pullquote.dtx or from CTAN, once it's provided there too. - Click on browse files and also download the
pq-alice.jpg
,pq-duck.pdf
, andpullquote_test.tex
files, to get filler images and a sample file. - Compile the
pullquote.dtx
file with LaTeX. Do it twice for correct references. It will generate apullquote.sty
file and the documentation filepullquote.pdf
. Place the files where your LaTeX can find them, or simply in the document's folder. - Start with a document class and the
lipsum
package for dummy text, and load thepullquote
package:\documentclass{article} \usepackage{lipsum} \usepackage{pullquote}
- Create a command that prints your quotation in a paragraph box:
\newcommand{\myquote}{% \parbox{4cm}{ \hrule\vspace{1ex} \textit{I can't go to a restaurant and order food because I keep looking at the fonts on the menu.} \hfill Knuth, Donald (2002)% \vspace{1ex} \hrule }% }
- In the document, use a
pullquote
environment with the self-defined macro in the argument, and dummy text, as follows:\begin{document} \begin{pullquote}{object=\myquote} \lipsum[1] \end{pullquote} \end{document}
- Compile and have a look:
How it works...
We loaded the lipsum
package, which gives us filler text. Then we loaded the pullquote
package. We defined a macro, which prints the quotation.
For our example, we made a paragraph box with lines above and below, printing italic text and the author's name at the right. To avoid undesired white space, we commented out the line breaks in some places by putting a %
sign at the end.
In the document, we simply made a pullquote
environment with that macro as a pulled object within the argument, and lipsum
text for filling the surrounding space.
The pullquote
package does the rest for us. It does the following things:
- It puts the object into a box
- It measures height and width
- It adds space for the distance
- It normalizes the total height to be an integral multiple of the value specified for the
\baselineskip
command to match a number of text lines - It calculates the vertical position
- It calculates a shape for the paragraph
- It balances the text columns according to the shape
- It arranges all and prints the whole construct
There are some restrictions. Mainly, the text within the environment should be simple paragraphs of text. This means that lists such as itemize, displayed math, section headings, and modified vertical spacing in general, are undesirable. Such non-simple elements may trouble the calculation. However, it's already great for images and text boxes.
There's more...
The key=value
list in the argument of the pullquote
package understands further parameters. Besides the default rectangular shape, there's a circular one. We can specify it via the shape
option. The following example will demonstrate it. We will create a TikZ picture to have an actual circled element to place in. So, we need to load the TikZ package as well.
You can verify it with this sample code, similar to the preceding code:
\documentclass{article} \usepackage{lipsum} \usepackage{pullquote} \usepackage{tikz} \newcommand{\mylogo}{% \begin{tikzpicture} \node[shape=circle,draw=gray!40,line width=3pt, fill={gray!15},font=\Huge] {\TeX}; \end{tikzpicture}% } \begin{document} \begin{pullquote}{shape=circular,object=\mylogo} \lipsum[1] \end{pullquote} \end{document}
The code will produce this layout:

TikZ is a very capable graphics package. You can read more about it in Chapter 9, Creating Graphics. We could also have used a circular image instead. For this, refer to the recipe Shaping an image like a circle in the next chapter.
For arbitrary shapes specified by shape functions, refer to the package manual. It also explains image inclusion support with the shape=image
list. Then, the cut-out dimensions would be calculated from the image dimensions. For this, the free ImageMagick program would need to be installed on the system, since it would then be called internally.
- Advanced Machine Learning with Python
- Visual Basic .NET程序設(shè)計(jì)(第3版)
- TypeScript入門與實(shí)戰(zhàn)
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- Learning Selenium Testing Tools with Python
- Developing Mobile Web ArcGIS Applications
- Reactive Programming With Java 9
- EPLAN實(shí)戰(zhàn)設(shè)計(jì)
- Drupal 8 Module Development
- Android移動(dòng)開發(fā)案例教程:基于Android Studio開發(fā)環(huán)境
- Spring Data JPA從入門到精通
- 量子計(jì)算機(jī)編程:從入門到實(shí)踐
- ArcPy and ArcGIS(Second Edition)
- SCRATCH編程課:我的游戲我做主
- 微信公眾平臺(tái)服務(wù)號(hào)開發(fā):揭秘九大高級(jí)接口