问题:
尝试对齐多行和多列,其中每行的值数量不同。
最小工作示例(MWE):
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{flalign*}
\text{err:} & \qquad\text{...} && \text{\# Too far away}\\
& \qquad\text{beq t0, t1, err} && \text{\# Jump to err if t0 equal to t1}\\
\text{\# To manage a long jump...} && \\
\end{flalign*}
\end{document}
期望的结果:
err: ... # Too far away
beq t0, t1, er # Jump to err if t0 equal to t1
# To manage a long jump...
答案1
AMS 对齐在这里根本没有帮助,几乎所有添加的标记都是为了明确撤消 amsmath 设置。对齐是数学,但你想要文本,所以\text
它们交替右对齐和左对齐列,但你只想要左对齐,所以需要&&
跳过每隔一列,最后一行包含一个较长的未对齐条目,所以我过去常常\rlap
隐藏它的宽度。然而:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}
&\text{err:} && \qquad\text{...} && \text{\# Too far away}\\
& && \qquad\text{beq t0, t1, err}\qquad && \text{\# Jump to err if t0 equal to t1}\\
&\rlap{\# To manage a long jump...}
\end{alignat*}
\end{document}
或者...
\documentclass{article}
\begin{document}
\begin{verbatim}
err: ... # Too far away
beq t0, t1, er # Jump to err if t0 equal to t1
# To manage a long jump...
\end{verbatim}
\end{document}