1

The equations produced by this code are centered

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{cleveref}
\begin{document}
\begin{align}
    & \mathclap{f: A \to B, g: B \to C} \label{eq:1}
    \\
    f(a) &= \ldots \label{eq:2}
    \\
    g(b) &= \ldots \label{eq:3}
\end{align}
\end{document}

enter image description here

whereas these are no longer centered. Equation 1 is not centered like how normal humans would center it. Why is this so? Or is that considered centered for latex?

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{cleveref}
\begin{document}
\begin{align}
    \mathclap{\alpha_{s,j}^t = g(\frac{e^{\varphi_{c}([h_j^t,l_j,s])}}{\sum_j e^{\varphi_{c}([h_j^t,l_j,s])}}) \quad \hat{x}_{\varphi}^{t} = \varphi_m([h_i^t,l_i,s])} \label{eq:1}
    \\
    \hat{x}_i^{'t} &= \hat{x}_{\varphi}^{t} + (1 - \alpha_{l,i}^t)\hat{x}_i^{t-1} \label{eq:left}
    \\
    \hat{x}_i^{t} &= \hat{x}_{\varphi}^{t} + (1 - \alpha_{r,i}^t)\hat{x}_i^{'t} \label{eq:right}
\end{align}
\end{document}

enter image description here

This is how I would like the equations to be but without using two align environments due to the added space.

\begin{align}
    \alpha_{s,j}^t = g(\frac{e^{\varphi_{c}([h_j^t,l_j,s])}}{\sum_j e^{\varphi_{c}([h_j^t,l_j,s])}}) \quad \hat{x}_{\varphi}^{t} = \varphi_m([h_i^t,l_i,s]) \label{eq:1}
\end{align}
\begin{align}
    \hat{x}_i^{'t} &= \hat{x}_{\varphi}^{t} + (1 - \alpha_{l,i}^t)\hat{x}_i^{t-1} \label{eq:left}
    \\
    \hat{x}_i^{t} &= \hat{x}_{\varphi}^{t} + (1 - \alpha_{r,i}^t)\hat{x}_i^{'t} \label{eq:right}
\end{align}

enter image description here

2
  • you used \mathclap whose only function is to hide the size of the expression, so tex has no information about the first row size May 5 at 22:17
  • @DavidCarlisle thank you. How do I provide it information about the first row size? I would essentially like it to be like 2 align environments but without the added space like in my edit.
    – Kong
    May 5 at 22:23

2 Answers 2

1

enter image description here

you used \mathclap whose only function is to hide the size of the expression, so tex has no information about the first row size

I would use a normal equation for the first row

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{cleveref}
\begin{document}

\noindent X\dotfill X
\begin{equation}
    \alpha_{s,j}^t = g\biggl(\frac{e^{\varphi_{c}([h_j^t,l_j,s])}}{\sum_j e^{\varphi_{c}([h_j^t,l_j,s])}}\biggr) 
   \quad \hat{x}_{\varphi}^{t} = \varphi_m([h_i^t,l_i,s]) \label{eq:1}  
\end{equation}
\nopagebreak\vspace{-\baselineskip}
\begin{align}
    \hat{x}_i^{'t} &= \hat{x}_{\varphi}^{t} + (1 - \alpha_{l,i}^t)\hat{x}_i^{t-1} \label{eq:left}
    \\
    \hat{x}_i^{t} &= \hat{x}_{\varphi}^{t} + (1 - \alpha_{r,i}^t)\hat{x}_i^{'t} \label{eq:right} 
\end{align}
\noindent X\dotfill X
\end{document}
1

You could encase an align environment inside a gather environment.

I would also suggest you use \exp(...) notation instead of e^{...} notation in the first row; it doesn't require a lot of extra space, but it does improve the legibility.

Separately, might \hat{x}_i^{'t} better be written as \hat{x}_i^{\prime t}?

The framelines at the edges of the following screenshot are drawn because the sample code loads the showframe package. You may omit \usepackage{showframe} in your real document.

enter image description here

Remark: You may safely ignore the following sequence of error messages:

! Package amsmath Error: Multiple \label's: label 'eq:right' will be lost.

See the amsmath package documentation for explanation.

The user guide of the amsmath package states explicitly that it's ok to nest an align environment inside a gather environment. Creating cross-references to the second and third equation via, say \eqref will work just fine.


\documentclass{article}
\usepackage{amsmath}   % for 'gather' and 'align' environments
\usepackage{showframe} % draw framelines around textblock
\begin{document}

\begin{gather}
\alpha_{s,j}^t = 
   g\biggl(\frac{\exp\{\varphi_{c}([h_j^t,l_j,s])\}}{%
     \sum_j \exp\{\varphi_{c}([h_j^t,l_j,s])\}}
     \biggr) 
     \quad 
     \hat{x}_{\varphi}^{t} = \varphi_m([h_i^t,l_i,s]) 
     \label{eq:1} \\
\begin{align}
   \hat{x}_i^{\prime t} &= \hat{x}_{\varphi}^{t} 
     + (1 - \alpha_{l,i}^t)\hat{x}_i^{t-1}
     \label{eq:left} 
   \\[\jot]
   \hat{x}_i^{t} &= \hat{x}_{\varphi}^{t} 
     + (1 - \alpha_{r,i}^t)\hat{x}_i^{\prime t}
     \label{eq:right}
\end{align}
\end{gather}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .