# Displayed, single line equations with quantifiers aligned to the left

Is there an environment (or standard framework) to typeset a (single line) displayed equation with a "short" quantification that gives the following result? That is, the "main" part of the equation is centered (as if nothing else were there), and the quantifier part is aligned to the left with some indentation. I don't think this is supposed to work for longer strings, and I am not looking for a solution that does.

I have found similar questions here (e.g. equation center, quantifier push right), but solutions like

\begin{flalign}
\forall x \in X  &&&  P(x)  &&
\end{flalign}


are not what I'm looking for since $P(x)$ is not centred within the page, and $\forall x\in X$ is not indented. Adding

\begin{flalign}
\qquad \forall x \in X  &&&  P(x)  &&
\end{flalign}


does seem to get the desired indentation, but $P(x)$ is now even less centred.

• your image shows an unnumbered equation but your code fragments use flalign rather than flalign* so produce numbered equations. (This has a bearing on the answers see for example Mico's comment on @Bernard's question which wouldn't apply in the unnumbered case) – David Carlisle Dec 16 '18 at 21:42
• That's true, and I apologise for the confusion. As I mentioned in a comment under Mico's answer, I was looking for a solution that would support equation numbering. – prt13463 Dec 16 '18 at 23:13

Here's a proposal that does the centering when feasible, resorting to standard centering otherwise. (Thanks to Mico for the coding.)

\documentclass{book}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{environ}

\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]

\newcommand\bff{\mathbf{f}}
\newcommand\bfg{\mathbf{g}}

\makeatletter
\NewEnviron{quantifiedequation}[1]{% #1 is the quantifiers
$$\expandafter\make@quantifiedequation\expandafter{\BODY}{#1}$$
}
\NewEnviron{quantifiedequation*}[1]{% #1 is the quantifiers
\begin{equation*}$$\expandafter\make@quantifiedequation\expandafter{\BODY}{#1}$$\end{equation*}
}
\newcommand{\make@quantifiedequation}[2]{%
\m@th % remove mathsurround
\sbox\z@{$\displaystyle#2$}% measure the quantifiers
\sbox\tw@{\let\label\@gobble$\displaystyle#1$}
\ifdim\dimexpr 1em+\wd\z@+0.5\wd\tw@+2em>0.5\displaywidth
% centering is not possible
\else
\makebox[0pt][r]{%
}#1
\fi
}
\makeatother

\begin{document}
\setcounter{chapter}{1}
\setcounter{section}{1}
\setcounter{defn}{12}

\begin{defn}
Let $M$ be a manifold. A \emph{derivation} at a point $p\in M$
is an $\mathbb{R}$-linear map $X\colon C^\infty(p)\to\mathbb{R}$
which satisfies the \emph{Leibniz rule}
\begin{quantifiedequation*}{\forall\,\bff,\bfg\in C^\infty(p)}
X(\bff\bfg)=\bff(p)X(\bfg)+\bfg(p)X(\bff)
\end{quantifiedequation*}
\end{defn}

\begin{defn}
Let $M$ be a manifold. A \emph{derivation} at a point $p\in M$
is an $\mathbb{R}$-linear map $X\colon C^\infty(p)\to\mathbb{R}$
which satisfies the \emph{Leibniz rule}
\begin{quantifiedequation}{\forall\,\bff,\bfg\in C^\infty(p)}
X(\bff\bfg)=\bff(p)X(\bfg)+\bfg(p)X(\bff)
\label{qeq}
\end{quantifiedequation}
\end{defn}

Here's the reference \eqref{qeq}.

\begin{defn}
Let $M$ be a manifold. A \emph{derivation} at a point $p\in M$
is an $\mathbb{R}$-linear map $X\colon C^\infty(p)\to\mathbb{R}$
which satisfies the \emph{Leibniz rule}
\begin{quantifiedequation*}{\forall\,\bff,\bfg\in C^\infty(p)}
X(\bff\bfg)=\bff(p)X(\bfg)+\bfg(p)X(\bff)
+\bff(p)X(\bfg)+\bfg(p)X(\bff)
\end{quantifiedequation*}
\end{defn}
\end{document}


I'm not aware of a ready-made environment or "standard framework" that does exactly what you're looking to achieve. However, it's not too much work to create a custom macro that gets the job done.

Note that the macro \quant -- you're obviously free to choose a different name for this macro -- takes 2 arguments: the quantifier (which is indented by \quad from the left-hand edge of the text block; feel free to change the indentation amount) and the actual equation. Do note that because the equation is centered exactly on the line, the whitespace to its left and right won't be of equal length (since the whitespace on the left is reduced by the presence of the quantier).

Observe that equation numbering isn't an option, but then I got the impression that automatic equation numbering isn't a requirement. Do advise if it is.

Observe also that if quantifier and/or the equation are quite long, they will likely overlap in a very unsightly way. I gather, though, that this is not likely to be an issue.

\documentclass{report}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amsthm}
\theoremstyle{definition}
\newtheorem{defn}{Definition}
\counterwithin{defn}{section}

%% Set up a macro called "\quant":
\newcommand{\quant}[2]{\par%
\vspace{\abovedisplayskip}%
\noindent%
\parbox{0pt}{\mbox{\quad$\displaystyle #1$}}
\hfil $\displaystyle #2$ \hfill\par
\vspace{\belowdisplayskip}}

\newcommand\bff{\mathbf{f}}
\newcommand\bfg{\mathbf{g}}

\begin{document}
\setcounter{chapter}{1}
\setcounter{section}{1}
\setcounter{defn}{12}

\begin{defn}
Let $M$ be a manifold. A \emph{derivation} at a point $p\in M$
is an $\mathbb{R}$-linear map $X\colon C^\infty(p)\to\mathbb{R}$
which satisfies the \emph{Leibniz rule}
\quant{\forall\,\bff,\bfg\in C^\infty(p)}{%
X(\bff\bfg)=\bff(p)X(\bfg)+\bfg(p)X(\bff)}
\end{defn}
\end{document}

• Thank you. Actually, yes, it's not a huge deal-breaker, but it would be helpful if this supported equation numbering. I understand that egreg improved your code to implement this. Thanks to both! – prt13463 Dec 16 '18 at 22:42

\documentclass{article}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}
\usepackage{mathtools}

\begin{document}

\begin{flalign}
\quad \mathrlap{\forall x \in X} &&& P(x) &&
\end{flalign}

\end{document}


• With this approach, P(x) won't be place exactly in the center of the entire line. Instead, it will be centered on the line segment that stretches from the left-hand edge of the text block to (but not including) the equation number. Is there a way to achieve full centering (which seems to be one of the OP's formatting objectives)? – Mico Dec 16 '18 at 21:06
• @Mico: Strangely, my code is the closest to the expected result (lengths difference < 1pt between both blank spaces). Adding a \quadon the right side makes the difference greater (6 to 7 pt). So clearly there are placement details I have no control on. – Bernard Dec 16 '18 at 21:36
• Although I have accepted egreg's answer, this also works well and produces the desired output. – prt13463 Dec 16 '18 at 23:10