对齐时自动换行

对齐时自动换行

考虑以下例子https://tex.stackexchange.com/a/12782/4011

\documentclass{article}
\usepackage{amsmath}
\newcounter{eqn}
\renewcommand*{\theeqn}{\alph{eqn})}
\newcommand{\num}{\refstepcounter{eqn}\text{\theeqn}\quad}
\begin{document}
\begin{alignat*}{6}
  \num&& x^2 + y^2 &= 1 \qquad& \num&& a + b &= c
          &  \num&& r-x &= y+z \\
  \num&\quad& f - y &= z      & \num&& a - b &= 2d
    \qquad&  \num&& r+x &= 2y-3z
\end{alignat*}
\end{document}

输出

这里(像往常一样)必须通过 来指定换行的位置\\。但是有没有办法自动换行,比如你给出方程之间的空格,然后TeX自动决定在给定空格的约束下,有多少方程适合最满的行(比如 n),然后换行,这样你就可以在每行对齐中获得 n 个方程,就像上面的例子一样。

答案1

您可以使用垂直对齐来完成测量,然后在水平布局中重新排列它们:

在此处输入图片描述

\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}

相关内容