# equation custom horizontal alignment & numbering each row

As I know, "align" has the fixed horizontal alignment right-left-right-left-..., and we cannot change this alignment. So if we want to align equations with custom horizontal alignment, e.g., right-center-center-left, we may use "equation" or "gather", "array", "arraycolsep" (for spacing "=" like "align"), and "displaystyle" (for proper handling of "frac" or "lim").

For example,

\newcommand{\argmax}{\operatornamewithlimits{arg\,max}}
...
\begin{gather}
\arraycolsep=1.4pt\def\arraystretch{2.2}
\begin{array}{rccl}
p_{\mathrm{MLE}}(x) & = & \displaystyle \max_{m} &P(X = x | \theta = m) \\
m_{\mathrm{MLE}}(x) & = & \displaystyle \argmax_{m} &P(X = x | \theta = m)
\end{array}
\end{gather}


produces below.

However, this has the only one numbering label. It cannot split numbers for each row. It may be one BAD choice to use "align" and adjust spacing MANUALLY by using "\,", "\phantom{}", "\quad", or "\qquad".

For this case, how can we label different numbers for each row?

• You probably already know about the option \notag that removes the numbering of one row in align environment. I think there must be something similar, but instead it forces a tag for each entry in multi-rows of math environments. What you ask is indeed interesting and I am waiting to find the answer – Al-Motasem Aldaoudeyeh Jun 30 '17 at 2:54
• Off-topic: Don't use | to denote "given that" items. Instead, write \mid. – Mico Jun 30 '17 at 8:04
• A newenvironment here could help... But I am waiting for an answer in a problem I found trying to manipulate the rows of my newenvironment... I will come back for an answer... But have to study a little bit about newenvironments – koleygr Jun 30 '17 at 8:08

Since you're using the amsmath package, I would use that package's \DeclareMathOperator* directive to create two new "operators": \argmax and \midmax, where the latter displays the word "max" centered in a box of width equal to "arg max". I would also use a split environment instead of an array environment, an equation environment instead of a gather environment, and \mid instead of \.

If you need to number each row separately, use an align environment instead of the nested equation/ split environments.

\documentclass{article}
\usepackage{amsmath}
%% Create two new math opertors: \argmax and \midmax
\DeclareMathOperator*{\argmax}{arg\,max}
\newlength\mylen
\settowidth\mylen{arg\,max}
\DeclareMathOperator*{\midmax}{\parbox{\mylen}{\centering\upshape max}} % center-set "max"
\begin{document}

%% Single equation number for both rows:
$$\begin{split} p_{\mathrm{MLE}}(x) &= \midmax_{m} P(X = x \mid \theta = m) \\ m_{\mathrm{MLE}}(x) &= \argmax_{m} P(X = x \mid \theta = m) \end{split}$$

% Separate equation numbers, one per row:
\begin{align}
p_{\mathrm{MLE}}(x) &= \midmax_{m} P(X = x \mid \theta = m) \\
m_{\mathrm{MLE}}(x) &= \argmax_{m} P(X = x \mid \theta = m)
\end{align}
\end{document}