- LaTeX Cookbook
- Stefan Kottwitz
- 685字
- 2021-07-09 21:25:01
Typesetting in a grid
Besides full horizontal justification, LaTeX also adjusts the page content vertically to get a consistent page height. So, internal spacing is often variable. Furthermore, implicit spaces are often independent of the baseline height.
Consequently, lines of adjacent pages may look shifted. For two-sided prints with very thin paper, matching base lines would look much better. Especially in two-column documents it may be desirable to have baselines of adjacent lines at exactly the same height.
In this recipe, we would like to arrange lines on a grid. Normal text lines will be placed at a baseline grid. Displayed formulas, figures, tables, and captions are allowed to have a different baseline, but the following text should return to the grid.
How to do it...
We will use the grid
package, which has been developed for grid typesetting. Follow these steps:
- Prepare a small, two-column example with dummy text, where we can apply the
grid
commands. Here is a simple code snippet that you can use for a start:\documentclass{article} \usepackage[english]{babel} \usepackage{blindtext} \usepackage{microtype} \begin{document} \twocolumn \section*{Two columns} \blindtext[3] \begin{figure} \centering \fbox{\makebox(50,50){}} \caption{A dummy figure} \end{figure} \begin{equation} \sum_n f(n) \end{equation} Text \end{document}
- Take a first look. Compare the height of the text lines in the left- and right-hand columns. Note that the baselines of the text are not yet aligned:
- Now, add the
grid
package to the preamble with font size options, as follows:\usepackage[fontsize=10pt,baseline=12pt]{grid}
- Then, put the equation into a
gridenv
environment. It will look like this:\begin{gridenv} \begin{equation} \sum_n f(n) \end{equation} \end{gridenv}
- Compile the document and take a look at what has changed. Examine the baselines in the following screenshot closely:
How it works...
We specified the font size and the base line height as options to the grid
package because the default settings don't look right.
The grid
package makes some changes that helps the lines to stay in the grid. This is how it works:
- So-called glue, also known as rubber space, which is elastic space, is removed or replaced by a fixed space.
- The heights of many frequently-used items were made integral multiples of the baseline height so that they would fit exactly to the grid. This has been made, for example, for the following:
- Section headings
- Figures and tables
- Displayed equations
We did this here, and got a quick solution for double-column grid typesetting, at least in a limited way. For example, we need to accept the changed section heading size.
There's more...
The gridset
package provides a command, \vskipnextgrid
, which jumps the next grid position. It can be used as a simple fix, without being a complete solution. It requires two or more typesetting runs until all is adjusted. So you need to look at the affected place and repeat compiling if needed, especially if you use \vskipnextgrid
repeatedly.
This command can also be used in addition to the grid
package. In a case where the grid
package might fail, we can correct this by inserting the \vskipnextgrid
command.
For example the amsmath
package's multiline displayed equations could be a problem for the grid
package. We can fix this as follows:
- Load
amsmath
using the following command:\usepackage{amsmath}
- Also load the
gridset
package by using the following command:\usepackage{gridset}
- In the document, create an
align
environment, as follows:\begin{align} y &= \sum_{n=1}^3 f(n) \\ &= f(1) + f(2) + f(3) \end{align}
- Directly after it, add the following line. It ends the paragraph, skips to the next position in the grid, and avoids inserting paragraph indentations:
\par\vskipnextgrid\noindent
- Add some text following it.
- Compile the document once. The position of the previously-added text may still not yet fit the grid.
- Compile again. The
\vskipnextgrid
command will again adjust the spacing to match the base line grid.
The \vskipnextgrid
command may have problems in two-column mode. In this case, we fixed it by breaking the paragraph, adjusting the position, and suppressing the following paragraph indentation, because that is unusual after a displayed formula.
- TypeScript入門與實戰
- jQuery EasyUI網站開發實戰
- 基于Java技術的Web應用開發
- Learn Programming in Python with Cody Jackson
- Python自然語言處理(微課版)
- Hands-On Microservices with Kotlin
- 大學計算機基礎(第2版)(微課版)
- JavaCAPS基礎、應用與案例
- ServiceNow:Building Powerful Workflows
- C#程序設計(項目教學版)
- 新印象:解構UI界面設計
- Java程序設計與項目案例教程
- IBM Cognos TM1 Developer's Certification guide
- Python面向對象編程(第4版)
- Mobile Test Automation with Appium