Solve overfull \hbox in equation's case

Solve overfull \hbox in equation's case

I have just started LaTeX so this may be a silly question, but I am getting a warning "Overfull \hbox(---pt too wide) detected" and the compiled pdf shows this text "if the sum of edge densities in the patch (x', y') is greater than threshold" (line 3 in the code) in a single line and this line is going out of bounds. Ideally that line should've been printed in two lines. I have tried linebreak but that doesn't work here. How to correct this?

\begin{equation}
I^p(x',y') = \left\{\begin{array}{rl}
    1 & \text{if the sum of edge densities in the patch (x', y') is greater than threshold}\\
    0 & \text{otherwise}\\
    \end{array}\right.
\end{equation}

답변1

You can't break lines in \text, but you can use a \parbox; adjust the width to suit.

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum}% for mock text

\begin{document}

\lipsum*[3]
\begin{equation}
I^p(x',y') =
\begin{cases}
  1 & \parbox[t]{.5\textwidth}{\raggedright
        if the sum of edge densities in the patch
        $(x', y')$ is greater than threshold
      }\\[4ex]
  0 & \text{otherwise}
\end{cases}
\end{equation}
\lipsum[4]

\end{document}

enter image description here

답변2

With mathtools and stackengine, you have a very simple code. The cases* takes care of the left brace and the second column of the environment automatically leaves math mode:

\documentclass{article}

\usepackage{mathtools, stackengine}

\begin{document}

\begin{equation}\def\stackalignment{l}
I^p(x',y') =\begin{cases*}
    1 & \stackunder{if the sum of edge densities in the patch}{$(x', y')$ is greater than threshold} \\
    0 & otherwise\\
    \end{cases*}
\end{equation}

\end{document} 

enter image description here

관련 정보