我想让所有等号对齐。所以我尝试了论坛里的许多解决方案,但都没有效果。我仍然无法让它工作。这是我的代码:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\setlength{\parindent}{4em}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1.25}
\usepackage{braket}
\usepackage{mathtools}
\everymath{\displaystyle}
\begin{document}
[...]
Where $H\left(\frac{\omega_{0}}{2},\mu\right)$ is the Hamiltonian for isotropic $2-D$ oscillator with frequency $\frac{\omega_{0}}{2}\\
\begin{align}
\left[H\left(\frac{\omega_{0}}{2},\mu\right),L_{z}\right]&=\left[H\left(\frac{\omega_{0}}{2},\mu\right),xp_{y}-yp_{x}\right]\\
\qquad &=\frac{1}{2\mu}\left(\left[p_{x}^2,xp_{y}\right]+\left[p_{y}^2,-yp_{x}\right]\right)+\frac{\mu\omega_{0}^2}{8}\left(\left[x^2,-yp_{x}\right]+\left[y^2,xp_{y}\right]\right)\\
\qquad &=\frac{1}{2\mu}\left[2p_{x}p_{y}(-i\hbar)+2(i\hbar)p_{y}p_{x}\right]+\frac{\mu\omega_{0}^2}{8}\left[2yx(-i\hbar)+2xy(i\hbar)\right]\\
\qquad &=0\textrm{\qquad, }\left([p_{x},p_{y}]=[x,y]=0\right)$\\
\end{align}
[...]
\end{document}
我总是收到这个错误信息:
! Package amsmath Error: \begin{align} allowed only in paragraph mode.
See the amsmath package documentation for explanation.
Type H <return> for immediate help.
...
l.65 \begin{align}
你可以帮帮我吗?
答案1
我假设这all
意味着“除了最终向量之外的所有向量”。
代码被更改的行被标记为%here。
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\setlength{\parindent}{4em}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1.25}
\usepackage{braket}
\usepackage{mathtools}
\everymath{\displaystyle}
\begin{document}
[...]
Where $H\left(\frac{\omega_{0}}{2},\mu\right)$ is the Hamiltonian for isotropic $2-D$ oscillator with frequency $\frac{\omega_{0}}{2}$ %here
\begin{align}
\left[H\left(\frac{\omega_{0}}{2},\mu\right),L_{z}\right]&=\left[H\left(\frac{\omega_{0}}{2},\mu\right),xp_{y}-yp_{x}\right]\\
\qquad &=\frac{1}{2\mu}\left(\left[p_{x}^2,xp_{y}\right]+\left[p_{y}^2,-yp_{x}\right]\right)+\frac{\mu\omega_{0}^2}{8}\left(\left[x^2,-yp_{x}\right]+\left[y^2,xp_{y}\right]\right)\\
\qquad &=\frac{1}{2\mu}\left[2p_{x}p_{y}(-i\hbar)+2(i\hbar)p_{y}p_{x}\right]+\frac{\mu\omega_{0}^2}{8}\left[2yx(-i\hbar)+2xy(i\hbar)\right]\\
\qquad &=0\textrm{\qquad, }\left([p_{x},p_{y}]=[x,y]=0\right) %here
\end{align}
[...]
\end{document}
此外,请注意,\\
之前完全不需要类似方程的环境。
答案2
Przemysław Scherwentke 有已回答您的问题,但代码还有一些需要改进:
\documentclass{article}
\usepackage{amsmath}
\everymath{\displaystyle}
\setlength\parindent{4em}
\begin{document}
[\dots]
where $H{\mkern -5mu}\left(\frac{\omega_{0}}{2}, \mu\right){\mkern -5mu}$ is the Hamiltonian for isotropic $\mathrm{2D}$ oscillator with frequency $\frac{\omega_{0}}{2}$;
\begin{align}
\left[H{\mkern -5mu}\left(\frac{\omega_{0}}{2}, \mu\right){\mkern -5mu}, L_{z}\right]
&= \left[H{\mkern -5mu}\left(\frac{\omega_{0}}{2}, \mu\right){\mkern -5mu}, xp_{y} - yp_{x}\right]\\
&= \frac{1}{2\mu}{\mkern -3mu}\left(\left[p_{x}^{2}, xp_{y}\right] + \left[p_{y}^{2}, -yp_{x}\right]\right){\mkern -3mu} + \frac{\mu\omega_{0}^{2}}{8}{\mkern -3mu}\left(\left[x^{2}, -yp_{x}\right] + \left[y^{2}, xp_{y}\right]\right){\mkern -3mu}\\
&= \frac{1}{2\mu}[2p_{x}p_{y}(-i\hbar) + 2(i\hbar)p_{y}p_{x}] + \frac{\mu\omega_{0}^{2}}{8}[2yx(-i\hbar) + 2xy(i\hbar)]\\
&= 0,\qquad ([p_{x}, p_{y}] = [x, y] = 0)
\end{align}
[\dots]
\end{document}
更新
结合 Mico 的建议,得出以下结论:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mleftright}
\everymath{\displaystyle}
\setlength\parindent{4em}
\begin{document}
[\dots]
where $H\mleft(\frac{\omega_{0}}{2}, \mu\mright)$ is the Hamiltonian for isotropic $\mathrm{2D}$ oscillator with frequency $\frac{\omega_{0}}{2}$;
\begin{align}
\left[H\mleft(\frac{\omega_{0}}{2}, \mu\mright), L_{z}\right]
&= \mleft[H\mleft(\frac{\omega_{0}}{2}, \mu\mright), xp_{y} - yp_{x}\mright]\\
&= \frac{1}{2\mu}\mleft(\mleft[p_{x}^{2}, xp_{y}\mright] + \mleft[p_{y}^{2}, -yp_{x}\mright]\right) + \frac{\mu\omega_{0}^{2}}{8}\left(\mleft[x^{2}, -yp_{x}\mright] + \mleft[y^{2}, xp_{y}\mright]\mright)\\
&= \frac{1}{2\mu}[2p_{x}p_{y}(-i\hbar) + 2(i\hbar)p_{y}p_{x}] + \frac{\mu\omega_{0}^2}{8}[2yx(-i\hbar) + 2xy(i\hbar)]\\
&= 0,\qquad ([p_{x}, p_{y}] = [x, y] = 0)
\end{align}
[\dots]
\end{document}
在这里,mleftright
添加包是为了删除{\mkern -<x>mu}
构造。