2

I want to write the optimization problem.

My code is:

\begin{alignat}{3}
    & \underset{\framebox(100,10){}}{\text{minimize}}   & \quad & \framebox(100,10){}\\
    & \text{subject to}                                 &       & \framebox(100,10){},\\
    &                                                   &       & \framebox(100,10){},\\
    &                                                   &       & \framebox(100,10){},\\
    &                                                   &       & \framebox(100,10){},\\
    &                                                   &       & \max_{i=1,\ldots,l+m+n} \framebox(100,10){},\\
    &                                                   &       & \min_{i \in \mathbb{R}} \framebox(100,10){}.
\end{alignat}

The result is: enter image description here

However, I want to make the problem like this: enter image description here

  1. minimize and subject to is aligned at center.
  2. constraints are aligned at left (except for subscript)
Danny_Kim
  • 615

2 Answers2

3

In mathtools you have a command \mathclap{<formula>} that can help you here. It centeres the <formula> but does not occupy any space. You can use that to center the subscript. To get a space between the \max and the following box you can insert \rule{15pt}{0pt}, but I like it better without. The text can be centered with \makebox in the same way as your \framebox.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\begin{document}
\begin{alignat}{3}
    & \underset{\framebox(100,10){}}{\text{minimize}}   & \quad & \framebox(100,10){}\\
    & \makebox(100,10){subject to}                      &       & \framebox(100,10){},\\
    &                                                   &       & \framebox(100,10){},\\
    &                                                   &       & \framebox(100,10){},\\
    &                                                   &       & \framebox(100,10){},\\
    &                                                   &       & {\max_{\mathclap{i=1,\ldots,l+m+n}}\framebox(100,10){}},\\
    &                                                   &       & {\min_{i \in \mathbb{R}} \framebox(100,10){}}.
\end{alignat}
\end{document}

enter image description here

StefanH
  • 13,823
  • 1
    You can replace \mathclap{\text{some text}} with the simpler \clap{some text}. – Bernard Jun 14 '17 at 12:36
  • @Bernard Yes, that should do. I can actually use \text for the first one and \makebox for the second (which also removes the slightly anoying \rule). I have updated. – StefanH Jun 14 '17 at 14:05
  • I know now the command "mathclap". By the way, can you start the frarmebox in $(6)$ at the end of $i=1,\ldots,l+m+n$? – Danny_Kim Jun 15 '17 at 08:14
  • 1
    @Danny_Kim yes, add \rule{15pt}{0pt} before the framebox. It is just a distnace of 15pt, which seems to be enough. – StefanH Jun 15 '17 at 11:33
0

With the help of code in https://tex.stackexchange.com/a/209732/4427

You can use \opt{maximize} in case this is the optimization problem.

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{xparse}

\makeatletter
\newcommand{\Cen}[2]{%
  \ifmeasuring@
    #2%
  \else
    \makebox[\ifcase\expandafter #1\maxcolumn@widths\fi]{$\displaystyle#2$}%
  \fi
}
\makeatother
\NewDocumentCommand{\opt}{me{_}}{%
  \Cen{1}{\operatorname*{#1}\IfValueT{#2}{_{#2}}}%
}
\NewDocumentCommand{\subjectto}{}{\Cen{1}{\textnormal{subject to}}}

\begin{document}

\begin{alignat}{2}
\opt{minimize}_{\framebox(100,10){}} && \quad & \framebox(100,10){}\\
\subjectto                           &&       & \framebox(100,10){},\\
                                     &&       & \framebox(100,10){},\\
                                     &&       & \framebox(100,10){},\\
                                     &&       & \framebox(100,10){},\\
                                     &&       & \max_{i=1,\ldots,l+m+n} \framebox(100,10){},\\
                                     &&       & \min_{i \in \mathbb{R}} \framebox(100,10){}.
\end{alignat}

\end{document}

enter image description here

egreg
  • 1,121,712