2
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}

\begin{document}
$$\begin{array}{rcl} 
\sum_{k=1}^{n}cx_k &= cx_1 + cx_2 + cx_3 + \dots + cx_n \\
                       &= c(x_1+x_2+x_3+ \dots + x_n) \\
                       &= c\sum_{k=1}^{n}cx_k \\
                       &= cs_n \\
                       &\to cL
\end{array}$$
\end{document}

I am trying to align those equations to the equal sign, but it comes out horrible like this:

enter image description here

  • 1
    Use the advantages of the package amsmath which provides the environment align. You should also read the mathmode: https://www.ctan.org/pkg/voss-mathmode?lang=de – Marco Daniel Jan 28 '17 at 19:57

2 Answers2

4

You have defined a three column array but only used two columns so all your right hand sides were in the second column, so centred.

But you do not want array here (and never use $$ in latex) use an AMS alignment. Apart from aligning properly, it uses display math (see the \sum)

enter image description here

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\begin{document}
\begin{align*}
\sum_{k=1}^{n}cx_k &= cx_1 + cx_2 + cx_3 + \dots + cx_n \\
                       &= c(x_1+x_2+x_3+ \dots + x_n) \\
                       &= c\sum_{k=1}^{n}cx_k \\
                       &= cs_n \\
                       &\to cL
\end{align*}
\end{document}
David Carlisle
  • 757,742
  • Thank you so much! It looks much more neat now. But is there anyway I can slide the equations to the far left so $\sum_{k=1}^{n}cx_k$ is right next to the left margin? – user3000482 Jan 28 '17 at 20:13
  • @user3000482 yes that is called flush left equations just add [fleqn] to your document class options at the top of the file. – David Carlisle Jan 28 '17 at 20:16
  • But wouldn't that make all my equations to go to the left margin? I only want this bunch of equations to slide to the left side. Also, why shouldn't I use $$?? – user3000482 Jan 28 '17 at 20:36
  • please don't add followup questions in comments, the site mechanics don't really support that. on $$ see http://tex.stackexchange.com/questions/503/why-is-preferable-to/69854#69854 – David Carlisle Jan 28 '17 at 20:48
1

For the sake of variety, here's a solution that replaces the array environment in your solution with an IEEEeqnarray* environment (from the package IEEEtrantools).

Compared with the "look" that's generated with an align* environment, the main difference is that all symbols in the middle "column" -- here: = and \to -- are automatically centered horizontally with respect to each other. That's not the case in an align* environment.

enter image description here

\documentclass{article}
\usepackage{IEEEtrantools} % for 'IEEEeqnarray*' env.
\begin{document}

\begin{IEEEeqnarray*}{rCl}
\sum_{k=1}^{n}cx_k &=& cx_1 + cx_2 + cx_3 + \cdots + cx_n \\
                   &=& c(x_1+x_2+x_3+ \cdots + x_n) \\
                   &=& c\sum_{k=1}^{n}x_k \\
                   &=& cs_n \\
                   &\to& cL
\end{IEEEeqnarray*}

\end{document}
Mico
  • 506,678