14

I used the code below, but the equation does not fit the page as it is too long. I tried to reduce the font size but I could not. What could be done to fit the equation to the line?

I am also wondering why the equation does not start from the beginning of line. As you can see from the pic below, there is huge space in the left side of the equation

\documentclass{report}
\usepackage{amsmath}

\begin{document}

\begin{align}
 {{f}_{r:n}}(x)=\frac{n!}{(r-1)!(n-r+1)!}\,\left[ {{\left( \frac{x-1}{k}\right)}^{r-1}}\ {{\left( \frac{k-x+1}{k} \right)}^{n-r+1}}-{{\left( \frac{x}{k} \right)}^{r-1}}\ {{\left( \frac{k-x}{k} \right)}^{n-r+1}} \right]+{{f}_{r-1:n}}(x)                    
\end{align}

\end{document}

Here is the output

enter image description here

Stefan Pinnow
  • 29,535
Günal
  • 3,393
  • 8
  • 31
  • 31

3 Answers3

24

I suggest you embed a split environment (provided by the amsmath package) inside an equation environment.

Aside: Don't overuse { and } in math mode, and don't overuse auto-sizing of round parentheses and square brackets. Do take the time to look at the equation and fine-tune some of the horizontal spacing; in the code below, you'll find two instances of \, (positive thinspace) and four instances of \! (negative thinspace).

enter image description here

\documentclass{article}
\usepackage{amsmath} % for "split" environment
\begin{document}

\begin{equation}\begin{split}
f_{r:n}(x)&=\frac{n!}{(r-1)!\,(n-r+1)!}
   \Biggl[ \biggl( \frac{x-1}{k}  \biggr)^{\!r-1} 
           \biggl( \frac{k-x+1}{k}\biggr)^{\!n-r+1} \\
  &\qquad -\biggl( \frac{x}{k}    \biggr)^{\!r-1} 
           \biggl( \frac{k-x}{k}  \biggr)^{\!n-r+1} \,
   \Biggr]+ f_{r-1:n}(x)                    
\end{split}\end{equation}

\end{document} 
Mico
  • 506,678
  • 1
    You could even improve your answer by using \binom{n}{r-1} for the first term. (Unfortunately I cannot upvote twice though). – Henri Menke Aug 01 '16 at 09:46
  • @HenriMenke - Thanks! I did consider writing \binom{n}{r-1} instead of \frac{n!}{(r-1)!\,(n-r+1)!}, but didn't pursue it as I don't have information on the author's intentions for how he/she will discuss or highlight various parts of the formula. – Mico Aug 01 '16 at 20:11
13

Or use multline:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{multline}
  f_{r:n}(x)=\frac{n!}{(r-1)!\,(n-r+1)!}
    \Biggl[ \biggl( \frac{x-1}{k}   \biggr)^{\!r-1}
            \biggl( \frac{k-x+1}{k} \biggr)^{\!n-r+1} \\
          - \biggl( \frac{x}{k}     \biggr)^{\!r-1}
            \biggl( \frac{k-x}{k}   \biggr)^{\!n-r+1} \,
    \Biggr] + f_{r-1:n}(x)
\end{multline}

\end{document}

enter image description here

Henri Menke
  • 109,596
JPi
  • 13,595
7

Answer reversed to show the 'logical' solution first, and the 'literal' answer second

If you have an equation which takes the length of a page, making it smaller / narrower / splitting onto several lines etc, is unlikely to aid the reader that much, as it is likely to be very dense and hard to read in the first place. If you have an equation like that, it probably means you're doing something wrong, and it would be worth considering if your equation can be restated in a more digestible way, as logical steps.

I think your equation could easily be restated, e.g. as:

enter image description here

      enter image description here

f_{r:n}(x) = \binom {n} {r \! - \! 1} 
             \biggl [ \Phi(x \! - \! 1) - \Phi(x) \biggr ] 
             + f_{r-1:n}(x)

\Phi(x) = \biggl ( \frac {x}   {k} \biggr ) ^ {r-1} 
          \biggl ( \frac {k-x} {k} \biggr ) ^ {n - r + 1}

which both saves you space and makes it clearer what's going on.

However, to answer your question literally, if you really don't want to split in this way, and you're just asking if it is at all possible with some sort of 'hack' to fit it all into one page / line, then you can save some space by making use of the 'choose r from n' notation, maybe substitute r-1 and x-1 with something else, and generally play with mkern to remove unnecessary extra space you don't want, particularly space resulting from the superscripts, e.g.:

f_{r:n}(x) = {n \choose r'}!! \left [! \left ( \frac {x'}{k} \right )^{!!r'}!!!! \left ( \frac{k - x'}{k}  \right )^{!!n-r'}!!!!!!!!! - \left ( \frac{x}{k} \right )^{!!r'}!!!! \left ( \frac{k-x}{k} \right )^{!!n-r'}!  \right ]!! +! f_{r':n}(x)

\text{where:}~~r' = r - 1, ~~~x' = x - 1

