7

I need to wrap some of the characters with whitespace so that the terms align correctly

$\begin{align*}
x = 1 + 2 + 3 + 4 + \cdots + n \\
x = n + (n-1) + (n-2) + (n-3)+\cdots+ 1\\
\cline{1-2}
2x = (1+n) + (1+n) + (1+n) + (1+n) + \cdots (1+n)
\end{align*}$
2
  • You need to remove the $ here. align* on itself starts math-mode. If you want to use align* (or align), you need to use & as an alignment point, in your case probably right before the = signs. Oct 13, 2013 at 4:32
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Oct 13, 2013 at 4:48

2 Answers 2

7

The following might be in line with what you're after:

enter image description here

\documentclass{article}
\usepackage{amsmath,array}% http://ctan.org/pkg/{amsmath,array}
\newcolumntype{C}{>{{}}c<{{}}}
\begin{document}
\begin{align*}
  x = 1 + 2 + 3 + 4 + \cdots + n \\
  x = n + (n-1) + (n-2) + (n-3)+\cdots+ 1\\
  \cline{1-2}
  2x = (1+n) + (1+n) + (1+n) + (1+n) + \cdots (1+n)
\end{align*}

\[
  \renewcommand{\arraystretch}{1.2}
  \begin{array}{r*{12}{@{}C}}
    x & = & 1 & + & 2 & + & 3 & + & 4 & + & \cdots & + & n \\
    x & = & n & + & (n-1) & + & (n-2) & + & (n-3) & + & \cdots & + & 1 \\
    \hline
    2x & = & (1 + n) & + & (1 + n) & + & (1 + n) & + & (1 + n) & + & \cdots & + & (1+n)
  \end{array}
\]
\end{document}

The entire structure is set in an array with a column type that provides the appropriate spacing around binary operators and relations (by inserting an empty group {} on the left/right of every cell, thanks to the array package's \newcolumntype). Some extra padding on the left and right (default of \arraycolsep or 5pt) can be changed, if needed.

2

Do you mean something like this?

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

\begin{align*}
x &= 1 &&+ 2 &&+ 3 &&+ 4 &&+ \cdots &&+ n \\
x &= n &&+ (n-1) &&+ (n-2) &&+ (n-3)&&+\cdots&&+ 1\\
\cline{1-12}
2x &= (1+n) &&+ (1+n) &&+ (1+n) &&+ (1+n) &&+ \cdots &&+(1+n)
\end{align*}
\end{document}

enter image description here

1
  • I wanted to add whitespace so that, for example, 2 and (n-1) have the same width Oct 13, 2013 at 4:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .