# Aligning equations in math mode with different rules between lines

I was wondering how to align "minimize" and "subject" in the following example at their first letters, while keeping the alignment at the equal signs as is.

Thanks.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
\text{minimize} \quad J(y) &=\int_a^b \sqrt{1 + y^{\prime}(x)^2} \, \text{d}x \\
\text{subject to} \quad y(a) &= \alpha \\
y(b) & = \beta \\
y &\in C^1[a,b].
\end{aligned}
\end{equation}
\end{document} You can get what you want by putting in an extra alignment point: Code:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
&\text{minimize} & J(y) &=\int_a^b \sqrt{1 + y^{\prime}(x)^2} \, \text{d}x \\
&\text{subject to} & y(a) &= \alpha \\
&&y(b) & = \beta \\
&&y &\in C^1[a,b].
\end{aligned}
\end{equation}
\end{document}


There is a specific package called optidef that generates examples like your code.

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

\begin{document}

\begin{mini}<b>
{}{ J(y) =\int_a^b \sqrt{1 + y'^2(x)} \, \text{d}x }{}{} 