3

enter image description here

How can I reproduce this format of an optimization problem? Ive been trying to use align but then I can produce the P only on the right side (using \tag). With alignat I couldn't produce the P at all.

This is what I tried:

\documentclass[•]{article}
\usepackage{amsmath}


\begin{document}
\begin{align*}
& \min\limits_{x \in X} && f(x) \tag{P} \\
& \text{subject to} && g(x) \leq \epsilon \nonumber
\end{align*}

\end{document}
Werner
  • 603,163

2 Answers2

4

You may want to switch between numbering equations on the left/right and use a gather to centre content - the alignment in your post seems non-uniform. To achieve some form of alignment around =, I've used boxes via \eqmakebox[<tag>][<align>]{<stuff>}. This sets <stuff> in a box of maximum width across the same <tag> using the appropriate <align>ment; left and right in my case.

enter image description here

\documentclass{article}

\usepackage[leqno]{amsmath}
\usepackage{eqparbox}

% https://tex.stackexchange.com/q/193535/5764
\makeatletter
\newcommand{\leqnomode}{\tagsleft@true}
\newcommand{\reqnomode}{\tagsleft@false}
\makeatother

\begin{document}

\reqnomode

\begin{align}
  f(x) &= ax^2 + bx + c \\
  g(x) &= dx^2 + ex + f
\end{align}

\leqnomode

\begin{gather}
  \eqmakebox[LHS][r]{$\min\ f(x)$}
    \eqmakebox[RHS][l]{$\displaystyle {}= \sum_{j = 1}^n f_j(x_j)$} \tag{P} \\
  \eqmakebox[LHS][r]{$\textup{s.t.}\ g_i(x)$}
    \eqmakebox[RHS][l]{$\displaystyle {}= \sum_{j = 1}^n g_{ij}(x_j) \leq b_i,\ i = 1,\dots,m,$} \nonumber \\
  x \in X = X_1 \times X_2 \times \dots \times X_n, \nonumber
\end{gather}

\reqnomode

\begin{align}
  f(x) &= ax^2 + bx + c \\
  g(x) &= dx^2 + ex + f
\end{align}

\end{document}
Werner
  • 603,163
3

Is this what you want?

enter image description here

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{equation}
\begin{aligned}
\min_{x \in X}  f(x) &= \sum_{j=1}^{n} f_j(x_j) \\
\text{s.t. } g_i(x)  &= \sum_{j=1}^{n} g_{ij}(x_j)\leq b_i,\ i=1,\dots,m, \\
x\in X               &= X_1\times X_2\times \dots \times X_n.
\end{aligned}
\tag{P}
\end{equation}
\end{document}
Sigur
  • 37,330