# \end{align*} not in math environment

As I'm fairly new to LaTeX, I was hoping someone could help me out. Using the apa6 document format, with amsmath imported, I tried to compile the following code:

\text{A} = B * \text{log}\frac{C}{D} \\ \text{where} \begin{align*} & C = \text{lorem} \\ & D = \text{ipsum} end{align*}


This throws the following errors:

Could anyone give me an indicator on how to solve this or why this happens?

• You cannot have align (a math environment) inside a math environment. – Johannes_B Oct 28 '17 at 7:52

You are probably looking for the aligned environment:

\documentclass{apa6}

\usepackage{amsmath}

\begin{document}

\mathrm{A} = B * \log\frac{C}{D}, \qquad \text{where}\quad \begin{aligned} C &= \text{lorem} \\ D &= \text{ipsum} \end{aligned}

\begin{gather*}
\mathrm{A} = B * \log\frac{C}{D}, \\
\begin{aligned}[t]
C &= \text{lorem} \\
D &= \text{ipsum}
\end{aligned}
\end{gather*}

\end{document}


align* is a top level math environment to be used instead of $...$.

Note that $...$ does not accept the line break command \\ (at least it has no effect), so if you want to the conditions on a separate line use either gather* (as in my second example) or align*.

• use \log for the log operator
• use \mathrm{A} to get an upright A

Part of the reason is that \text will change font according to the surrounding text and you do not want that to happen in the maths.

I also strongly suspect you do not want to have the * multiplication symbol and should just B \log .... But that is a question of your style.

As you cannot use align* inside $....$ you probably want to use an array environment, so that your code will look something like this:

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

$A = B * \log\frac{C}{D}, \qquad \text{ where } \begin{array}{ll} C &= \text{lorem} \\ D &= \text{ipsum} \end{array}$

\end{document}


This produces:

Personally, I would omit the * and write A = B\log\frac{C}{D}. In particular, I have used:

• \log instead of \text{log}
• A instead of \text{A} (since A is part of the mathematics, not the text)
• \qquad to put some space between the equation and where

and that it is normally better to put the alignment character & before the equal signs rather than before the whole equation.

Another option would be to use a cases environment:

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

$A = B * \log\frac{C}{D}, \qquad \text{ where } \begin{cases} C = \text{lorem} \\ D = \text{ipsum} \end{cases}$

\end{document}


to give

As Bernard pointed out in the comments, it is better not to use alignment in the cases environment.

Finally, when asking questions it is better to give a full minimal working example. A MWE should start with a \documentclass command, have a minimal preamble and then \begin{document}...\end{document}. The code should compile and be as small as possible to demonstrate your problem. Adding a MWE clarifies your question and makes it much easier for people to help you.

• I wouldn't put any ampersand in the cases environment: why add a horizontal spacing? – Bernard Oct 28 '17 at 9:43
• @Bernard Good point. I agree. Will edit. – user30471 Oct 28 '17 at 10:24
• Thank you very much, learned a lot by your post(s?)! Next time I will provide a MWE :-) – MPieters Nov 15 '17 at 20:23