I'm trying to write something out some math in LaTeX with two aligned columns using the aligned
environment, which seems to have the best results so far. Using the following code, I have no issue, and it comes out pretty much exactly as I want it to:
\[
\begin{aligned}[c]
f(x) &= e^{-4x}\\
f'(x) &= -4e^{-4x}
\end{aligned}
\qquad
\begin{aligned}[c]
f(0) &= e^0 = 1\\
f'(0) &= -4e^0 = -4
\end{aligned}
\]
But I'll be doing this a lot in the document I'm working on, so I want to make this a command. The code I use for the command is
\newcommand{\mtable}[2]{
\[
\begin{aligned}[c]
{#1}
\end{aligned}
\qquad
\begin{aligned}[c]
{#2}
\end{aligned}
\]
}
but now when I try to use this command in the same way, like so
\mtable{
f(x) &= e^{-4x}\\
f'(x) &= -4e^{-4x}
}{
f(0) &= e^0 = 0\\
f'(0) &= -4e^0 = -4
}
I get two errors that say Missing { Inserted.
and two errors that say Missing } inserted.
all pointing to the last line in the previous block of code. As far as I can tell, there's no unmatched parentheses, and I've tried removing the parentheses around {#1}
and {#2}
from the command definition but nothing has quite worked, so I'm not sure what's wrong with this code.
Forgive me if this is a duplicate question, but for most other similar questions I've found, the answer has been that there was an incorrect \left
or \right
, and I don't think that applies in my case.
Edit: Playing around with it some more, I've found that the issue seems to be the newline command (\\
). When I remove it, I don't get the error, but obviously I also don't get new lines where I need them.