I have found a strange "bug", where my equations do not seem to be aligned correctly when using the geometry package. I try to explain this behavior in more detail using this MWE:

\documentclass[ a4paper, 12pt ]{book}

\RequirePackage[]{geometry}    % works, when this line is deleted


%\section{TEST}    % does work
\chapter{TEST}     % does not work

This is an equation
  \mathbf{A}(t) =  \frac{ a b c d e f }{\pi} \operatorname{lim} \left[ \mathcal{X}_a[\boldsymbol{\mu}(t)](a+b) + \mathcal{X}_a[\boldsymbol{\mu}(t)](a+b) + d e f \right].
And this is an equation
  \mathbf{B}(t) =\frac{a}{\pi} \operatorname{lim} \left[ \frac{ \mathcal{X}_a[\boldsymbol{\mu}(t)](a+b) + \boldsymbol{\mu}(0) }{a + b} + \frac{ \mathcal{X}_a[\boldsymbol{\mu}(t)](a+b) + \boldsymbol{\mu}(0) }{a - b} \right].


As you can see, two (meaningless) equations are shown below each other in this very simple document. Strangely, when compiled, the second equation is not aligned to the center, but is clearly shifted to the left. Its horizontal alignment is broken.

Even more strangely, this bug does only occur, if I use a \chapter, but not, if I use a \section in the beginning. Furthermore, it seems to be tied to the geometry package. When this package is turned off, the alignment works again. It is also worth to mention that only some equations seem to be off the center - most certainly depending on certain characters (probably amsmath symbols) which they contain.

I have absolutely no idea whats going on although I really tried a lot to solve this. Can you please help me to get my equations aligned properly?

Remark: I was able to reproduce this bug on different systems.

  • 2
    When an equation is “too near” to the equation number, it is shifted left; the amount of shifting is so that “space before+equation+space after+equation number = line width”, with equal spaces before and after. This is “by design”, so not a bug at all. – egreg Oct 28 '15 at 11:26
  • Are you sure? So why does it depend on geometry and \chapter? – Hendrik Oct 28 '15 at 11:32
  • 1
    Using geometry changes the line width; with no \chapter, the equation number doesn't have a prefix, while its size increases when \chapter is issued. – egreg Oct 28 '15 at 11:33
  • Thank you for this information. I was not aware of that centering constraint and I think it does not look good. Can you give me a hint how these limits can be configured? – Hendrik Oct 28 '15 at 11:35
  • They're built in TeX (at least for equation, which uses the primitive setting); the amsmath environments do no different. The treshold is exactly the width of the equation number; if the space between the centered equation is less than this width, the centering is done in the available space (line width minus width of equation number); amsmath just adds that, if no space remains, the equation number is shifted down. – egreg Oct 28 '15 at 11:55

The behavior you see is not a bug, but a consequence of how TeX has been written.

Let's examine the case of equation, which is also followed by the amsmath environments that just add the shifting down of the equation number in case the equation is overlong.

The rules are not really straightforward, but basically they are as follows (it's a simplified version, but not far from the truth).

  1. Measure the horizontal size available for the equation (usually the line width), d

  2. Measure the width of the equation, w

  3. Measure the size of the equation number, e

  4. Try centering the equation, which would leave a space (dw)/2 on either side

  5. If (dw)/2 – e < e, center the equation in the available space de

These rules are built in and there's no way of changing them, besides using a hand-made alignment.

The tentatively centered equation is considered too near to the equation number (case 5) if the space between the equation and the equation number is less than the width of the equation number itself, in order to keep a good visual distinction.

Your cases show different results for several reasons

  1. \usepackage{geometry} changes the standard line width of the book class

  2. If no \chapter command is issued, the equation number has no prefix

  3. When \chapter is issued, the first equation number becomes (1.1), which is wider than (1), so triggering step 5 countermeasure.

You may not like it, but that's what TeX does. The inequality evaluated in step 5 is hardwired and there's no way to change them (except by rewriting TeX).

The full description can be found on pages 188–189 of the TeXbook.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.