0

I'm writing a description of how recursive functions are applied within lists using the align environment from amsmath in LaTeX. Here's the code:

\begin{align*}
  & \reduce (+, 0,                  & [1, 2, 3, 4]) \\
= & \reduce (+, 0 + 1,              & [2, 3, 4]) \\
= & \reduce (+, 0 + 1 + 2,          & [3, 4]) \\
= & \reduce (+, 0 + 1 + 2 + 3,      & [4]) \\
= & \reduce (+, 0 + 1 + 2 + 3 + 4,  & []) \\
= & 0 + 1 + 2 + 3 + 4\\
= & 10
\end{align*}

or my try out to enhance the readability. Inserted \quads there:

\begin{align*}
 & \reduce (+,\quad 0,                   & [1, 2, 3, 4]) \\
=& \reduce (+,\quad 0 + 1,               & [2, 3, 4]) \\
=& \reduce (+,\quad 0 + 1 + 2,           & [3, 4]) \\
=& \reduce (+,\quad 0 + 1 + 2 + 3,       & [4]) \\
=& \reduce (+,\quad 0 + 1 + 2 + 3 + 4,   & []) \\
=& 0 + 1 + 2 + 3 + 4\\
=& 10
\end{align*}

It just doesn't look nice. Here's a quick picture of the latter:

http://havu.viuhka.fi/kuvat/alignenv.png

It is almost both readable and aesthetical, but not quite.

How to make the gap smaller? And any other tips you may have are appreciated!

mike3996
  • 17,047
  • 9
  • 64
  • 80
  • How it should look like? – Alexey Malistov Oct 29 '10 at 10:33
  • Doesn't the large gap look a bit clumsy? Out of the three parametres as "columns", I want it to clearly show how it recursively "moves" the list items to the middle. In that sense left-aligning the middle column and right aligning the rightmost column looks okay, but it could be firmer. – mike3996 Oct 29 '10 at 11:45

1 Answers1

1

How about using a tabular environment instead of align, with which you can more easily control alignment of the columns? I personally liked the results of:

\begin{tabular}{ r l c }
 & reduce(+,\;\, 0,                   & [1, 2, 3, 4]) \\
=& reduce(+,\;\, 0 + 1,               & [2, 3, 4]) \\
=& reduce(+,\;\, 0 + 1 + 2,           & [3, 4]) \\
=& reduce(+,\;\, 0 + 1 + 2 + 3,       & [4]) \\
=& reduce(+,\;\, 0 + 1 + 2 + 3 + 4,   & []) \\
=& 0 + 1 + 2 + 3 + 4\\
=& 10
\end{tabular}

Causes the set on the right to form (visually speaking) an upside down triangle shape. I also replaced \quad with \;\, \quad seemed like too much, and \; not enough... space there.

I briefly considered doing the same to the sums in their own column, but decided that the sums 'growing to the right' was visually more effective.

Iain
  • 985
  • 2
  • 9
  • 20
  • I like your style. The gap seems hard to get rid of. Unless something that really removes the gap comes up, I'll check yours as the accepted answer. – mike3996 Oct 30 '10 at 07:56
  • Thanks! Yeah, I'm not sure about the gap. Perhaps playing with tabular's settings in more detail would get you what you want. You may want to look at: http://www.andy-roberts.net/misc/latex/latextutorial4.html, a very helpful page on working with LaTex's tabular environment. – Iain Oct 30 '10 at 16:01