\frac{1-z^{n+1}}{1-z} doesn't look very good and how to leave space equal to the size of a given text

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

• Is that exclamation point supposed to be there? – Antal Spector-Zabusky Oct 17 '10 at 19:46
• No. It is a vestigial error from a previous attempt that I forgot to delete. Anyways, it is not a good solution even without it. See the one by Philipp – Anna Taurogenireva Oct 17 '10 at 19:52

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

Try this:

\documentclass{minimal}
\begin{document}
$\frac{1-z^{n+1}}{1-z\hfill}$
\end{document}
• 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

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

• 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

\phantom is your friend for the second question.