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

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.

主站蜘蛛池模板: 三明市| 保康县| 富平县| 达拉特旗| 托克托县| 达孜县| 乐昌市| 应城市| 拉萨市| 诸暨市| 滦南县| 张家界市| 印江| 绵阳市| 呼伦贝尔市| 孝昌县| 图片| 平顶山市| 伽师县| 九江市| 祁连县| 神池县| 即墨市| 南丹县| 黄大仙区| 宁明县| 洛南县| 庄河市| 临沭县| 兴山县| 泾川县| 太仆寺旗| 镇赉县| 弋阳县| 许昌市| 泸州市| 八宿县| 施秉县| 南木林县| 昌黎县| 双流县|