# 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?

$$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.$$

• you just post a fragment that makes it hard for people to test and hard to suggest changes, In particualar the fragment gives no indication on how wide your text is so if we make a test document it may or may not be overfull depending on what we guess for font size and page size {but you can use a \parbox instead of \text if you need line breaks. Feb 18, 2018 at 15:16
• Also, is there a reason to emulate cases with array? Feb 18, 2018 at 15:41

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]
$$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}$$
\lipsum[4]

\end{document}


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}

\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{document}