3

How can I make two optimization problems appear side by side using optidef? I am trying to do so for the following:

\documentclass[paper=letter,DIV=10]{scrartcl}
\usepackage{optidef}
\begin{document}

\begin{maxi*}
  {x\in R^n}
  {c^\top x}
  {}
  {{(\mathrm{P})}}
  \addConstraint{Ax}{\leq b}{}
  \addConstraint{x}{\geq 0}{}
\end{maxi*}
\begin{maxi*}
  {x\in R^n,s\in R^m}
  {c^\top x}
  {}
  {{(\mathrm{P}')}}
  \addConstraint{Ax+{s}}{=b}{}
  \addConstraint{x}{\geq 0}{}
  \addConstraint{s}{\geq 0}{}
\end{maxi*}
\end{document}

and putting them in an array environment hasn't worked; neither has alignat. Thanks!

2
  • 1
    Please can you put the minimal complete code that we can compile it? Thank you. Have you define a macro for \R?
    – Sebastiano
    Commented Jun 8, 2021 at 22:21
  • 1
    Thanks, just changed it
    – rrrrr
    Commented Jun 8, 2021 at 22:24

2 Answers 2

4

You can use minipages.

\documentclass[paper=letter,DIV=10]{scrartcl}
\usepackage{optidef}
\usepackage{amssymb}

\usepackage{lipsum} % for mock text

\newcommand{\R}{\mathbb{R}}

\begin{document}

\lipsum[3][1-4]
\[
\setlength{\abovedisplayskip}{0pt}
\begin{minipage}[t]{0.4\textwidth}
\begin{maxi*}
  {x\in\R^n}
  {c^\top x}
  {}
  {(\mathrm{P})}
  \addConstraint{Ax}{\leq b}{}
  \addConstraint{x}{\geq 0}{}
\end{maxi*}
\end{minipage}
\begin{minipage}[t]{0.4\textwidth}
\begin{maxi*}
  {x\in\R^n,s\in\R^m}
  {c^\top x}
  {}
  {(\mathrm{P}')}
  \addConstraint{Ax+{s}}{=b}{}
  \addConstraint{x}{\geq 0}{}
  \addConstraint{s}{\geq 0}{}
\end{maxi*}
\end{minipage}
\]
\lipsum[4][1-4]
\begin{maxi*}
  {x\in\R^n}
  {c^\top x}
  {}
  {(\mathrm{P})}
  \addConstraint{Ax}{\leq b}{}
  \addConstraint{x}{\geq 0}{}
\end{maxi*}
\lipsum[4][1-4]

\end{document}

The setting of \abovedisplayskip is meant to avoid a spurious insertion of that glue at the top of the minipages.

enter image description here

1
  • thanks! is there an easy way to make this into a macro for more of an array-style syntax (using & to denote columns of the minipages) or is this a separate question?
    – rrrrr
    Commented Jun 8, 2021 at 22:36
0

Based on @egreg's answer, I made a quick macro:

%%% side-by-side optimization environment
\newenvironment{sidebyside}[2]%
{
  \[
  \setlength{\abovedisplayskip}{0pt}
  \begin{minipage}[t]{0.4\textwidth}
    \centering
    #1
  \end{minipage}
  \begin{minipage}[t]{0.4\textwidth}
    \centering
    #2
  \end{minipage}
  \]
}%
{\par}%

You must log in to answer this question.

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