3

I have the following problem: I am writing my PhD and the alignat environment changes the behaviour during the document. Here is an example:

\documentclass[12pt, a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[english]{varioref}
\usepackage[fleqn]{amsmath}

\begin{document}
    \frontmatter
    \chapter*{A}
        This is a string which tests the text width. This is a string which tests the text width. This is a string which tests the text width.

        \begin{alignat}{3}
            & \big\{\phi_{B^\prime}(v) | \mbox{$v \in V$ is a leaf of $G$}\big\}
                && = \big\{b \in B | \iota(b) \not\equiv d \mod d\big\}\\
            \intertext{and}
            & \big\{\phi_{B^\prime}(v) | \mbox{$v \in V$ is not a leaf of $G$}\big\}
                && = \big\{b \in B | \iota(b) \equiv d \mod d\big\}.
        \end{alignat}

    \mainmatter
    \chapter{B}
        This is a string which tests the text width. This is a string which tests the text width. This is a string which tests the text width.

        \begin{alignat}{3}
            & \big\{\phi_{B^\prime}(v) | \mbox{$v \in V$ is a leaf of $G$}\big\}
                && = \big\{b \in B | \iota(b) \not\equiv d \mod d\big\}\\
            \intertext{and}
            & \big\{\phi_{B^\prime}(v) | \mbox{$v \in V$ is not a leaf of $G$}\big\}
                && = \big\{b \in B | \iota(b) \equiv d \mod d\big\}.
        \end{alignat}
\end{document}

After using \mainmatter the alignat environment changes its behaviour. I tried to use \pagenumbering{arabic}, but it did not help.

Is it a bug? Or do I something wrong?

Thank you very much for your answer.

Best regards, T

  • Other than (1) vs (1.1) I do not see any difference – daleif Jan 07 '16 at 15:23
  • \mainmatter switches chapter counting on, i.e. \frontmatter will use unnumbered chapters, regardless, whether \chapter or \chapter* is used. As such, the equation number is now (1.1) (wider than before) –  Jan 07 '16 at 15:29
  • No, the alignments around the “=” are in the second case wrong (before “=” is additional space and the line width is exceeded (without yielding a warning)). – user94645 Jan 07 '16 at 15:30
  • From book.cls: \renewcommand\theequation {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@equation} -- i.e. as long as the chapter number is zero, it will not be prepended to the equation number, i.e. \mainmatter increases the counter output and that's to wide for alignat –  Jan 07 '16 at 15:37
  • There's certainly a issue with \frontmatter and the fleqn option, which seems to be triggered when the equation is rather wide. – egreg Jan 07 '16 at 15:49
  • Thank you, I tried now to remove the fleqn option and than all is OK. So there is no problem with the chapter number in this concrete case. However, I would like to use the fleqn option due to other equations. – user94645 Jan 07 '16 at 15:53
  • this problem was noted in 1996, and allegedly fixed in the 1997 release of amsmath; it is not a problem when used with an ams document class, but with [12pt]{book} it reappears. it has been re-posted to the "live" amsmath bugs list. thank you for the reliably working example. – barbara beeton Jan 07 '16 at 20:56

2 Answers2

2

It is not a mainmatter/frontmatter issue. But due to the larger number the equation is a bit too long for the line and then alignat pushes the number in the margin. I don't know if it is intended or a bug or simply can't be avoided. You probably will have to shorten your equation.

\documentclass[12pt, a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[english]{varioref}
\usepackage[fleqn]{amsmath}

\begin{document}
    \mainmatter
    \chapter{A}
        This is a string which tests the text width. This is a string which tests the text width. This is a string which tests the text width.

        \begin{alignat}{3}
            &a
                && = b\\            
        \end{alignat}

        \begin{alignat}{3}                         
            &a
                && = btests the text width. This is a string which tests the text width\\                
        \end{alignat}
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Yes, but in the first case there (in my example) there is enough space. The problem is the unnecessary free space before “=” in the second case. The numbers of equations are usually on a new line if the expression is too long. – user94645 Jan 07 '16 at 15:32
  • You are saying that there is enough space, but obviously latex doesn't. If I shorten both equations a bit the numbers are again in the text (not using fleqn helps too). – Ulrike Fischer Jan 07 '16 at 15:44
  • definitely a bug. see comment on original question. – barbara beeton Jan 07 '16 at 20:57
2

It seems to be a bug of alignat when fleqn is active and the equation is too wide.

I can offer you a workaround (see https://tex.stackexchange.com/a/209732/4427)

\documentclass[12pt, a4paper,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[english]{varioref}
\usepackage[fleqn]{amsmath}

\makeatletter
\newcommand{\Lft}[2]{%
  \ifmeasuring@
    #2%
  \else
    \makebox[\ifcase\expandafter #1\maxcolumn@widths\fi][l]{$\displaystyle#2$}%
  \fi
}
\makeatother


\begin{document}

\frontmatter

\chapter{A}

This is a string which tests the text width. This is a string which tests the text width. This is a 
string which tests the text width.
\begin{align}
  \Lft{1}{\bigl\{\phi_{B'}(v) \mid \text{$v \in V$ is a leaf of $G$}\bigr\}}
  & = \bigl\{b \in B \mid \iota(b) \not\equiv d \mod d\bigr\}
\intertext{and}
  \Lft{1}{\bigl\{\phi_{B'}(v) \mid \text{$v \in V$ is not a leaf of $G$}\bigr\}}
  & = \bigl\{b \in B \mid \iota(b) \equiv d \mod d\bigr\}.
\end{align}

\mainmatter

\chapter{B}

This is a string which tests the text width. This is a string which tests the text width. This is a 
string which tests the text width.
\begin{align}
  \Lft{1}{\bigl\{\phi_{B'}(v) \mid \text{$v \in V$ is a leaf of $G$}\bigr\}}
  & = \bigl\{b \in B \mid \iota(b) \not\equiv d \mod d\bigr\}
\intertext{and}
  \Lft{1}{\bigl\{\phi_{B'}(v) \mid \text{$v \in V$ is not a leaf of $G$}\bigr\}}
  & = \bigl\{b \in B \mid \iota(b) \equiv d \mod d\bigr\}.
\end{align}

\end{document}

I used oneside just in order to show the pages side by side.

enter image description here

On the other hand, I'd simply use gather for this case, but of course two equation environments would do as well (and even better).

This is a string which tests the text width. This is a string which tests the text width. This is a
string which tests the text width.
\begin{equation}
\bigl\{\phi_{B'}(v) \mid \text{$v \in V$ is a leaf of $G$}\bigr\}
= \bigl\{b \in B \mid \iota(b) \not\equiv d \mod d\bigr\}
\end{equation}
and
\begin{equation}
\bigl\{\phi_{B'}(v) \mid \text{$v \in V$ is not a leaf of $G$}\bigr\}
= \bigl\{b \in B \mid \iota(b) \equiv d \mod d\bigr\}.
\end{equation}

enter image description here

egreg
  • 1,121,712
  • Thank you very much for your solution! You are right that it looks better with the equation environment. However, I have the same problem on many places of my PhD thesis and thus I use the first solution as well. – user94645 Jan 07 '16 at 16:16