前段时间,David Carlislebrqalign
在这个答案中写了一个很棒的函数:https://tex.stackexchange.com/a/51543/4011.参见下面引用的代码。
如何修改brqalign
环境,以便可以在可选参数中指定列数或至少最大列数?与原始内容一样,brqalign
列也应均匀分布在整个文本宽度上。
\documentclass{article}
\usepackage[leqno]{amsmath}
\renewcommand\theequation{\alph{equation}}
\newenvironment{brqalign}{%
% START CODE
%%%%%%%%%%%%
% Do everything an a box, as you can not remove
% things from the main vertical list.
\setbox0\vbox\bgroup
% Allow \\ for ends of row.
\let\\\cr
% Use an \halign (I experimented with using one
% of the AMS alignments but they tend to want to
% be full width, or already in math mode, so just
% use a primitive \halign here with two display math
% entries in its preamble.
\halign\bgroup
\refstepcounter{equation}\theequation)\quad
\hfil$\displaystyle##$&$\displaystyle{}##$\hfil\cr}%
{%
% END CODE
%%%%%%%%%%
% Finish the \halign.
\crcr\egroup
% Now, at this point the vertical list being assembled in
% box0 contains all the rows of the alignment these will be
% a sequence of \hboxes (which will all be forced to be the
% same width) and baselineskip glue. (While testing with the
% AMS alignments there was additional glue and penalties
% as well.
%
% We will discard all the glue and penalties but assemble
% a horizontal list of the boxes in box1.
% start by making box1 and empty hbox.
\global\setbox1\null
% Then loop backwards up the vertical list discarding any glue
% and penalties and grabbing hold of each box.
\loop
% This combination removes two adjacent glue items
% or glue followed by penalty, it may be more than needed
% but better be safe than sorry.
\unskip\unskip\unpenalty\unskip\unpenalty
% Glue and penalties we discard, but the boxes have the
% formula so remove this one from the current list and
% save it in box 4.
\setbox4\lastbox
% If there was no box box4 is void and we reached the top
% of the original vertical alignent so stop.
\ifvoid4
\else
% Otherwise Put this box4 at the front of the horizontal
% list being built in box1, followed by an em of space.
\global\setbox1\hbox{\box4\hskip 1em\unhbox1}%
% Go round the loop again.
\repeat
% End the group for the working box 0.
% The horizontal list is globally assigned
% to box 1 so will be visible after this group end.
\egroup
% Now put out all the boxes flush left, the usual paragraph breaker
% will fit as many on a line as it can. As each box is the same width
% vertical alignment is automatic.
\begin{flushleft}\unhbox1 \end{flushleft}%
% Ignore white space after the end of the environment
\ignorespacesafterend
}
\begin{document}
\begin{brqalign}
x^2 + y^2 &= 1\\
a + b &= c\\
r-x &= y+z \\
f - y &= z\\
a - b &= 2d\\
r+x &= 2y-3z
\end{brqalign}
\end{document}
答案1
我想这个问题是针对我的......
\documentclass{article}
\usepackage[leqno]{amsmath}
\renewcommand\theequation{\alph{equation}}
\newenvironment{brqalign}[1][]{%
\ifx\relax#1\relax
\def\colwidth{}%
\else
\def\colwidth{to \dimexpr(\linewidth/#1)-1em\relax}%
\fi
% START CODE
%%%%%%%%%%%%
% Do everything an a box, as you can not remove
% things from the main vertical list.
\setbox0\vbox\bgroup
% Allow \\ for ends of row.
\let\\\cr
% Use an \halign (I experimented with using one
% of the AMS alignments but they tend to want to
% be full width, or already in math mode, so just
% use a primitive \halign here with two display math
% entries in its preamble.
\halign\bgroup
\refstepcounter{equation}\theequation)\quad
\hfil$\displaystyle##$&$\displaystyle{}##$\hfil\cr}%
{%
% END CODE
%%%%%%%%%%
% Finish the \halign.
\crcr\egroup
% Now, at this point the vertical list being assembled in
% box0 contains all the rows of the alignment these will be
% a sequence of \hboxes (which will all be forced to be the
% same width) and baselineskip glue. (While testing with the
% AMS alignments there was additional glue and penalties
% as well.
%
% We will discard all the glue and penalties but assemble
% a horizontal list of the boxes in box1.
% start by making box1 and empty hbox.
\global\setbox1\null
% Then loop backwards up the vertical list discarding any glue
% and penalties and grabbing hold of each box.
\loop
% This combination removes two adjacent glue items
% or glue followed by penalty, it may be more than needed
% but better be safe than sorry.
\unskip\unskip\unpenalty\unskip\unpenalty
% Glue and penalties we discard, but the boxes have the
% formula so remove this one from the current list and
% save it in box 4.
\setbox4\lastbox
% If there was no box box4 is void and we reached the top
% of the original vertical alignent so stop.
\ifvoid4
\else
% Otherwise Put this box4 at the front of the horizontal
% list being built in box1, followed by an em of space.
\global\setbox1\hbox{\hbox\colwidth{\box4\hfil}\hskip 1em\unhbox1}%
% Go round the loop again.
\repeat
% End the group for the working box 0.
% The horizontal list is globally assigned
% to box 1 so will be visible after this group end.
\egroup
% Now put out all the boxes flush left, the usual paragraph breaker
% will fit as many on a line as it can. As each box is the same width
% vertical alignment is automatic.
\begin{flushleft}\unhbox1 \end{flushleft}%
% Ignore white space after the end of the environment
\ignorespacesafterend
}
\begin{document}
\begin{brqalign}
x^2 + y^2 &= 1\\
a + b &= c\\
r-x &= y+z \\
f - y &= z\\
a - b &= 2d\\
r+x &= 2y-3z
\end{brqalign}
\begin{brqalign}[2]
x^2 + y^2 &= 1\\
a + b &= c\\
r-x &= y+z \\
f - y &= z\\
a - b &= 2d\\
r+x &= 2y-3z
\end{brqalign}
\begin{brqalign}[1]
x^2 + y^2 &= 1\\
a + b &= c\\
r-x &= y+z \\
f - y &= z\\
a - b &= 2d\\
r+x &= 2y-3z
\end{brqalign}
\end{document}