3

I have the following test case:

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
    \section{Test}
    \paragraph{Group A:}
    \begin{align*}
        E &= mc^2\\
        E &= \hbar\omega
      \intertext{\paragraph{Group B:}}
        F &= ma\\
        F &= mv\frac{dv}{dx}
    \end{align*}
\end{document}

I would expect this to produce the paragraph title "Group A:", followed by two energy expressions, followed by the paragraph title "Group B:", followed by two force expressions. When I use two align* blocks instead of intertext then this works, but in my actual document (where the equations are more complicated), the equations are obviously not aligned across the blocks.

If I remove the \paragraph from the \intertext, then I get the expected result (but the "Group B:" text is obviously not formatted as I want).

The specific output that I get from TexMaker looks as follows:

Log:

LOG FILE :
This is pdfTeX, Version 3.1415926-1.40.10 (MiKTeX 2.8) (preloaded format=pdflatex 2013.7.16) 16 JUL 2013 15:42
(etc)

Output:

1 Test

Group A:

E = mc²

E = hw

Group A:

F = ma

F = mv dv/dt

Group A:

...which is obviously not what I want!

Solution (thanks to egreg):

Prelude:

\newcommand{\group}[1]{\noalign{\noindent\textbf{#1}}}

Document:

  E &= mc^2\\
  E &= \hbar\omega\\
\group{Group B:}\\
  F &= ma\\
  F &= mv\frac{dv}{dx}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • 3
    Welcome to TeX.SX! You're abusing \paragraph, in my opinion. Why not just \noindent\textbf{Group A:}? – egreg Jul 16 '13 at 14:51
  • Hi! I normally use Word2000, so I'm used to using heading styles for headings, rather than setting the formatting manually. I chose Tex for this since I want some nice vector diagrams (via Tikz), and originally had two \paragraphs and two align* blocks. I'll try that \noindent\textbf way now. Thanks! – Mark K Cowan Jul 16 '13 at 14:53
  • \paragraph is actually the name for the sectional level below \subsubsection. You can define your own macro, say \newcommand{\group}[1]{\par\noindent\textbf{Group #1:}} and use \group{A} instead of specifying formatting instructions in the document. – egreg Jul 16 '13 at 14:55
  • @egreg: That gives the right formatting, but the alignment is off. Wrapping it in \noalign worked! Thanks! – Mark K Cowan Jul 16 '13 at 14:56
  • @egreg: Just out of curiosity, how am I abusing \paragraph? -- ah just seen your answer, thanks! – Mark K Cowan Jul 16 '13 at 15:05
  • @MarkKCowan LaTeX users would also expect to use sectioning commands for sections, but not inside the middle of an alignment! – Joseph Wright Jul 16 '13 at 15:05
  • @JosephWright: Thanks, I'm producing a list of equations that are separated into small named sections by usage, and should all be aligned at the =. – Mark K Cowan Jul 16 '13 at 15:13

1 Answers1

4

The \paragraph macro is not a general purpose macro for setting things in boldface. It's a sectional command, in the hierarchy

\section
\subsection
\subsubsection
\paragraph
\subparagraph

In your case I'd define a special macro for this kind of secondary header.

\documentclass[12pt]{article}
\usepackage{amsmath,mathtools}

\newcommand{\group}[1]{%
  \par\noindent\textbf{Group #1:}
}

\begin{document}
\section{Test}
\group{A}
\begin{align*}
  E &= mc^2\\
  E &= \hbar\omega
\shortintertext{\group{B}}
  F &= ma\\
  F &= mv\frac{dv}{dx}
\end{align*}
\end{document}

In this way you don't have formatting instructions in the file and the \group macro represents an instance of an abstract secondary header; you can modify the appearance just by acting on the definition.

For better results, \shortintertext from mathtools should be used, because the spacing it provides are not as dramatic as those produced by \intertext.

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
  • When I try putting \par directly inside the intertext it complains about the paragraph ending before align*. But it works if I have the \par inside another command like the \group{} command here then it works perfectly. Even something like \newcommand\gpar\par is enough (you can then use \gpar inside an intertext); I can't understand why this is the case though. – codebeard Dec 26 '16 at 05:49
  • @codebeard align doesn't accept \par inside it, even if it is in \intertext. – egreg Dec 26 '16 at 10:22
  • yes, that's what confuses me. I guess there are two questions here: 1) why does \renamedpar work but \par does not, and 2) why does align try to prevent par in the first place? – codebeard Dec 26 '16 at 14:00
  • 1
    @codebeard When a macro is not \long (which is what the inner macros for align are) it doesn't accept \par in its argument (as well as an empty line), but it accepts any other token, even if it is equivalent to \par. See What's the difference between \newcommand and \newcommand*? – egreg Dec 26 '16 at 14:02