# Equation problems

So I am trying to insert an equation. The output seems to be correct, but I get some error messages.

\centering \label{eg:homogeneity2} \begin{align} H(C) = - \sum\limits_{c=1}^{|C|} \left\frac{\sum\limits_{k=1}^{|K|} {a_c_k} }{n}\right log \left\frac{\sum\limits_{k=1}^{|K|} {a_c_k}}{n}\right \end{align}

-

• You can't write "double subscripts" like a_c_k. You have to choose either {a_c}_k or a_{c_k}. I went for the latter in my code below.

• Your \left...\right syntax needs to specify what kind of bracket you want. For instance, \left(...\right).

• You can't have align inside an equation, so I got rid of the align environment, since it wasn't doing anything. (Perhaps you intended aligned?)

• I took the liberty of changing \frac{big formula}{n} to \frac{1}{n} big formula, which I think is better style.

• \centering isn't doing anything here, so I got rid of it. Equations are centred by default.

## Fixed code

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\label{eg:homogeneity2} H(C) = - \sum\limits_{c=1}^{|C|} \left(\frac{1}{n}\sum\limits_{k=1}^{|K|} {a_{c_k}} \right) log \left(\frac{1}{n}\sum\limits_{k=1}^{|K|} {a_{c_k}}\right)$$
\end{document}


## Output

-
Wow, thanks so much! And to answer your question, I thought I had to have \align... I'm a latex-noob :) – Johan Sjons May 22 '13 at 14:35
Oh, one more thing I forgot in my answer: you should write \log rather than log. log is typeset as l multiplied by o multiplied by g. – John Wickerson May 22 '13 at 14:57
@JohanSjons -- align is not recommended for one-line equations. many people use it for convenience, but it's bad. some discussion appears in this question: Spacing between equation and text inconsistent due to large equations – barbara beeton May 22 '13 at 18:04
@JohnWickerson Thank you so much, noticed that in the original equation, but did not know the difference! I have another question (though feeling like an idiot). When trying almost the same thing, I get some error messages: $$\label{eg:homogeneity1} H(C|K) = - \sum\limits_{k=1}^{|K|} \sum\limits_{c=1}^{|C|} \left(\frac{a_{c_k}}{n}\right) \log \left(\frac{a_{c_k}}{\sum\limits_{c=1}^{|C|} {a_{c_k}}\right)}$$ – Johan Sjons May 23 '13 at 11:04
@barbarabeeton Thank you! – Johan Sjons May 23 '13 at 11:05