4

When we write it by hand we usually align the 1's in numerator and denominator. Should I change it manually, i.e. defining a command for typing the sum of the geometric progression or is there a package with a solution for this?

Right now I am solving it with

\newcommand{\geomsum}[2]{\frac{1-#1^{#2+1}}{1-#1\text{\textcolor{white}{${}^{#2+1}$!}}}}

A second question is how to leave space given by the size of some given text. There should be a cleaner way to do this instead of writing the text in white as I am doing above.

Caramdir
  • 89,023
  • 26
  • 255
  • 291

4 Answers4

6

Try this:

\documentclass{minimal}
\begin{document}
\[ \frac{1-z^{n+1}}{1-z\hfill} \]
\end{document}
Philipp
  • 17,641
  • neat solution is this! – Anna Taurogenireva Oct 17 '10 at 19:39
  • @Franklin But only for this particular problem, of course. Using \phantom is more general. – Philipp Oct 17 '10 at 19:54
  • Also, this solution relies on the implementation of \frac, which seems like a bad idea. – Harald Hanche-Olsen Oct 17 '10 at 19:57
  • It is more general for hiding a text, but my main interest is solving the problem with the fraction. Are there cases in which the \hfill doesn't behave well for. I mean, is there some problem if I change z and n by something else? – Anna Taurogenireva Oct 17 '10 at 20:01
  • @Harald: Could you expand? please. – Anna Taurogenireva Oct 17 '10 at 20:13
  • @Franklin: In general it is not considered a good idea to rely on undocumented aspects of the implementation of some feature, because it could break if that feature is implemented differently in the future. In this case, however, I think it's reasonably safe: I had never looked at the implementation of \frac before, but now that I have, I see it is a rather thin veneer over plain's \over. And that, in turn, is well documented in the TeXbook. (Though you have to hunt a bit in Appendix G to find the relevant bits.) – Harald Hanche-Olsen Oct 18 '10 at 20:59
5

In the general case, I agree with Hendrik Vogt: fractions look better centered. And yes, when I'm writing fractions, I typically write the top, draw a line, and then try to center the bottom. I usually screw this up, but that's what computers are for :-)

However, in this case, I can see why you might prefer to align things, even if I wouldn't do so myself. To do so, you should use \hphantom. There are three \phantom commands: \phantom, \hphantom, and \vphantom. They each create an empty box; the first command creates one the exact size of its argument, the second creates a solely horizontal box, and the third one creates a solely vertical box. You then want to overlap the actual text with the box. For this, you can use \rlap, which sets its contents in a zero-width box and overlaps it to the right. However, this gets math mode a little wrong; to get this really right, we can use the \crampedrlap command from the mathtools package. Putting this together gives

\newcommand{\geomsum}[2]{\frac{1-#1^{#2+1}}%
                              {1-\crampedrlap{#1}\hphantom{#1^{#2+1}}}}

I don't know of any package which does this for you, since as I said, it's more typical to leave things centered. The \cfrac command from amsmath is designed for typesetting continued fractions, but specifying \cfrac[l]{\text{short numerator}}{\text{very long denominator}} will left-align the numerator. It doesn't provide a way to deal with the denominator, and it's for continued fractions so something about its spacing (I'm not sure exactly what, but something) is different; however, it might provide a good starting point.

  • Very good answer. One question, why is it that you have to apply phantom to the whole thing and then have to overlap instead of phantom only the exponent? – Anna Taurogenireva Oct 17 '10 at 20:29
  • 1
    I did so for two reasons. First, I think that the superscript might add vertical space; you don't want this. It's the same reason I used \hphantom instead of \phantom; you only want to set the horizontal alignment, not vertical. Second, this way is more general: if you had something besides #1 in \crampedrlap, it would still work (as long as it was not as wide as #1^{#2+1}). – Antal Spector-Zabusky Oct 17 '10 at 20:42
4

Actually, we don't do it when we write it by hand, at least I don't, and I wouldn't recommend to change it manually. Even if I understand that you don't like the output, I like it less with aligned 1's. If you really want to do it, use 1-z^{\phantom{n+1}} in the denominator.

EDIT: Antal S-Z is quite right: \phantom does not always work properly in this example. Above it's OK, but for larger exponenents you need \hphantom, as e.g. in \frac{1-z^{n^2}}{1-z^{\hphantom{n^2}}}.

Hendrik Vogt
  • 37,935
  • I completely doubt it. Do you write from left to right or you implement centering text in your head? It is completely unnatural. Try it. The difference becomes more apparent as the text is larger. Try a bulky exponent and ratio instead of n and z. – Anna Taurogenireva Oct 17 '10 at 19:37
  • In handwriting, I would have the fraction line (is that the correct English word?) only under 1-z and the exponent mostly outside the fraction (so the effect is more like {\frac{1-z}{1-z}}^{n+1}, except that my fraction lines usually extend somewhat longer to the left and right). Otherwise I usually center fractions in handwriting. – Caramdir Oct 17 '10 at 19:53
  • I don't think that that is true. It is difficult to parse centering a large expression. Clearly one can write the numerator draw a line below it and center 1-z in the denominator. Think about what would happen if instead of z you had a mammoth expression as the ration of the geometric progression. – Anna Taurogenireva Oct 17 '10 at 20:05
  • There is still one more reason for wanting that alignment and it is the mnemonic device we use to remember the formula for the sum of a geometric progression. It is easy to remember because we only need to write the same thing 1 minus the ratio and an exponent above that is the number of terms. Visually this picture is broken if the two things are not aligned. The centering doesn't aid the understanding of the formula. Very true that, in general, one would like fractions to be centered but typesetting is content dependent. – Anna Taurogenireva Oct 17 '10 at 20:10
  • How would you write \frac{1}{1-z}, i.e. the infinite geometric series? – Caramdir Oct 17 '10 at 20:14
  • Oh my! Now I understand. I never put in the question that what I'm writing is many sums of geometric progressions. My bad. – Anna Taurogenireva Oct 17 '10 at 20:18
  • @Caramir: As I said, typesetting is content dependent. The goal is to convey meaning without distraction. \frac{1}{1-z} is just perfect. But the nature of what we are writing now is different from the formula for the geometric progression. – Anna Taurogenireva Oct 17 '10 at 20:20
  • @Franklin: Maybe I'm influenced by TeX in my handwriting. I did try it before answering, and it seems that indeed I have the text centering implemented in my brain. If you want it as a mnemonic device, which I find good, then I would still first write it centered and then emphasize that it is easier to memorize in this left aligned form. (And then later on I would use the centered form only. But this of course also depends on the audience you're going to address.) – Hendrik Vogt Oct 18 '10 at 11:31
1

\phantom is your friend for the second question.

Caramdir
  • 89,023
  • 26
  • 255
  • 291