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

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:

  1. 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}
  2. 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:
    How to do it...
  3. Now, add the grid package to the preamble with font size options, as follows:
    \usepackage[fontsize=10pt,baseline=12pt]{grid}
  4. 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}
  5. Compile the document and take a look at what has changed. Examine the baselines in the following screenshot closely:
    How to do it...

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

Note

It's recommended that you enclose the equation environments within a gridenv environment for proper spacing.

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.

Note

At the time of writing, the package was in alpha status.

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:

  1. Load amsmath using the following command:
    \usepackage{amsmath}
  2. Also load the gridset package by using the following command:
    \usepackage{gridset}
  3. 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} 
  4. 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
  5. Add some text following it.
  6. Compile the document once. The position of the previously-added text may still not yet fit the grid.
  7. 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.

主站蜘蛛池模板: 乐昌市| 克拉玛依市| 台北市| 江永县| 水富县| 天柱县| 德江县| 昆明市| 金湖县| 金华市| 铁岭市| 五河县| 灵石县| 汾西县| 白沙| 双江| 深州市| 兰西县| 龙泉市| 阿拉善左旗| 崇文区| 桂林市| 新余市| 右玉县| 增城市| 阿荣旗| 舟山市| 灌阳县| 台中市| 阿拉善右旗| 永昌县| 屯门区| 翼城县| 新化县| 晋州市| 清水河县| 高邮市| 莆田市| 宣威市| 大关县| 宁明县|