\hfill 在数学模式中重新出现

\hfill 在数学模式中重新出现

这是此主题。我基本上遵循了 @egreg 提供的构造。当我a & b在行中使用 时,以下构造会引发错误\pushright。如果我省略b代码运行。有没有办法让我使用\pushright并在符号右侧放置符号&

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\pushright}[1]{\ifmeasuring@#1\else\omit$\displaystyle#1$\ignorespaces\fi}
\makeatother

\begin{document}
\begin{align}
    a  &   b  \pushright{\hfill\text{(foo)}}
\end{align}
\end{document}

最终我想要做的是像这样:

\begin{align}
    x_{t+1} = & x_t + f(x_t) - c_t  \pushright{\hfill\text{(eq of motion)}} \\
    x_0     = & \bar{x}       \pushright{\hfill\text{(initial condition)}}
\end{align}

并将短语eq of motioninitial condition右对齐到等式数字的左侧。谢谢!

答案1

像那样?

\begin{align}
    x_{t+1} = & x_t + f(x_t) - c_t  & \pushright{\hfill\text{(eq of motion)}} \\
    x_0     = & \bar{x}       & \pushright{\hfill\text{(initial condition)}}
\end{align}

enter image description here

答案2

我想知道您是否只是在寻找\tag

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
    x_{t+1} = & x_t + f(x_t) - c_t  \tag{eq of motion} \\
    x_0     = & \bar{x}       \tag{initial condition}
\end{align}
\end{document}

enter image description here

答案3

总有flalign:如果希望方程式居中,请\text用替换\llap

\documentclass{article}
\usepackage{amsmath}
\usepackage{showframe}

\begin{document}
\begin{flalign}
&& x_{t+1} &= x_t + f(x_t) - c_t  &\text{(eq of motion)} \\
&&    x_0  &= \bar{x}       &\text{(initial condition)}
\end{flalign}
\end{document}

demo

相关内容