2

The compiler says "Package amsmath Error: \begin{aligned} allowed only in math mode." which I don't understand because "aligned" is inside an "equation" which per se is math mode.

\documentclass{article}

\usepackage{amsmath}
\usepackage{adjustbox}
\usepackage[utf8]{inputenc}


\begin{document}

\begin{adjustbox}{max totalsize={.4\textwidth},center}
 \begin{equation*}
        \textnormal{ Min} \qquad
        \begin{aligned}
              &36x_{11}+32x_{12}+33x_{13}+19x_{14}+\\
              &10x_{21}+\; \: 8x_{22}+\; \:  7x_{23}+20x_{24}+\\
              &12x_{31}+17x_{32}+16x_{33}+29x_{34}+\\
              &23x_{41}+15x_{42}+16x_{43}+28x_{44}
            \end{aligned}
    \end{equation*}
\end{adjustbox}

\vskip 5mm

\begin{adjustbox}{max totalsize={.4\textwidth},center}
     \begin{equation*}
        \textnormal{ s.a.} \qquad
        \begin{aligned}
              &\sum_{i=1}^{4}x_{ij}=b_i  \qquad \forall 1=1,2,3,4\\
              &\sum_{i=1}^{4}x_{ij}=b_j  \qquad \forall j=1,2,3,4\\
              &x_{ij}\ge 0\\
              &b_1=3\quad b_2=2 \quad b_3=1 \quad b_4=1
            \end{aligned}
    \end{equation*}
\end{adjustbox}

\end{document}
4
  • 1
    Why do you want to enclose an equation environment in an adjustbox? This will lead to quite inconsistent font sizes.
    – leandriis
    Commented Feb 6, 2021 at 12:53
  • I need to scale it in order to get the equation to fit in a column. Commented Feb 6, 2021 at 13:02
  • Just out of curiosity, is it an optimisation problem?
    – Bernard
    Commented Feb 6, 2021 at 13:16
  • Yes it is an optimisation problem. I am preparing some lecture notes on the transportation problem. Commented Feb 6, 2021 at 14:03

2 Answers 2

2

Using the aligned environment, this code, based on theoptimisation dedicated package optidef, perfectly fits a single column:

\documentclass[twocolumn]{article}

\usepackage{amsmath}
\usepackage{optidef}
\usepackage{lipsum}

\begin{document}

\lipsum[11]

\begin{mini*}|s|
  {}{\begin{aligned}[t]
 &36x_{11}+32x_{12}+33x_{13}+19x_{14}+\\
 &10x_{21}+\; \: 8x_{22}+\; \: 7x_{23}+20x_{24}+\\
 &12x_{31}+17x_{32}+16x_{33}+29x_{34}+\\
 &23x_{41}+15x_{42}+16x_{43}+28x_{44}
           \end{aligned}}{}{}
 \addConstraint{\sum_{i=1}^{4}x_{ij}}{=b_i\quad \forall i=1,2,3,4}
\addConstraint{\sum_{i=1}^{4}x_{ij}}{=b_j\quad\forall j=1,2,3,4}
\addConstraint{x_{ij}}{\ge 0}{}
\addConstraint{b_1=3\quad b_2}{=2 \quad b_3 =1 \quad b_4=1}{}
\end{mini*}

\end{document}

enter image description here

2

Desired result you can obtain by use of the \medmath macro from the nccmath package:

\documentclass{article}
\usepackage{nccmath}
\usepackage{adjustbox}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

Without reducing equations size:
    \[
\text{Min} \quad
\begin{aligned}[t]
  & 36x_{11}+32x_{12}+33x_{13}+19x_{14}+    \\
  & 10x_{21}+\hphantom{3}8x_{22}+ \hphantom{3}7x_{23}+20x_{24}+ \\
  & 12x_{31}+17x_{32}+16x_{33}+29x_{34}+    \\
  & 23x_{41}+15x_{42}+16x_{43}+28x_{44}
\end{aligned}
    \]

With \verb+\adjustbox+:
    \[\begin{adjustbox}{max totalsize={.4\textwidth},center}$\displaystyle
\text{Min} \quad
\begin{aligned}[t]
  & 36x_{11}+32x_{12}+33x_{13}+19x_{14}+    \\
  & 10x_{21}+\hphantom{3}8x_{22}+ \hphantom{3}7x_{23}+20x_{24}+ \\
  & 12x_{31}+17x_{32}+16x_{33}+29x_{34}+    \\
  & 23x_{41}+15x_{42}+16x_{43}+28x_{44}
\end{aligned}$
\end{adjustbox}
    \]

With \verb+\medmath+ from the \verb+nccmath+:
    \[\medmath{
\text{Min} \quad
\begin{aligned}[t]
  & 36x_{11}+32x_{12}+33x_{13}+19x_{14}+    \\
  & 10x_{21}+\hphantom{3}8x_{22}+ \hphantom{3}7x_{23}+20x_{24}+ \\
  & 12x_{31}+17x_{32}+16x_{33}+29x_{34}+    \\
  & 23x_{41}+15x_{42}+16x_{43}+28x_{44}
\end{aligned}}
    \]
\end{document}

enter image description here

You must log in to answer this question.

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