1

I'd like to make a special paragraph environment that is numbered, and have the numbers put in the margin. Looking at this question, I came up with a way to do this using \llap. However, there is one issue: if the paragraph begins with a theorem environment then there is an unwanted line break at the start of the paragraph.

Here is what I have:

\documentclass{book}
\usepackage{lipsum}
\usepackage{amsthm}

\newtheorem*{theorem}{Theorem}
\newcounter{para}
\newenvironment{para}[1][]{%
  \vskip\baselineskip\noindent%
  \refstepcounter{para}%
  \llap{\makebox[6em][r]{[\thepara]\hspace{.75cm}}}%
}{}

\begin{document}

The following is correct:

\begin{para}
\lipsum[2]
\end{para}

\vskip\baselineskip
The following is incorrect:

\begin{para}
\begin{theorem}
\lipsum[2]
\end{theorem}
\end{para}

\vskip\baselineskip
The above should look like this:

\begin{para}
\textbf{Theorem.} \itshape \lipsum[2]
\end{para}


\end{document}

Sample output

One way to fix this is to define an alternate version of the theorem environment with no leading space, and use it at the start of these paragraphs. This is not ideal, since if you add/remove text before the theorem you'd have to remember to change the theorem environment to the right one. Is there a better way?

2
  • Should the number in the margin be the theorem number? – Bernard Oct 13 '20 at 19:48
  • The number in the margin should be the paragraph number. The theorems in this environment will not have their own numbers. – Winnie Oct 13 '20 at 19:59
0

All the theorem, list, and alignment (e.g., center) environments are derived from trivlist environment, and trivlist does some complex things to the "next" paragraph.

The following example makes use of the newly supported hook para/begin (since LaTeX2e 2021-06-01, see the doc texdoc ltpara), but I don't know why the \mbox{} is needed.

\documentclass{book}
\usepackage{lipsum}
\usepackage{amsthm}

\newtheorem*{theorem}{Theorem}
\newcounter{para}
\newenvironment{para}[1][]{%
  \vskip\baselineskip
  \refstepcounter{para}%
  \AddToHookNext{para/begin}{%
    \llap{\normalfont[\thepara]\hspace{.75cm}}\mbox{}%
    \OmitIndent % more or less equivalent to \noindent
  }%
}{}

\begin{document}

The following is correct:

\begin{para}
  \lipsum[2]
\end{para}

\bigskip
The following is incorrect:

\begin{para}
  \begin{theorem}
    \lipsum[2]
  \end{theorem}
\end{para}

\bigskip
The above should look like this:

\begin{para}
  \textbf{Theorem.} \itshape \lipsum[2]
\end{para}


\end{document}

enter image description here

1
  • Thanks for the reply after all these months, this looks useful. – Winnie Jul 12 at 12:59
0

A simple solution adds the relevant negative vertical spacing just before the theorem:

\documentclass{book}
\usepackage{lipsum}
\usepackage{amsthm}

\newtheorem*{theorem}{Theorem}
\newcounter{para}
\newenvironment{para}[1][]{%
  \vskip\baselineskip\noindent%
  \refstepcounter{para}%
  \llap{\makebox[6em][r]{[\thepara]\hspace{.75cm}}}%
}{}

\begin{document}

The following is correct:

\begin{para}
\lipsum[2]
\end{para}

\vskip\baselineskip
The following is also correct:

\begin{para}\vspace*{-\dimexpr\baselineskip+\topsep}
\begin{theorem}
\lipsum[2]
\end{theorem}

\end{para}

\end{document}

enter image description here

1
  • Thanks for the suggestion. This does work, but also suffers from the problem that you have to remember to add/remove the \vspace if you remove/add text before the theorem, so it's not totally ideal. – Winnie Oct 14 '20 at 11:03

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.