5

Here is an example of a parbox that produces both an underfull and an overfull warning:

\parbox{100pt}{A set of comparison triplets \(T = \{ (i,j,l) | z_i \;is\; more\; similar\; to\; z_j\; than\; z_l\}\) is given.}

When rendered to pdf, it looks like this:

rendered formula

Apparently, parts of the formula can't be broken up across multiple lines. I would like to allow Latex to linebreak the text within the curly braces and to position it like the other text in the parbox. Is that possible?

I have searched for similar questions:

\allowbreak works for me as well. I can define specific points at which the equation may be broken up. But how can I avoid sprinkling allowbreak everywhere in my math typesetting? The following code works (well it still produces an underfull warning, but that's my text content and has nothing to do with the inline formula) but is horrible to read and edit:

\parbox{100pt}{A set of comparison triplets \(T = \{ (i,j,l) | \allowbreak z_i \; \allowbreak is\;  \allowbreak more\;  \allowbreak similar\;  \allowbreak to\;  \allowbreak z_j\; \allowbreak than\; \allowbreak z_l\}\) is given.}
1
  • 2
    Beside the point, but you want \text{is more similar to} so that TeX knows you're dealing with text not math.
    – Teepeemm
    Commented Jul 29, 2020 at 21:21

3 Answers 3

11

The general recommendation I give is to avoid long textual set builder notation: readers will be very tired when looking at the text and they'll have a hard time in isolating the closing brace.

A set $T$ consisting of comparison triplets $(i,j,l)$ such that $z_i$ 
is more similar to $z_j$ than $z_l$ is given.

However, if you use the set builder notation, it is not a set, but the set:

The set $T$ consisting of all comparison triplets $(i,j,l)$ such that $z_i$ 
is more similar to $z_j$ than $z_l$ is given.

If you insist in using the set builder notation, go back and forth in and out of math mode:

The set of comparison triplets $T=\{(i,j,l)\mid z_i$ 
is more similar to $z_j$ than $z_l\}$ is given.

enter image description here

I used twocolumn in order to emulate your problem. Note \mid and not the simple | that has wrong spacing around it.

Alternative way: define a symbol.

\documentclass[twocolumn]{article}

\newcommand{\MST}{\mathrm{MST}}

\begin{document}

Define the ternary relation ``is more similar to than'' on the positive integers
by stipulating that $\MST(i,j,l)$ holds if and only if $z_i$ is more similar
to $z_j$ than $z_l$ and set
\[
T=\{(i,j,l)\mid \MST(i,j,l)\}
\]

\end{document}

enter image description here

6

You can just put text in textmode.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\begin{document}

\parbox{100pt}{A set of comparison triplets $T=\{(i,j,l) | z_i$ is more similar to $z_j$ than $z_l\}$ is given.}

\end{document}

enter image description here

4
  • 5
    It should be \mid rather than |.
    – egreg
    Commented Jul 29, 2020 at 13:52
  • Wouldn’t it be better to put the text in \text rather than going in and out of math mode? i.e. $T=\{(i,j,l) | z_i \text{ is more similar to } z_j \text{ than } z_l\}$
    – bradrn
    Commented Jul 30, 2020 at 4:20
  • (Actually, never mind — just realised that that would disallow a line break in the math formula, which isn’t what OP wanted.)
    – bradrn
    Commented Jul 30, 2020 at 4:26
  • @bradrn the line breaks issue aside, I'd say it's better to write that as \text{$z_i$ is more similar to $z_j$ than $z_l$}. Putting math mode inside text mode inside math mode might seem weird, but it gives the correct spacing.
    – N. Virgo
    Commented Jul 30, 2020 at 7:29
0

Personally I think the set builder notation is appropriate, but stylistically, I would say this (or really anything this long) should be a displayed equation, simply because it's much easier to read that way than as an inline equation.

enter image description here

\parbox{100pt}{
    A set of comparison triplets 
    \[
        T = \{ (i,j,l) \mid \text{$z_i$ is more similar to $z_j$  than $z_l$}\}
    \]
    is given.
}

(Note that I also changed it to use \text for the text part of the equation, which requires including the amsmath package. Additionally, using \mid instead of | puts the correct spacing around the vertical bar.)

That doesn't solve the overful/underfull hbox issue by itself, but by using the multline environment, also provided by amsmath, you can add line breaks yourself:

enter image description here

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\parbox{100pt}{
    A set of comparison triplets 
    \begin{multline*}
        T = \{ (i,j,l) \mid \text{$z_i$ is} \\
        \text{more similar to $z_j$} \\
        \text{than $z_l$}\}
    \end{multline*}
    is given.
}

\end{document}

Admittedly, this still looks a little bit silly, but I'm hoping the 100pt column is just for the sake of the example and you actually have at least a little bit more space than that.

You can use \\ to insert line breaks in the multline environment, but they have to be outside of any command, which is why I've had to put several separate \text commands.

You can remove the * from multline* to give it an equation number. (I recommend always numbering displayed equations.) Also note that, for some reason, it's "multline" with one 'i', and not "multiline" as you might expect.

You must log in to answer this question.

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