0

So this is what I have:

Code:

\documentclass[12pt]{beamer}
\usepackage{amsmath}
\usepackage{pgfpages}
\pgfpagesuselayout{resize to}[a4paper,landscape]
%\pgfpagesuselayout{2 on 1}[a4paper]
%\usetheme{Singapore}
\usetheme{Boadilla}
\usepackage{bm}
%\usefonttheme[?options?]{structuresmallcapsserif}
%\definecolor{beamer@blendedblue}{RGB}{203,140,55} % changed this
\definecolor{beamer@blendedblue}{RGB}{0,102,102} % changed this
%\definecolor{beamer@blendedblue}{RGB}{0,153,153} % changed this
\usefonttheme{professionalfonts} %To get the accents aligned correctly, albeit in Computer Modern Roman
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{blocks}[rounded][shadow=true]
\begin{document}
    %-----------------------------------------------------------------New slide ----------------------------------------------------%
    \begin{frame}{Sample}
        \setcounter{equation}{200}
        \begin{align}
            &\hspace{-0.6cm}\mathcal{H}\left(\mathbf{x}, \mathbf{u}, \bm{\lambda}, t\right) = \mathcal{L}\left(\mathbf{x}, \mathbf{u}, t\right) + \bm{\lambda}^{\textrm{T}}\left(t\right)\mathbf{f}\left(\mathbf{x},\mathbf{u}, t\right).\quad \text{(Hamiltonian)}&\\
            &\hspace{-0.6cm}
            \begin{aligned}[b]
                \dot{\mathbf{x}}^*\left(t\right) &= \frac{\partial}{\partial\bm{\lambda}}\mathcal{H}\left(\mathbf{x}^*, \mathbf{u}^*,\bm{\lambda}^*, t\right),\\ &= \mathbf{f}\left(\mathbf{x}^*, \mathbf{u}^*, t\right).
            \end{aligned}\quad 
            \text{(State equations)}&\\
            &\hspace{-0.6cm}
            \begin{aligned}[b]
                \dot{\bm{\lambda}}^*\left(t\right) &= -\frac{\partial}{\partial\mathbf{x}}\mathcal{H}\left(\mathbf{x}^*, \mathbf{u}^*,\bm{\lambda}^*, t\right)\\
                &= -\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right)^{\hspace{-0.1cm}\textrm{T}}\bm{\lambda}^* - \frac{\partial\mathcal{L}}{\partial\mathbf{x}}.
            \end{aligned}
            \quad \text{(Costate equations)}&
        \end{align}
    \end{frame}
\end{document}

Output:

enter image description here

As we can see from the output, the text descriptions like (State equations) and (Costate equations) are not right aligning. How to fix this?

On a side note, I have done \hspace{-0.6cm} for each line because of the equation label. Is there a way to write one line of code for all three lines of the equations?

2
  • you are using align but don't appear to be aligning anything, the= on the first line is not aligned with the one on the second and you are not specifying & alignment points for the text labels. Perhaps you would prefer gather which does no alignment? Jun 11, 2020 at 21:14
  • In this piece of code, I would like the text descriptions in parentheses to right align to each other before the equation labels show up. gather or not, as long as it works.
    – Superman
    Jun 11, 2020 at 21:15

2 Answers 2

2

Right-alignment of the text labels:

\documentclass[12pt]{beamer}
\usepackage{amsmath}
\usepackage{pgfpages}
\pgfpagesuselayout{resize to}[a4paper,landscape]
\usetheme{Boadilla}
\usepackage{bm}
\definecolor{beamer@blendedblue}{RGB}{0,102,102}
\usefonttheme{professionalfonts}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{blocks}[rounded][shadow=true]
\begin{document}
    \begin{frame}{Sample}
        \setcounter{equation}{200}
        \begin{alignat}{2}
            \mathcal{H}\left(\mathbf{x}, \mathbf{u}, \bm{\lambda}, t\right) & = \mathcal{L}\left(\mathbf{x}, \mathbf{u}, t\right) + \bm{\lambda}^{\textrm{T}}\left(t\right)\mathbf{f}\left(\mathbf{x},\mathbf{u}, t\right). \hspace{-8mm}
            & \text{(Hamiltonian)} \\
            \dot{\mathbf{x}}^*\left(t\right) 
                &= \frac{\partial}{\partial\bm{\lambda}}\mathcal{H}\left(\mathbf{x}^*, \mathbf{u}^*,\bm{\lambda}^*, t\right), \notag \\ 
                &= \mathbf{f}\left(\mathbf{x}^*, \mathbf{u}^*, t\right).
            & \text{(State equations)} \\
            \dot{\bm{\lambda}}^*\left(t\right) 
                &= -\frac{\partial}{\partial\mathbf{x}}\mathcal{H}\left(\mathbf{x}^*, \mathbf{u}^*,\bm{\lambda}^*, t\right) \notag \\
                &= -\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right)^{\hspace{-0.1cm}\textrm{T}}\bm{\lambda}^* - \frac{\partial\mathcal{L}}{\partial\mathbf{x}}.
            & \text{(Costate equations)}
        \end{alignat}
    \end{frame}
