在 alignat* 中右对齐特定列

在 alignat* 中右对齐特定列

简单来说,假设我想右对齐 alignat* 中的特定列。我该怎么做?

例子:

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{enumitem}

\newcounter{eqn_resetter}
\newcounter{eqn}[eqn_resetter]
\renewcommand*{\theeqn}{\arabic{eqn}.}
\newcommand{\num}{\refstepcounter{eqn}\text{\theeqn}\quad}

\newcommand{\prooflinen}[3][]{&\num #2 &&\qquad\text{#3}#1 \\}
\newcommand{\quadnum}[1][1]{\hspace*{#1em}\ignorespaces}
\newcommand{\algorithmline}[3]{\prooflinen{\quadnum[#1]\text{#2}}{$#3$}}

\begin{document}

        \begin{alignat*}{2}
            &\text{\textbf{Statement}} &&\qquad\text{\textbf{Number of times run}} \\
            \algorithmline{0}{power\_level = 10000}{1}
            \algorithmline{0}{k = -10}{1}
            \algorithmline{0}{for i = 1 to moves.length}{n + 1}
            \algorithmline{2}{uno = moves[i] + 8}{n}
            \algorithmline{2}{while k $<$ moves.length}{2n + 11}
            \algorithmline{4}{k += 1}{n + 11}
        \end{alignat*}

\end{document}

给予

LaTeX 图片

如何右对齐文本运行次数

答案1

alignat是错误的工具;您需要一个tabular

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{enumitem}

\newcounter{baytealgoline}
\newcommand{\numberalgoline}{\refstepcounter{baytealgoline}\thebaytealgoline.\quad}

\newcommand{\prooflinen}[3][]{\numberalgoline #2 &#3$#1$ \\}
\newcommand{\quadnum}[1][1]{\hspace*{#1em}\ignorespaces}
\newcommand{\algorithmline}[3]{\prooflinen{\quadnum[#1]\texttt{#2}}{$#3$}}

\newenvironment{baytealgo}[1][]
 {% don't reset the number if the optional argument is 'continue'
  \if\relax\detokenize{#1}\relax\setcounter{baytealgoline}{0}\fi
  \begin{tabular}{@{}l@{\qquad}r@{}}}
 {\end{tabular}}

\begin{document}

\begin{center}
\begin{baytealgo}
\textbf{Statement} & \textbf{Number of times run} \\
\algorithmline{0}{power\_level = 10000}{1}
\algorithmline{0}{k = -10}{1}
\algorithmline{0}{for i = 1 to moves.length}{n + 1}
\algorithmline{2}{uno = moves[i] + 8}{n}
\algorithmline{2}{while k $<$ moves.length}{2n + 11}
\algorithmline{4}{k += 1}{n + 11}
\end{baytealgo}
\end{center}

\end{document}

在此处输入图片描述

相关内容