我正在寻找一种方法,将一些文本对齐到右边缘(就像这样\tag*{…}
做)放在方程式每行的末尾。该方程式有多列,我需要控制每列的对齐方式(右对齐、居中对齐或左对齐)。此外,我不希望环境在第一列之前、最后一列之后或列之间添加额外的空间。
我尝试了以下方法,但不起作用,因为\tag{…}
整个等式只允许一个。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{array}{@{}r@{}c@{}l@{}}
a&bbbbb&c \tag*{a, b and c} \\
x&y&z \tag*{other stuff}\\
\end{array}
\]
\end{document}
cases
如果我也可以对子句(大括号后的行)执行此操作,那就太酷了,就像numcases
这样做(但numcases
不支持\tag
,并且在各处添加额外的空格)。
我尝试过的事情(浏览了这里不少问题之后):
equationarray
从eqnarray
包看起来很有希望,但它不支持\tag{…}
命令,只有\notag
(我试过,但未能手动调用内部函数\tag{…}
)。在命令align
之间添加额外的空间align
并且empheq
不支持rcl
列规范和添加额外空间alignat*
除列规范外,所有内容rcl
(硬编码为rlrlrl…
)
现在我最好的选择是放一个标记并将标签绘制为覆盖层(我对精确/参考tikz
不是特别感兴趣,如果需要,我可以让所有标签指向整个多线方程,因此绘制是一个粗略但可行的解决方案)。\label
\ref
tikz
答案1
你可以滥用IEEEtrantools
(但我建议不要将属于等式的材料推到右边距,右边距应该保留用于参考标记或数字)。
请注意,您有责任避免重叠。
\documentclass{article}
\usepackage{amsmath}
\usepackage{IEEEtrantools}
\usepackage{showframe}
\begin{document}
\begin{IEEEeqnarray*}{r-c-l+r-}
a&bbbbb&c &\makebox[0pt][r]{a, b and c} \\
x&y&z &\makebox[0pt][r]{other stuff}
\end{IEEEeqnarray*}
\begin{equation}
abbbbbc
\end{equation}
\end{document}
原答案供参考
\documentclass{article}
\usepackage{amsmath}
\usepackage{IEEEtrantools}
\renewcommand\theIEEEsubequationdis{\theIEEEsubequation}
\newcommand{\IEEEtag}[1]{%
\IEEEyessubnumber
\gdef\theIEEEsubequation{#1}%
}
\begin{document}
\begin{IEEEeqnarray}{r-c-l}
a&bbbbb&c \IEEEtag{a, b and c} \\
x&y&z \IEEEtag{other stuff}
\end{IEEEeqnarray}
\begin{equation} % just for checking the number has not advanced
a
\end{equation}
\end{document}
答案2
给你,有alignat
和eqparbox
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][M]{\eqmakebox[#1]{$\displaystyle#2$}}
\begin{document}
\begin{alignat}{3}\label{rcl-eq}
aa & & \eqmathbox{bbbbb} & & & c \tag*{a, b and c} \\
x & &\eqmathbox{ y} & & & zzz \tag*{other stuff}
\end{alignat}
\end{document}
答案3
比rl
对并没有深深嵌入 amsmath 代码中,因此很容易使用alignat
(或任何 AMS 比对)不同的设置。这里我提供了一个命令,让你指定一个字符串,例如,clr
它将根据需要重复多次,就像标准rl
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\align@preamble@r{%
\hfil
\strut@
\setboxz@h{\@lign$\m@th\displaystyle{##}$}%
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip}
\def\align@preamble@l{%
\strut@
\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@}
\def\align@preamble@c{%
\hfil
\strut@
\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@
}
\def\setalignpreamble#1{\def\align@preamble{}\x@setalignpreamble#1\relax}
\def\x@setalignpreamble#1{%
\ifx\relax#1\else
\edef\align@preamble{%
\unexpanded\expandafter{\align@preamble}%
&\span\expandafter\noexpand\csname align@preamble@#1\endcsname}%
\expandafter\x@setalignpreamble
\fi}
\begin{document}
default (rl)
\begin{alignat}{2}
a&b&c&d\\
www& xxx&yyy&zzz
\end{alignat}
rl \setalignpreamble{rl}
\begin{alignat}{2}
a &b&c&d\\
www& xxx&yyy&zzz
\end{alignat}
c \setalignpreamble{c}
\begin{alignat}{2}
a &b&c&d\\
www& xxx&yyy&zzz
\end{alignat}
ccrr \setalignpreamble{ccrr}
\begin{alignat}{2}
a &b&c&d\\
www& xxx&yyy&zzz
\end{alignat}
lcrc \setalignpreamble{lcrc}
\begin{alignat}{2}
a &b&c&d\\
www& xxx&yyy&zzz
\end{alignat}
\end{document}
答案4
这是一个使用 TikZ 和overlay,remember picture
的比较全面的实现\tikztag{text}
。
带星号的版本\tikztag*{text}
省略了 周围的括号text
。当给出单个可选参数时,它会给出标签的名称,例如\tikztag[eq:foo]{Foo}
将放置一个标签,例如\ref{eq:foo}
使用 用作Foo
“ref”文本。当给出第二个可选参数时,它会选择“ref”的文本,例如\tikztag*[eq:foo][Short]{Blah blah (Short)}
将引用方程式,但会在方程式的右侧Short
包含更多内容。Blah Blah
当 hyperref 加载时,引用\ref{…}
指向正确的子方程。
要使用它,只需复制序言中\makeatletter
和之间的所有内容\makeatother
(或在 中.sty
,删除\makeatletter
和\makeatother
行)。然后,使用\begin{taggableequationstar}…\end{{taggableequationstar}
代替\begin{equation*}…\end{equation*}
包含 使用的方程式\tikztag
。
% This code is released under the CC0 license (i.e. in the Public Domain
% or under a very permissive license if your country does not recognise
% dedications to the Public Domain.
\documentclass{article}
\makeatletter
\usepackage{amsmath, tikz, array, hyperref, lipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parse options into:
% \if@tikztag@star
% \if@tikztag@label@
% \@tikztag@label
% \if@tikztag@labeltext@
% \@tikztag@label
\newif\if@tikztag@star@
\newif\if@tikztag@label@
\newif\if@tikztag@labeltext@
\def\tikztag{\@ifstar\@tikztag@star\@tikztag@nostar}
\def\@tikztag@star{\@tikztag@star@true\expandafter\@tikztag@common}
\def\@tikztag@nostar{\@tikztag@star@false\expandafter\@tikztag@common}
\def\@tikztag@common{\@ifnextchar[{%
\@tikztag@label@true\@tikztag@get@label%
}{%
\@tikztag@label@false\@tikztag%
}}
\def\@tikztag@get@label[#1]{\def\@tikztag@label{#1}\expandafter\@tikztag@get@maybe@labeltext}
\def\@tikztag@get@maybe@labeltext{\@ifnextchar[{%
\@tikztag@labeltext@true\@tikztag@get@labeltext%
}{%
\@tikztag@labeltext@false\@tikztag%
}}
\def\@tikztag@get@labeltext[#1]{\def\@tikztag@labeltext{#1}\expandafter\@tikztag}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Implementation:
\edef\tikztagnumber{0}
\newcommand{\@tikztag}[1]{%
% place the marker:
\pgfmathtruncatemacro{\tikztagnumber}{\tikztagnumber+1}%
\xdef\tikztagnumber{\tikztagnumber}%
\tikz[remember picture]\coordinate(tikztagmarker\tikztagnumber){};%
% dispatch given the options
\expandafter\gdef\csname @tikztag@tag@\tikztagnumber\endcsname{#1}%
\if@tikztag@label@%
\if@tikztag@labeltext@%
\if@tikztag@star@%
\edef\@@tikztag{\noexpand\@@@tikztag{\expandafter\noexpand\@tikztag@label}{\expandafter\noexpand\@tikztag@labeltext}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{\tikztagnumber}{\noexpand\@firstoftwo}}%
\else%
\edef\@@tikztag{\noexpand\@@@tikztag{\expandafter\noexpand\@tikztag@label}{\expandafter\noexpand\@tikztag@labeltext}{(\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname)}{\tikztagnumber}{\noexpand\@firstoftwo}}%
\fi%
\else%
\if@tikztag@star@%
\edef\@@tikztag{\noexpand\@@@tikztag{\expandafter\noexpand\@tikztag@label}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{\tikztagnumber}{\noexpand\@firstoftwo}}%
\else%
\edef\@@tikztag{\noexpand\@@@tikztag{\expandafter\noexpand\@tikztag@label}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{(\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname)}{\tikztagnumber}{\noexpand\@firstoftwo}}%
\fi%
\fi%
\else%
\if@tikztag@star@%
\edef\@@tikztag{\noexpand\@@@tikztag{no label}{no label text}{\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname}{\tikztagnumber}{\noexpand\@secondoftwo}}%
\else%
\edef\@@tikztag{\noexpand\@@@tikztag{no label}{no label text}{(\expandafter\noexpand\csname @tikztag@tag@\tikztagnumber\endcsname)}{\tikztagnumber}{\noexpand\@secondoftwo}}%
\fi%
\fi%
\@@tikztag%
}
\newcommand{\@@@tikztag}[5]{%
\g@addto@macro\accumulatetikztag{\@@@@tikztag{#1}{#2}{#3}{#4}{#5}}%
}
% #1=label #2=label text #3=text #4=\tikztagnumber #5=\@firstoftwo or \@secondoftwo to use label or not
\newcommand{\@@@@tikztag}[5]{%
\tikz[overlay,remember picture]%
\node[anchor=base east, inner xsep=0pt]%
at (tikztagmarker#4 -| current line right)%
{#3};%
#5{%
\tikz[overlay,remember picture]%
\node[anchor=base east, inner xsep=0pt]%
at (tikztagmarker#4 -| current line left)%
{\phantomsection\edef\@currentlabel{#2}\label{#1}};%
}{}
}
\newenvironment{taggableequationstar}{%
\noindent\tikz[remember picture]\coordinate(current line left){};%
\tikz[overlay,remember picture]%
\coordinate[xshift=\linewidth] (current line right) at (current line left){};%
\xdef\accumulatetikztag{}%
\begin{equation*}%
}{%
\end{equation*}%
\accumulatetikztag
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatother
\begin{document}
\newcolumntype{R}{>{\displaystyle}r}
\newcolumntype{C}{>{\displaystyle}c}
\newcolumntype{L}{>{\displaystyle}l}
\lipsum[2]
\begin{equation*}
\begin{array}{@{}R@{}C@{}L@{}}
a&bbbbb&c \\
x&y&z \\
\end{array}
\end{equation*}
\lipsum[2]
\begin{taggableequationstar}
\begin{array}{@{}R@{}C@{}L@{}}
a&bbbbb&c \tikztag[eq:foo][abc]{a, b and c} \\
x&y&z \tikztag[eq:bar]{other stuff}\\
x&y&z \tikztag{more stuff}\\
\end{array}
\end{taggableequationstar}
Foo: \ref{eq:foo}. Bar: \ref{eq:bar}. Baz: \ref{eq:baz}. Quux: \ref{eq:quux}.
\lipsum[2]
\begin{taggableequationstar}
\begin{array}{@{}R@{}C@{}L@{}}
\frac{a}{i}&bbbbb&c \tikztag*[eq:baz][baz]{a, b and c (baz)} \\
x&y&z \tikztag*[eq:quux]{other stuff 2}\\
x&y&z \tikztag*{more stuff 2}\\
\end{array}
\end{taggableequationstar}
\end{document}