- LaTeX Cookbook
- Stefan Kottwitz
- 488字
- 2021-07-09 21:25:02
Fitting text to a shape
There are occasions when text is not strictly arranged in a rectangular box. For example, if you would like to print a label for a DVD or compact disc, the text should be arranged in a circle.
How to do it...
The shapepar
package can typeset paragraphs in a specific shape, such as a circle, a hexagon, or a heart. The shape size will be adjusted so the given text fits in. We will now try it with a heart:
- Make a small document, load the packages
blindtext
(for dummy text) and theshapepar
package:\documentclass{article} \usepackage{blindtext} \usepackage{shapepar}
- In the document, use the
\shapepar
command with the shape argument, and then text as follows:\begin{document} \shapepar{\heartshape}\blindtext[2] \end{document}
- Compile and have a look:
How it works...
We loaded the blindtext
package, which provides filler text via the \blindtext
command, which is great for testing. Then we loaded the shapepar
package.
That package provides the command \shapepar
, which is used as follows:
\shapepar[scale length]{shape command} text of the paragraph
Here, we used the \heartshape
command as the shape command, which typesets the following paragraph of text with the shape of a heart. The shape applies only to the following paragraph. The paragraph is not an argument.
The scale length
value is optional. It's a LaTeX length, which will be used as a base unit within the shape definition. If not given, it's automatically calculated for optimal filling of the shape.
There's another short command:
\heartpar{text}
It works as follows:
\shapepar{\heartshape} text\ \ $\heartsuit$\par
It prints the text in the shape of a heart and ends it with a heart symbol.
There's more...
We can shape text in various ways. Furthermore, we can let text flow around a shape. In other words, we can cut out shapes from the text.
The following shapes and corresponding commands are predefined:

The last shape doesn't provide another command. Use it as follows:
\shapepar{\rectangleshape{40}{20}} text
Use it without the units for the length, as the command refers to the base unit length of the shape. The holes mentioned in the preceding table are circular.
A companion of the \shapepar
command can cut out text using a shape:
\cutout {side} (horizontal offset,vertical offset) settings \shapepar ...
This cuts out the text with the specified shape from the following text. The side
option can be l
or r
for left or right, respectively. You can use offsets for shifting settings as optional code. It can contain commands such as modifying the \cutoutsep
command, which is the separation between outer text and shaped text, 12 pt by default. These commands have only a local effect.
For further details, refer to the package's manual. Since a good example is missing there, here's one, simply working within the code from our preceding recipes:
\cutout{l} (5ex,2\baselineskip) \setlength{\cutoutsep}{8pt} \shapepar{\circleshape} a few words of text\par \blindtext
This will generate the following as output:

- C語言程序設(shè)計(jì)實(shí)踐教程(第2版)
- Python for Secret Agents:Volume II
- Mastering Concurrency in Go
- Python網(wǎng)絡(luò)爬蟲從入門到實(shí)踐(第2版)
- Practical Windows Forensics
- SQL Server 2016數(shù)據(jù)庫應(yīng)用與開發(fā)習(xí)題解答與上機(jī)指導(dǎo)
- SAP BusinessObjects Dashboards 4.1 Cookbook
- 區(qū)塊鏈底層設(shè)計(jì)Java實(shí)戰(zhàn)
- Java高并發(fā)核心編程(卷1):NIO、Netty、Redis、ZooKeeper
- Azure Serverless Computing Cookbook
- MINECRAFT編程:使用Python語言玩轉(zhuǎn)我的世界
- PrimeFaces Blueprints
- QPanda量子計(jì)算編程
- C++ System Programming Cookbook
- AngularJS UI Development