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*}$
  • 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. – Qrrbrbirlbel Oct 13 '13 at 4:32
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Sean Allred Oct 13 '13 at 4:48
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.

|improve this answer|||||
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

|improve this answer|||||
  • I wanted to add whitespace so that, for example, 2 and (n-1) have the same width – Tae Hyung Kim Oct 13 '13 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.