2

I have the following in the align environment:

\begin{align}
\bm{i}_t&=\sigma(\bm{W}^i\bm{x}_t+\bm{U}^i\bm{h}_{t-1}+\bm{b}^i)&&\text{Puerta }\mathit{input}\nonumber\\
\bm{f}_t&=\sigma(\bm{W}^f\bm{x}_t+\bm{U}^f\bm{h}_{t-1}+\bm{b}^f)&&\text{Puerta }\mathit{forget}\nonumber\\
\bm{o}_t&=\sigma(\bm{W}^o\bm{x}_t+\bm{U}^o\bm{h}_{t-1}+\bm{b}^o)&&\text{Puerta }\mathit{output}\nonumber\\[8pt]
\bm{g}_t&=\tanh(\bm{W}^c\bm{x}_t+\bm{U}^c\bm{h}_{t-1})&&{}\nonumber\\
\bm{c}_t&=\bm{f}_t\odot\bm{c}_{t-1}+\bm{i}_t\odot\bm{g}_t&&\text{Celda de memoria}\nonumber\\
\bm{h}_t&=\bm{o}_t\odot\tanh\bm{c}_{t}&&\text{Celda de salida}
\end{align}

See what it looks like here.

enter image description here

The alignment is how I want it, however, I want the text on the right to start more to the left (closer to where the formulae end). How can I do that?

2 Answers 2

3

The simplest will use the alignat environment (actually I used alignedat to simplify a bit your code), which gives you full control on the spacing between alignment columns: I just added a quad at the second row, which has the longest formula in the first column:

\documentclass{article}
\usepackage{mathtools, bm}

\begin{document}

\begin{align}
\bm{i}_t&=\sigma(\bm{W}^i\bm{x}_t+\bm{U}^i\bm{h}_{t-1}+\bm{b}^i)&&\text{Puerta }\mathit{input}\nonumber\\
\bm{f}_t&=\sigma(\bm{W}^f\bm{x}_t+\bm{U}^f\bm{h}_{t-1}+\bm{b}^f)&&\text{Puerta }\mathit{forget}\nonumber\\
\bm{o}_t&=\sigma(\bm{W}^o\bm{x}_t+\bm{U}^o\bm{h}_{t-1}+\bm{b}^o)&&\text{Puerta }\mathit{output}\nonumber\\[8pt]
\bm{g}_t&=\tanh(\bm{W}^c\bm{x}_t+\bm{U}^c\bm{h}_{t-1})&&{}\nonumber\\
\bm{c}_t&=\bm{f}_t\odot\bm{c}_{t-1}+\bm{i}_t\odot\bm{g}_t&&\text{Celda de memoria}\nonumber\\
\bm{h}_t&=\bm{o}_t\odot\tanh\bm{c}_{t}&&\text{Celda de salida}
\end{align}

\begin{equation}
\begin{alignedat}[b]{2}
\bm{i}_t&=\sigma(\bm{W}^i\bm{x}_t+\bm{U}^i\bm{h}_{t-1}+\bm{b}^i)&&\text{Puerta }\emph{input} \\
\bm{f}_t&=\sigma(\bm{W}^f\bm{x}_t+\bm{U}^f\bm{h}_{t-1}+\bm{b}^f)&\quad &\text{Puerta }\emph{forget} \\
\bm{o}_t&=\sigma(\bm{W}^o\bm{x}_t+\bm{U}^o\bm{h}_{t-1}+\bm{b}^o)&&\text{Puerta }\emph{output} \\[8pt]
\bm{g}_t&=\tanh(\bm{W}^c\bm{x}_t+\bm{U}^c\bm{h}_{t-1})&&{} \\
\bm{c}_t&=\bm{f}_t\odot\bm{c}_{t-1}+\bm{i}_t\odot\bm{g}_t&&\text{Celda de memoria} \\
\bm{h}_t&=\bm{o}_t\odot\tanh\bm{c}_{t}&&\text{Celda de salida}
\end{alignedat}
\end{equation}

\end{document} 

enter image description here

4
  • 1
    It should be \text{Puerta \textit{input}}, there is no reason for \mathit.
    – egreg
    Commented Aug 9, 2020 at 9:54
  • @egreg: I didn't even notice this point! I'll fix it instantly. How comes there was no error message, since it is not in math mode?
    – Bernard
    Commented Aug 9, 2020 at 10:02
  • I didn't notice the edit, which is even worse than before: \text{Puerta \textit{input}} is much better: why spitting? And it's not \emph, in my opinion, but really \textit, because it's a foreign term.
    – egreg
    Commented Oct 16, 2020 at 9:38
  • @egreg: What's worse? I didn't want to nest the font change, and the spacing is the same. I always use \emph to highlight foreign terms, or latin terms, in case the surrounding text would be italic (Not necessary for greek terms, though…)
    – Bernard
    Commented Oct 16, 2020 at 10:21
2

It is not a good solution using negative math space \mkern-70mu but it works...my it is just a quick alternative.

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{test}
\author{b}
\date{June 2020}

\usepackage{bm}
\usepackage{amsmath}

\begin{document}


\begin{align}
\bm{i}_t&=\sigma(\bm{W}^i\bm{x}_t+\bm{U}^i\bm{h}_{t-1}+\bm{b}^i)&&\mkern-70mu\text{Puerta }\mathit{input}\nonumber\\
\bm{f}_t&=\sigma(\bm{W}^f\bm{x}_t+\bm{U}^f\bm{h}_{t-1}+\bm{b}^f)&&\mkern-70mu\text{Puerta }\mathit{forget}\nonumber\\
\bm{o}_t&=\sigma(\bm{W}^o\bm{x}_t+\bm{U}^o\bm{h}_{t-1}+\bm{b}^o)&&\mkern-70mu\text{Puerta }\mathit{output}\nonumber\\[8pt]
\bm{g}_t&=\tanh(\bm{W}^c\bm{x}_t+\bm{U}^c\bm{h}_{t-1})&&{}\nonumber\\
\bm{c}_t&=\bm{f}_t\odot\bm{c}_{t-1}+\bm{i}_t\odot\bm{g}_t&&\mkern-70mu\text{Celda de memoria}\nonumber\\
\bm{h}_t&=\bm{o}_t\odot\tanh\bm{c}_{t}&&\mkern-70mu\text{Celda de salida}
\end{align}

\end{document}

enter image description here

2
  • +1. \hspace also works, but it's a bit cumbersome to change the spacing for every line if you want to experiment with different spacings. (I use a text replacer tool but still)
    – Asier R.
    Commented Aug 9, 2020 at 9:13
  • @AsierR. :-) I not use \hspace that is specific in text mode.
    – Sebastiano
    Commented Aug 9, 2020 at 9:14

You must log in to answer this question.

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