Optimization formulas in LaTeX
this is very easy to accomplish using the aligned
environment from amsmath
:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
\min_{w,b,\xi} \quad & \frac{1}{2}w^{t}w+C\sum_{i=1}^{N}{\xi_{i}}\\
\textrm{s.t.} \quad & y_{i}(w\phi(x_{i}+b))+\xi_{i}-1\\
&\xi\geq0 \\
\end{aligned}
\end{equation}
\end{document}
(in the future, please make your code a full compilable example, from \documentclass
through \end{document}
.)
An even easier approach would be to use the package optidef:
\documentclass{article}
\usepackage{optidef}
\begin{document}
\begin{mini*}|s|
{w,b,\xi}{\frac{1}{2}w^{t}w+C\sum_{i=1}^{N}{\xi_{i}}}
{}{}
\addConstraint{y_{i}(w\phi(x_{i}+b))+\xi_{i}-1}
\addConstraint{\xi\geq0}{}
\end{mini*}
\end{document}
and get the exactly same output:
The advantage of the package is that you can easily change the alignment of the constraints using four different formats, use a long format for the problem description, or add any referencing of your like. For example, the code:
\documentclass{article}
\usepackage{optidef}
\begin{document}
\begin{mini!}|l|[3]
{w,b,\xi}{\frac{1}{2}w^{t}w+C\sum_{i=1}^{N}{\xi_{i}}}
{}{}
\addConstraint{y_{i}(w\phi(x_{i}+b))+\xi_{i}-1}
\addConstraint{\xi\geq0}{}
\end{mini!}
\end{document}
would produce three changes:
1. A long format: given by using |l|
instead of |s|
.
2. Multiple referencing: given by using \begin{mini!}
instead of \begin{mini*}
.
3. Put the constraints below the "subject to": given by using [3]
instead of default.
In addition, the package also provides other features like line breaking line, various ways of referencing equations, or other environments for defining maximizition or arg mini problems.
A post explaining more about the package can be found here. The full documentation here and the repository with issue tracker here.
The align
environment from amsmath
also helps you achieve this with ease, like so:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
& \min_{w,b,\xi} & & \frac{1}{2}w^{t}w+C\sum_{i=1}^{N}{\xi_{i}} \nonumber \\
& \textrm{s.t.} & & y_{i}(w\phi(x_{i}+b))+\xi_{i}-1 \label{opt_prob:misc} \tag{42}\\
& & & \xi\geq0 \nonumber \\
\end{align}
\end{document}
The important thing to note is that in the align
environment, the alignment switches between left aligned and right aligned for consecutive columns. Therefore, I simply added an empty column to change the alignment of the expressions to left aligned.
Furthermore, while working in a jupyter notebook I found that align
lets me use labels with the equations, unlike the aligned
environment. This is the reason I prefer align
over the other.