3

I am using a list environment to set some text and equations. The equations are displayed using flalign (but all that follows is also true for align), and they line up correctly with the text that precedes and follows them. But if I want to introduce a line between two lines of equations, using \noalign, then the inserted text is flushed completely left, and the leftmargin is ignored:

\documentclass[a4paper, 11pt]{article}

\usepackage{amsmath}

\begin{document}

\begin{list}{(a)}{%
  \settowidth{\leftmargin}{(m)}%
  \labelwidth\leftmargin\advance\labelwidth-\labelsep%
  \partopsep=0pt%
  }
\item Some text to make a line for the first example, using
  \texttt{\textbackslash align}.
  \begin{flalign*}
    &x^2+y^2=a^2&&\\
    \noalign{\text{a comment}} &r^2=a^2&&
  \end{flalign*}
  And some text to close the whole thing.
\end{list}

\end{document}

This yields: enter image description here

I know that I can fix this, for example by defining a command like \leftalign, which would precede the text with an appropriate \hspace, but I wondered if anyone could explain to me why \noalign ignores the leftmargin setting. I feel sure I'm missing something that might be important, but I haven't found an explanation anywhere.

  • 2
    can't explain technically why \noalign doesn't work, but \shortintertext (requires mathtools) will do what you want. – barbara beeton Feb 23 '17 at 16:09
  • The explanation you have asked for is pretty long; moreover, its level of detail depends on your level of expertize with (La)TeX. For example, do you know what \parshape is? However, from a general point of view, you can’t expect a primitive command like \noalign to cope correctly with LaTeX constructs: it’s always best to avoid the use of such primitives altogether. Finally, note that \text inside \noalign is superfluous (you are no longer in a mathematical context inside a \noalign). – GuM Feb 23 '17 at 17:43
1

As an alternative to barbara's suggestion, here I use an \rlap of the text, with some vertical space added too.

\documentclass[a4paper, 11pt]{article}

\usepackage{amsmath}

\begin{document}

\begin{list}{(a)}{%
  \settowidth{\leftmargin}{(m)}%
  \labelwidth\leftmargin\advance\labelwidth-\labelsep%
  \partopsep=0pt%
  }
\item Some text to make a line for the first example, using
  \texttt{\textbackslash align}.
  \begin{flalign*}
    &x^2+y^2=a^2&&\\[3pt]
    &\text{a comment}\\[3pt]
    &r^2=a^2&&
  \end{flalign*}
  And some text to close the whole thing.
\end{list}

\end{document}

enter image description here

| improve this answer | |
  • 1
    \text inside \rlap serves no purpose. – GuM Feb 23 '17 at 17:37
  • @GustavoMezzetti Thank you for the reminder...fixed. – Steven B. Segletes Feb 23 '17 at 17:50
  • 1
    Well, I would have rather dropped the \rlap, and retained the \text—or, more precisely, &\text{...}… :-) – GuM Feb 25 '17 at 0:05
  • @GustavoMezzetti My brain was definitely in neutral gear yesterday! Thanks. – Steven B. Segletes Feb 25 '17 at 12:33
0

You could do with \shortintertext (requires mathtools) or \intertext (just amsmath). You can also exploit enumitem instead of doing all computations by hand for your list.

\documentclass[a4paper, 11pt]{article}

\usepackage{amsmath,mathtools}
\usepackage{enumitem}
\usepackage{showframe}

\begin{document}

\begin{enumerate}[label=(\alph*),leftmargin=*,partopsep=0pt]
\item Some text to make a line for the first example, using
  \texttt{align}.
  \begin{flalign*}
  &x^2+y^2=a^2&&\\
  \shortintertext{a comment}
  &r^2=a^2&&
  \end{flalign*}
  And some text to close the whole thing.

\item Something else
\end{enumerate}

\end{document}

The showframe package is loaded just to show the bounding box of the text area.

enter image description here

You need to be aware, though, that different document classes may have very different ideas about the whole thing. If you change article into amsart, you'd get

enter image description here

You can do with nccmath:

\documentclass[a4paper, 11pt]{article}

\usepackage{amsmath,mathtools}
\usepackage{enumitem}
\usepackage{nccmath}
\usepackage{showframe}

\begin{document}

\begin{enumerate}[label=(\alph*),leftmargin=*,partopsep=0pt]
\begin{fleqn}
\item Some text to make a line for the first example, using
  \texttt{align}.
  \begin{align*}
  &x^2+y^2=a^2 \\
  \shortintertext{a comment}
  &r^2=a^2
  \end{align*}
  And some text to close the whole thing.

\item Some text to make a line for the first example, using
  \texttt{align}.
  \begin{equation*}
  x^2+y^2=a^2
  \end{equation*}
  a comment
  \begin{equation*}
  r^2=a^2
  \end{equation*}
  And some text to close the whole thing.
\end{fleqn}
\end{enumerate}

\end{document}

enter image description here

With amsart you should only change \begin{fleqn} into \begin{fleqn}[\leftmargin] to get

enter image description here

Adding a setting to itemsep would be better.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.