4

I'm trying to create a nice display of the KKT conditions, with sub-numbering for each condition. I have been able to do this using the \empheq package (MWE at the end of my question). However, these don't line up neatly.

Screenshot

In particular I would like to align the constraints on their inequalities and align the braces/description. So far, I can't achieve either of these goals without losing the numbering for each constraint. Any help is appreciated.

I am also open to solutions using numbered cases environments (such as \numcases) that put the braces/descriptions on the left, but so far these approaches also seem to have the same alignment problem. All things being equal, however, I prefer the visual effect of putting the descriptions on the right better.

MWE

\documentclass{article}

\usepackage{amssymb, amsthm, amsmath}
\usepackage{mathtools, empheq}

\begin{document}
\begin{empheq}[right={\empheqrbrace \textrm{Primal Feasibility}}]{align}
                g_1(\mathbf{x}) & \leq 0 \\
                g_2(\mathbf{x}) & \leq 0
            \end{empheq}
            \begin{empheq}[right={\empheqrbrace \textrm{Dual Feasibility} }]{align}
                \sum_{i = 1}^m \lambda_i \nabla g_i(\mathbf{x}) & = \nabla f(\mathbf{x}) \\
                \lambda_i & \geq 0 \quad \forall i
            \end{empheq}
            \begin{empheq}[right={\empheqrbrace \textrm{Complementary Slackness}}]{align}
                \lambda_1 g_1(\mathbf{x}) & = 0 \\
                \lambda_2 g_2(\mathbf{x}) & = 0.
            \end{empheq}
\end{document}

1 Answer 1

5

Hack above hack. ;-)

\documentclass{article}

\usepackage{amssymb, amsthm, amsmath}
\usepackage{mathtools, empheq,eqparbox}

\newcommand{\eqmath}[3][l]{\eqmakebox[#2][#1]{$\displaystyle\if#1l{}\fi#3$}}
\newcommand{\ftext}[2]{\makebox[#1][l]{\textup{#2}}}

\begin{document}
\begin{empheq}[
  right=\empheqrbrace \ftext{10em}{Primal Feasibility}
]{align}
  \eqmath[r]{A}{g_1(\mathbf{x})} & \eqmath[l]{B}{\leq 0} \\
  \eqmath[r]{A}{g_2(\mathbf{x})} & \eqmath[l]{B}{\leq 0}
\end{empheq}
\begin{empheq}[
  right=\empheqrbrace \ftext{10em}{Dual Feasibility}
]{align}
  \eqmath[r]{A}{\sum_{i=1}^m \lambda_i \nabla g_i(\mathbf{x})} & \eqmath[l]{B}{= \nabla f(\mathbf{x})} \\
  \eqmath[r]{A}{\lambda_i} & \eqmath[l]{B}{\geq 0 \quad \forall i}
\end{empheq}
\begin{empheq}[
  right=\empheqrbrace \ftext{10em}{Complementary Slackness}
]{align}
  \eqmath[r]{A}{\lambda_1 g_1(\mathbf{x})} & \eqmath[l]{B}{= 0} \\
  \eqmath[r]{A}{\lambda_2 g_2(\mathbf{x})} & \eqmath[l]{B}{= 0}.
\end{empheq}

\end{document}

enter image description here

A different kind of hack:

\documentclass{article}

\usepackage{amssymb, amsthm, amsmath}

\begin{document}
\begin{align}
\multispan{2}\hfill\textit{Primal Feasibility}\hfill\notag\\
g_1(\mathbf{x}) & \leq 0 \\
g_2(\mathbf{x}) & \leq 0 \\[2ex]
\multispan{2}\hfill\textit{Dual Feasibility}\hfill\notag\\[-0.5ex]
\sum_{i=1}^m \lambda_i \nabla g_i(\mathbf{x}) & = \nabla f(\mathbf{x}) \\[-1ex]
\lambda_i & \geq 0 \quad \forall i \\[2ex]
\multispan{2}\hfill\textit{Complementary Slackness}\hfill\notag \\
\lambda_1 g_1(\mathbf{x}) & = 0 \\
\lambda_2 g_2(\mathbf{x}) & = 0.
\end{align}

\end{document}

enter image description here

1
  • I figured the solution would be to force the box widths, but I didn't know how to make that happen. Thank you!
    – Tim
    Commented Dec 6, 2019 at 18:58

You must log in to answer this question.

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