f_{r:n}(x) = \binom{n}{r'} 
  \mkern -4mu  \left [
  \mkern -4mu    \left ( \frac {x'}     {k} \right ) ^ { \!\! r'   }
  \mkern -12mu   \left ( \frac {k - x'} {k} \right ) ^ { \!\! n-r' }
  \mkern -24mu - \left ( \frac {x}      {k} \right ) ^ { \!\! r'   }
  \mkern -12mu   \left ( \frac {k-x}    {k} \right ) ^ { \!\! n-r' }
  \right ] \! + \! f_{r':n}(x)

\text{where:}~~r' = r - 1, ~~~x' = x - 1

However, as you might gather from the controversy this latter approach has managed to gather in the comments below, this just packs everything on one line, is probably not the best idea anyway, and some people feel quite strongly about it.

  • This “answer” is completely useless. The abundance of \! make the source hardly legible. Also {n \choose r'} is deprecated. Use \binom{n}{r'} from amsmath instead. – Henri Menke Aug 01 '16 at 09:44
  • I can replace \binom. Would you also prefer more leggible \kern instructions in place of \! or was the intent just to be rude and I shouldn't bother? This approach is reasonable, and makes it easier for the reader, so I disagree it's "useless". Legible code is secondary when the actual text produced is illegible. – Tasos Papastylianou Aug 01 '16 at 09:48
  • I mean by this that you should abandon the approach of negative kerning altogether. It does not make it any more legible in the output either. Also, automatically sized delimiters with \left and \right should only be used when all the manually sized ones (\bigl to \Biggl) are not applicable. Please read at least the chapter »Fine Points of Mathematics Typing« from the TeXbook. – Henri Menke Aug 01 '16 at 09:56
  • Fair enough. I would argue that kerning here is appropriate though, because the extra whitespace after all the parentheses is a side-effect of the long superscripts, and in fact it looks ugly without kerning in this case. – Tasos Papastylianou Aug 01 '16 at 09:59
  • 1
    I would use \mkern instead of \kern while in math mode. And there should be a positive thinspace, not a negative thinspace, before \right]. – Mico Aug 01 '16 at 10:13
  • @HenriMenke The chapter you just cited (specifically the bottom of p.169) actually seems to be in support of manual kerning rather than against it. "Where too much white space appears, because of certain unlucky combinations of shapes [...] a tastefully applied ‘!’ will close things together so that the reader won’t be distracted from the mathematical significance of the formula." – Tasos Papastylianou Aug 01 '16 at 10:15
  • @Mico thanks, good point. I'll edit my answer. – Tasos Papastylianou Aug 01 '16 at 10:16
  • 1
    You may be overusing \!. For the sake of legibility, I believe it's better to break the long equation across two lines. With your setup, one has to look up what r' and x' mean, which interrupts the reader's attention. – Mico Aug 01 '16 at 10:21
  • I don't disagree, but I feel this is a matter of preference. When I read maths, I prefer a logical progression of formulas over a long, convoluted formula split over two lines. I think if your formula is so long that it doesn't even fit the page, then one should consider restating it more clearly. But I agree it's important the steps aren't arbitrary. Here I think it makes sense to define r' as the "previous" element, and "F(x)" as the additive factor over the iteration. If anything, I feel it makes the logic of the equation clearer here to do so, rather than simply split over two lines. – Tasos Papastylianou Aug 01 '16 at 10:33
  • 1
    the ^{\!...} is often useful after a \right) or \Bigr), as the superscript can seem a long way from what it applies to without that. Some of the other adjustments look too forced to me, hitting the readability. – Chris H Aug 01 '16 at 13:53
  • Yes, I agree; I'm just providing a literal answer to the question. My preferred solution would be to break down into logical subexpressions, as I mention in the second part of the answer. Perhaps I should edit and reverse the order to make that clearer. – Tasos Papastylianou Aug 01 '16 at 14:01
  • i've upvoted your revised answer. Just for completeness, you should show the code -- in the form of an MWE -- for the first solution (your preferred solution) as well as for the second solution (the one that's closer to the OP's way of writing the formula). By the way, the screenshot you posted for the second (original) solution, the "primes" look to be the same size regardless of whether they're in script mode or scriptscript mode. This somehow looks very "non-TeX" to me. Are you using an unusual font? – Mico Aug 02 '16 at 00:31
  • Thanks. Edited. You're right; I don't use a different font, but I type my formulas in Anki and drag-and-drop directly from the output, which makes it very quick, and for some reason Anki doesn't respect my preferred fontsize, so I added a 'scriptsize' command in the note type's preamble, to make sure the output appears roughly the same size as the card's normal text. I'd forgotten I'd done that :) – Tasos Papastylianou Aug 02 '16 at 09:34
  • @Mico if you know any other fast way to generate a nice latex equation image without going through the hassle of compiling a latex document and image-processing the output, please share the love, heheh :) – Tasos Papastylianou Aug 02 '16 at 09:36