Fit equation with \cases in page width using \resizebox

casesequationsresizetextwidth

I'm trying to fit an equation with several cases into my page width. The pain is that one case is awfully long. I used the \resizebox{} approach (see solution here), which would work, if there would be no \begin{cases}.

I learned that \resizebox creates a 'new' box and within this box there is no math environment, which is the reason why the solution math content starts with an $, to trigger the inline math mode. My problem is that \begin{cases} is not suitable for the inline math mode, and I receive a 'Missing $ inserted.' error.

Do you have an alternative approach to solve this issue. Adding another \begin{equation} within the box does not work. The work compiles but I would love to see a smoother solution than latex putting $ by itself. – Thanks!

Code looks like this:

\begin{equation}
\resizebox{.9\hsize}{!}{
  r(b_{i,t}^C,p_{market,t})= \begin{cases}  
    -(b_{i,t}^C - p_{market,t})^2,      & \text{if} b_{i,t}^C > p_{market,t}\\
    -(b_{i,t}^C - p_{grid})^2,          & \text{if} b_{i,t}^C < p_{market,t} \\
    \frac{p_{market,t}}{100} + \theta,  & \text{if} b_{i,t}^C = p_{market,t} \\
    \frac{p_{market,t}}{100} + 2\theta, & \text{if} b_{i,t}^C = p_{market,t} \text{and} b_{i,t}^C < min(b_{i,t-j}^C,.., b_{i,t-1}^C) \quad|  b_{i,t-j}^C=p_{market,t-j} 
 \end{cases}
 }
\end{equation}

Best Answer

You can split the long condition into three lines.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
  r(b_{i,t}^C,p_{\mathrm{market},t})=
  \begin{cases}  
    -(b_{i,t}^C - p_{\mathrm{market},t})^2,
      & \text{if } b_{i,t}^C > p_{\mathrm{market},t} \\[2ex]
    -(b_{i,t}^C - p_{\mathrm{grid}})^2,
      & \text{if } b_{i,t}^C < p_{\mathrm{market},t} \\[2ex]
    \frac{p_{\mathrm{market},t}}{100} + \theta,
      & \text{if } b_{i,t}^C = p_{\mathrm{market},t} \\[2ex]
    \frac{p_{\mathrm{market},t}}{100} + 2\theta,
      & \begin{aligned}[t]
        &\text{if } b_{i,t}^C = p_{\mathrm{market},t} \text{ and} \\
        &b_{i,t}^C < \min(b_{i,t-j}^C,\dots, b_{i,t-1}^C) \\
        &\mid b_{i,t-j}^C=p_{\mathrm{market},t-j}
        \end{aligned}
  \end{cases}
\end{equation}

\end{document}

enter image description here

Note \mathrm{market}, \mathrm{grid}, \dots and \min.