\resizebox – Error: \begin{aligned} allowed only in math mode

errorsmath-moderesize

This code snippet produces the error "\begin{aligned} allowed only in math mode. Missing $ inserted."

\resizebox{\columnwidth}{!}{%
$$\begin{aligned}
\sin ^{2} \theta+\cos ^{2} \theta=1 & \quad
\sec ^{2} \theta-\tan ^{2} \theta=1 & \quad
\csc ^{2} \theta-\cot ^{2} \theta=1
\end{aligned}$$
%
}

Any ideas why?

Best Answer

You should never use $$ in LaTeX. Well, there are rare situations in which $$...$$ can be useful, but they're very special.

Why do you get the error?

When TeX is typesetting a horizontal box, which is part of the work of \resizebox, display math mode is not allowed and therefore $$ just denotes an empty math formula. Hence, in your case, aligned is found outside of math mode, which is illegal and the error message tells you exactly this.

You should use $...$ instead. Well, assuming you really want to do that.

Is aligned necessary?

Not at all: you need aligned to make multiline displays, but you have just one (very long) line. The only thing aligned does is to add additional space between the second and third formulas.

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{graphicx}

\usepackage{lipsum} % for context

\begin{document}

\lipsum[1][1-3]
\begin{center}
\resizebox{0.999\columnwidth}{!}{%
$\begin{aligned}
\sin ^{2} \theta+\cos ^{2} \theta=1 & \quad
\sec ^{2} \theta-\tan ^{2} \theta=1 & \quad
\csc ^{2} \theta-\cot ^{2} \theta=1
\end{aligned}$%
}
\end{center}
\lipsum[1][4-6]

\end{document}

Why 0.999\columnwidth? Because the various roundings lead to a width of 229.50241pt, whereas the column width is just 229.5pt, so you get two lines. Here's the output:

enter image description here

Can you see the difference in the spaces? If you remove \begin{aligned} and &, you get

enter image description here

Why? Because aligned adds space after even numbered columns.

Why not doing a full display?

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{graphicx}

\usepackage{lipsum} % for context

\begin{document}

\lipsum[1][1-3]
\begin{gather*}
\sin ^{2} \theta+\cos ^{2} \theta=1 \\
\sec ^{2} \theta-\tan ^{2} \theta=1 \qquad
\csc ^{2} \theta-\cot ^{2} \theta=1
\end{gather*}
\lipsum[1][4-6]

\end{document}

enter image description here

Related Question