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

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:

  1. 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.
  2. Click on browse files and also download the pq-alice.jpg, pq-duck.pdf, and pullquote_test.tex files, to get filler images and a sample file.
  3. Compile the pullquote.dtx file with LaTeX. Do it twice for correct references. It will generate a pullquote.sty file and the documentation file pullquote.pdf. Place the files where your LaTeX can find them, or simply in the document's folder.
  4. Start with a document class and the lipsum package for dummy text, and load the pullquote package:
    \documentclass{article}
    \usepackage{lipsum}
    \usepackage{pullquote}
  5. 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
      }%
    }
  6. 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}
  7. Compile and have a look:
    How to do it...

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:

There's more...

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.

主站蜘蛛池模板: 玉环县| 津南区| 杭锦后旗| 巴楚县| 清流县| 修水县| 宁都县| 呼伦贝尔市| 赣州市| 泽州县| 鲜城| 平定县| 万源市| 瑞金市| 怀柔区| 深水埗区| 乌鲁木齐县| 曲靖市| 桐庐县| 定西市| 昭平县| 射阳县| 华池县| 景泰县| 嘉鱼县| 蕉岭县| 左云县| 阿荣旗| 扎赉特旗| 黑山县| 鄱阳县| 孟村| 庄河市| 望江县| 桐城市| 颍上县| 乾安县| 大同市| 托克逊县| 城步| 河源市|