3

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}

2 Answers 2

3

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.

1
  • Thank you, works fine. Didn't think about the \begin{aligned}. Also, thanks for the small improvements.
    – Sulfat
    Commented Mar 27, 2022 at 17:26
3

The following solution shortens some of the expressions by putting p^*=p_{market}. This, in turns, allows displaying the conditions for the final case in just two rows.

enter image description here

\documentclass{article}
\usepackage{mathtools}         % for 'dcases' env.
\newcommand\vn[1]{\mathrm{#1}} % use mathrm display variable names
\begin{document}

\noindent
Put $p^*_t=p_{\vn{market},t}$. Then
\begin{equation}
r(b_{i,t}^C,p^*_t)= 
\begin{dcases}  
  -(b_{i,t}^C - p^*_t)^2         & \text{if $b_{i,t}^C > p^*_t$} \\
  -(b_{i,t}^C - p_{\vn{grid}})^2 & \text{if $b_{i,t}^C < p^*_t$} \\
  p^*_t/100 + \theta             & \text{if $b_{i,t}^C = p^*_t$} \\
  p^*_t/100 + 2\theta            & \text{if $b_{i,t}^C = p^*_t$ and} \\
       & b_{i,t}^C < \min(b_{i,t-j}^C,\dots, b_{i,t-1}^C) 
       \mid b_{i,t-j}^C=p^*_{t-j}
\end{dcases}
\end{equation}

\end{document}

You must log in to answer this question.

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