![使用 align* 或 flalign* 将两列和三列左对齐](https://linux22.com/image/440640/%E4%BD%BF%E7%94%A8%20align*%20%E6%88%96%20flalign*%20%E5%B0%86%E4%B8%A4%E5%88%97%E5%92%8C%E4%B8%89%E5%88%97%E5%B7%A6%E5%AF%B9%E9%BD%90.png)
问题:
尝试对齐多行和多列,其中每行的值数量不同。
最小工作示例(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}