15

Often when I use math inside a paragraph, the spacing becomes ajar. This particularly happens when I use exponents or "choose" notation (for combinations).

Minimal working example below. The issue can be much worse with other setups with different fonts and font sizes.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1][1-3] There are $|A|={N \choose k}^2$ different options. \lipsum[1][1-3]
\end{document}

How it looks:

Latex with math in paragraphs and different font sizes

5
  • 6
    TeX increases the spacing when the lines would otherwise overlap. You can change some parameters to control this, but how do you actually want to handle this situation? Jan 29 at 14:19
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Jan 29 at 14:22
  • 6
    unrelated but use \binom{N}{k} not {N \choose k} in latex Jan 29 at 14:44
  • 4
    One solution woulod be to increase the spacing on every line. See tex.stackexchange.com/questions/819/double-line-spacing Jan 29 at 23:00
  • @JohnKormylo with a highly underrated answer. Would get an upvote if it were an official answer :)
    – ABC
    Jan 30 at 0:31

5 Answers 5

17

I suggest you familiarize yourself with the smallmatrix environment that's provided by the amsmath package.

It is straightforward to create a dedicated macro -- called \smallchoose in the following example -- that builds on the smallmatrix environment to typeset an expression that's noticeably smaller, along the vertical axis, than either {N \choose k} or \binom{N}{k}. Indeed, the result of $\smallchoose{N}{k}^2$ is so small as to no longer affect the line spacing.

enter image description here

\documentclass{article}
\usepackage{lipsum}    % filler text
\usepackage{amsmath} % for 'smallmatrix' env.
\newcommand\smallchoose[2]{%
   \bigl(\!\begin{smallmatrix}#1\\#2\end{smallmatrix}\!\bigr){}}

\begin{document}

${N\choose k}^2$ $\binom{N}{k}^2$ $\smallchoose{N}{k}^2$

\bigskip
\lipsum[1][1-3] 
There are $|A|={N \choose k}^2$ different options. 
\lipsum[1][1-3]

\medskip
\lipsum[1][1-3] 
There are $|A|=\smallchoose{N}{k}^2$ different options. 
\lipsum[1][1-3]
\end{document}
13

Just for historical context, I note that my copy of The Printing of Mathematics, (O.U.P, 1954) has this paragraph about binomial coefficients:

enter image description here

If I render that into LaTeX, you can see that the layout is rather better than OUP managed in 1954.

\documentclass{article}
\usepackage{amsmath}
\usepackage[textwidth=324pt]{geometry}
\begin{document}
\textit{Binomial coefficients} are now usually written with the notation $\binom{n}{r}$, 
though this, as here, breaks the line awkwardly when it appears in the 
text, as it may well do in enumerating the number of members in a set.
If this symbol is printed with $5\frac12$-point letters as $\scriptstyle\binom{n}{r}$, it is less quickly read,
especially with a more elaborate form such as $\scriptstyle\binom{mn+p-1}{n}$. The older forms
${}^nC_r$, $C^n_r$, which still survive, also have this disability and wastefully add
the intrusive $C$.  It is sugested that the symbol $(n\mathbin{!}r)$, which has been
used, might be tried more frequently.
\end{document}

enter image description here

I quite like (n!r) but I am not sure it will ever catch on.

2
  • Agree. Another alternative is to write it as a 2-argument function nCr, which is perhaps deemed inelegant but at any rate clear. Jan 30 at 15:49
  • 4
    +1 for the LaTeX typesetting of that classic. Jan 31 at 0:47
11

You have got many nice LaTeX answers, and hopefully resolved your problem. Let me give you one possible (partly new, tuning in progress) way to handle this in ConTeXt. (It will not help you in this case, but another TeX.SE user asked me to add it here. Maybe we will see something similar in LaTeX in the near future? And maybe it will help somebody else?)

As others have pointed out, extra space is usually added between lines when needed, in the sense that the depth of the top line is too big and/or the height of the bottom line is too big. In your example the main problem is the superscript 2 that sits high (as you will see it is placed lower in ConTeXt, probably due to some other font parameter setup).

Now, the standard model, described above, takes the whole lines in consideration when deciding on adding some extra skip or not between lines. With so-called profiling we act locally, to see if there really is some clash going on. In your example, just above the superscript 2 there is nothing that has a depth, so in principle the lines could sit close together. Let us see it in action with one example:

without and with profiling, with helpers

The top paragraph is set without profiling. The lines are shown with help of \showmakeup[line]. In the second example, profiling is switched on with \setupalign[profile]. We also use a helper (enabled with \enabletrackers[profiling.lines.show]) to show where it was activated. As you see, all extra space above the line with the "problematic" superscript 2 is gone. In the line below it is not, since that would mean that the left parenthesis in the binomial would be too close to the capital I on the line below. Let us also see how it looks without the helpers:

without and with profiling, without helpers

This mechanism is of course adding some overhead to the compilation, but it has turned out to be negligible (One reason is that it only has to check lines where the extra skip is added, and that is usually not too many.) It is possible to configure the profiling (amount and granularity) with \setuplineprofile.

9

It does not really fit:

enter image description here

If the p on the line above had been slightly to the left it would overlap the 2. Tex makes a decision based on the whole line. You can allow overlaps in individual cases with \smash (2) or for all lines with \lineskiplimit (3) or adjust the layout so the problem does not occur (4) and (5)

\documentclass{article}
\usepackage{lipsum,amsmath}
\showoutput
\showboxdepth=4
\begin{document}

1. \lipsum[1][1-3] There are $|A|=\binom{N}{k}^2$ different options. \lipsum[1][1-3]

2. \lipsum[1][1-3] There are \smash{$|A|=\binom{N}{k}^2$} different options. \lipsum[1][1-3]

{\setlength{\lineskiplimit}{-5pt}
3. \lipsum[1][1-3] There are $|A|=\binom{N}{k}^2$ different options. \lipsum[1][1-3]

}

4. \lipsum[1][1-3] There are \[|A|=\binom{N}{k}^2\] different options. \lipsum[1][1-3]


5. \lipsum[1][1-3] There are $|A|=\binom{N}{k}{}^2$ different options. \lipsum[1][1-3]

\end{document}
1
  • 1
    Another possibility is to increase the \baselineskip, although this obviously affects far more of the document. Nonetheless, if this formulation occurs frequently throughout, it may be an appropriate adaptation. Jan 29 at 15:37
7

If you have many such objects in your document, I'd consider increasing the interline space.

For the particular case, however, it's the exponent that gets in the way, so I can suggest lowering it.

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}

\makeatletter
\NewDocumentCommand{\Tbinom}{mme{^}}{%
  \IfNoValueTF{#3}{\tbinom{#1}{#2}}{%
    \begingroup
    \sbox\z@{$\m@th\tbinom{#1}{#2}$}%
    \usebox{\z@}\raisebox{\dimexpr\ht\z@-\height}{$\m@th^{\mkern-1mu #3}$}%
    \endgroup
  }%
}
\makeatother

\begin{document}

\lipsum[1][1-3] There are $|A|=\Tbinom{N}{k}^{2}$ different options. \lipsum[1][1-3]

\end{document}

enter image description here

The same, but with \linespread{1.05} before \begin{document}

enter image description here

3
  • +1. Would you say that the advantage of \Tbinom{N}{k}^{2} over \binom{N}{k}{}^{2} lies in better placement of the exponent?
    – Mico
    Jan 29 at 17:44
  • @Mico Yes, that was my first attempt, but the exponent comes up too low.
    – egreg
    Jan 29 at 20:26
  • I appreciate this suggestion!
    – ABC
    Jan 30 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.