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