gathered unexpectedly wider than its “natural” width

I have a gathered environment inside a multlined environment inside an equation environment. For some reason the gathered-environment is wider than its natural width. Here is a MWE

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\begin{document}

Equation looks like expected:

$$\left\lvert \begin{multlined} \Pr\left[ 1 \gets A(s) \middle\vert s \gets F(G) \right]\\ {} - \Pr\left[ 1 \gets A(s') \middle\vert (s', t) \gets S(G) \right] \end{multlined} \right\rvert$$

Equation with unexpected wide \verb#gathered#-environment

$$\left\lvert \begin{multlined} \Pr\left[ 1 \gets A\left( \begin{gathered}% <-- This is the problematic environment s',\\ m \end{gathered} \right) \middle\vert \begin{gathered} s \gets F,\\ m \gets M \end{gathered} \right]\\ {} - \Pr\left[ 1 \gets A\left( \begin{gathered} s'\\ m \end{gathered} \right) \middle\vert \begin{gathered} s' \gets F,\\ c \gets G \end{gathered}\right] \end{multlined} \right\rvert$$
\end{document}


Note: I know I could workaround the problem by using an array-environment within the parentheses in the second equation. However, I deliberately refrained from that, because of "semantic" programming. I tried to follow the rule (mathematical) vectors are coded as array's, a single equation or term that is too long for a single line is put into a multline and gather is for multiple equations without special alignment. Although, left( \begin{gathered}s',\\m\end{gathered}\right) might appear as it was a vector, it is actually not. In the full code s' and m are two equations. I have shortened them down for the sake of this MWE. Hence, I would prefer to stay with gathered.

Also, I would like to know what goes wrong here.

• And with pmatrix? – Bernard Jun 7 at 14:09
• @Bernard Of course, it works with pmatrix. (I believe to have read that pmatrix is based on array.) However the same argument applies here: The code inside gathered is not a vector but a system of equations that are logically "and'ed". Hence, I would like to use gathered, because gathered is for systems of equations and array for vectors. Moreover, the horizontal padding around a array or pmatrix is slightly different than around a gathered. – nagmat84 Jun 7 at 14:29

Looks like a bug in mathtools and/or amsmath but a workaroud might be

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\begin{document}

Equation looks like expected:

$$\left\lvert \begin{multlined} \Pr\left[ 1 \gets A(s) \middle\vert s \gets F(G) \right]\\ {} - \Pr\left[ 1 \gets A(s') \middle\vert (s', t) \gets S(G) \right] \end{multlined} \right\rvert$$

Equation with unexpected wide \verb#gathered#-environment

\newsavebox\oops
\savebox\oops{$\begin{gathered}% <-- This is the problematic environment s',\\ m \end{gathered}$}
$$\left\lvert \begin{multlined} \Pr\left[ 1 \gets A\left(\usebox\oops \right) \middle\vert \begin{gathered} s \gets F,\\ m \gets M \end{gathered} \right]\\ {} - \Pr\left[ 1 \gets A\left( \begin{gathered} s'\\ m \end{gathered} \right) \middle\vert \begin{gathered} s' \gets F,\\ c \gets G \end{gathered}\right] \end{multlined} \right\rvert$$
\end{document}

• The documentation mentions "Bug 2: Due to the way multilined is implemented, certain constructions does not work inside multlined.". gathered seems to be one of it. – Ulrike Fischer Jun 7 at 15:04
• @UlrikeFischer "Documentation" what's that? – David Carlisle Jun 7 at 15:06
• @DavidCarlisle you need a german keyboard to find it, at some time I will buy you one ;-). – Ulrike Fischer Jun 7 at 15:18