\end{document}

Left alignment of the text labels:

\documentclass[12pt]{beamer}
\usepackage{amsmath}
\usepackage{pgfpages}
\pgfpagesuselayout{resize to}[a4paper,landscape]
\usetheme{Boadilla}
\usepackage{bm}
\definecolor{beamer@blendedblue}{RGB}{0,102,102}
\usefonttheme{professionalfonts}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{blocks}[rounded][shadow=true]
\begin{document}
    \begin{frame}{Sample}
        \setcounter{equation}{200}
        \begin{alignat}{2}
            \hspace{-8mm}
            \mathcal{H}\left(\mathbf{x}, \mathbf{u}, \bm{\lambda}, t\right) & = \mathcal{L}\left(\mathbf{x}, \mathbf{u}, t\right) + \bm{\lambda}^{\textrm{T}}\left(t\right)\mathbf{f}\left(\mathbf{x},\mathbf{u}, t\right)\!. \ 
            && \text{(Hamiltonian)} \\
            \dot{\mathbf{x}}^*\left(t\right) 
                &= \frac{\partial}{\partial\bm{\lambda}}\mathcal{H}\left(\mathbf{x}^*, \mathbf{u}^*,\bm{\lambda}^*, t\right), \notag \\ 
                &= \mathbf{f}\left(\mathbf{x}^*, \mathbf{u}^*, t\right).
            && \text{(State equations)} \\
            \dot{\bm{\lambda}}^*\left(t\right) 
                &= -\frac{\partial}{\partial\mathbf{x}}\mathcal{H}\left(\mathbf{x}^*, \mathbf{u}^*,\bm{\lambda}^*, t\right) \notag \\
                &= -\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right)^{\hspace{-0.1cm}\textrm{T}}\bm{\lambda}^* - \frac{\partial\mathcal{L}}{\partial\mathbf{x}}.
            && \text{(Costate equations)}\! 
        \end{alignat}
    \end{frame}
\end{document}
6
  • That looks like a good solution for aligning the text! Thank you! How about right aligning the text?
    – Superman
    Jun 11, 2020 at 21:30
  • @Superman Oops, sorry I must have misread the question. I edited my answer!
    – Vincent
    Jun 11, 2020 at 21:37
  • Actually, can you keep your original answer? I may need that one later on just in case
    – Superman
    Jun 11, 2020 at 21:38
  • 1
    @Superman Done!
    – Vincent
    Jun 11, 2020 at 21:43
  • In your left align solution, does \! decrease the spacing by a little bit?
    – Superman
    Jun 11, 2020 at 21:55
1

perhaps

enter image description here

\documentclass[12pt]{beamer}
\usepackage{amsmath}
\usepackage{pgfpages}
\pgfpagesuselayout{resize to}[a4paper,landscape]
%\pgfpagesuselayout{2 on 1}[a4paper]
%\usetheme{Singapore}
\usetheme{Boadilla}
\usepackage{bm}
%\usefonttheme[?options?]{structuresmallcapsserif}
%\definecolor{beamer@blendedblue}{RGB}{203,140,55} % changed this
\definecolor{beamer@blendedblue}{RGB}{0,102,102} % changed this
%\definecolor{beamer@blendedblue}{RGB}{0,153,153} % changed this
\usefonttheme{professionalfonts} %To get the accents aligned correctly, albeit in Computer Modern Roman
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{blocks}[rounded][shadow=true]
\begin{document}
    %-----------------------------------------------------------------New slide ----------------------------------------------------%
    \begin{frame}{Sample}
        \setcounter{equation}{200}
\hspace*{-1cm}\begin{minipage}{\dimexpr\textwidth+1cm}
        \begin{alignat}{2}
  \mathcal{H}(\mathbf{x}, \mathbf{u}, \bm{\lambda}, t) 
&= \mathcal{L}(\mathbf{x}, \mathbf{u}, t) + \bm{\lambda}^{\textrm{T}}(t)\mathbf{f}(\mathbf{x},\mathbf{u}, t).
&\text{(Hamiltonian)}\\
                \dot{\mathbf{x}}^*(t)&
\begin{aligned}[t]
&= \frac{\partial}{\partial\bm{\lambda}}\mathcal{H}\left(\mathbf{x}^*, \mathbf{u}^*,\bm{\lambda}^*, t\right),\\ 
&= \mathbf{f}\left(\mathbf{x}^*, \mathbf{u}^*, t\right).
            \end{aligned}
&\text{(State equations)}\\
\dot{\bm{\lambda}}^*(t)&
            \begin{aligned}[t]
                &= -\frac{\partial}{\partial\mathbf{x}}\mathcal{H}\left(\mathbf{x}^*, \mathbf{u}^*,\bm{\lambda}^*, t\right)\\
                &= -\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right)^{\hspace{-0.1cm}\textrm{T}}\bm{\lambda}^* - \frac{\partial\mathcal{L}}{\partial\mathbf{x}}.
            \end{aligned}
&\text{(Costate equations)}
        \end{alignat}
\end{minipage}
    \end{frame}
\end{document}

You must log in to answer this question.

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