1

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: Errors in Texmaker

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

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

You are probably looking for the aligned environment:

Sample output

\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}, \\
  \text{where}\quad
  \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*.

Additionally you should

  • 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.

2

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:

enter image description here

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

enter image description here

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.

  • 1
    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. – Andrew 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

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.