4

In the following excerpt of a write-up, I was wondering how to left-align \hat{L} and f on the second column of the first two lines. The best I could produce is below.

Thanks.

enter image description here

\documentclass{extbook}
\usepackage{amsmath}
\newcommand{\diff}{\mathop{}\!\mathrm{d}}
\begin{document}
    \begin{equation*}
        \begin{aligned}
            &\text{maximize}   && \hat{L}(f) \\
            &\text{subject~to} & f &\in H_0^1[a,b], \\
            && \int_a^b f(x) \diff x &= 1, \\
            && f(x) &\geq 0  \text{ for all } x \in [a,b].
        \end{aligned}
    \end{equation*}
\end{document}
AEW
  • 819

3 Answers3

4

Is a two-column layout ok? (What would be point of aligning the \in symbol on line 2, the = symbol on line 3, and the \geq symbol on line 4 with each other?)

Remove the \textstyle and \smash directives in line 3 if you want a large integral symbol.

enter image description here

\documentclass{extbook}
\usepackage{amsmath}
\newcommand{\diff}{\mathop{}\!\mathrm{d}}
\begin{document}

\begin{alignat}{2} &\text{maximize} && \hat{L}(f) \[\jot] % insert some whitespace padding &\text{subject to\quad} && f \in H_0^1 [a,b], \ & && \textstyle\smash{\int_a^b} f(x)\diff x=1, \ & && f(x)\ge0 \text{ for all $x\in[a,b]$}. \end{alignat}

\end{document}

Mico
  • 506,678
4

Just playing around with the placement of \hat{L}(f):

\documentclass{article}

\usepackage{mathtools}

\newcommand{\diff}{\mathop{}!\mathrm{d}}

\begin{document}

Original: [ \begin{aligned} &\text{maximize} & & \hat{L}(f) \ &\text{subject~to} & f &\in H_0^1[a,b], \ & & \int_a^b f(x) \diff x &= 1, \ & & f(x) &\geq 0 \text{ for all } x \in [a,b]. \end{aligned} ]

Updated: [ \begin{aligned} &\text{maximize} & \mathrlap{\hat{L}(f)}\phantom{f} \ &\text{subject~to} & f &\in H_0^1[a,b], \ & & \int_a^b f(x) \diff x &= 1, \ & & f(x) &\geq 0 \text{ for all } x \in [a,b]. \end{aligned} ]

\end{document}

The placement of \hat{L}(f) is to the left of an f in a zero-width math box that is left-aligned (has a right overlap) using \mathrlap. This requires mathtools which loads amsmath.

Werner
  • 603,163
2

Using optidef package.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{optidef}

\begin{document} \begin{maxi}<b> { }{ \hat{L}(f) }{}{} \addConstraint { f \in H_0^1 [a,b] }{ } \addConstraint {\int_a^b f(x),\mathrm{d}x }{=1} \addConstraint {f(x)}{\geq 0 \textup{ for all } x \in [a,b].} \end{maxi} \end{document}

Sebastiano
  • 54,118