2

I today saw very interesting case when subsection started by shaded environment

\documentclass{amsbook}%{amsart}
\usepackage{xcolor}
\usepackage{framed}

\newtheorem{theorem}{Theorem}[section]

\newenvironment{Shaded}{% \def\FrameCommand{\fboxsep1pt \colorbox{shadecolor}}% \MakeFramed {\FrameRestore}}% {\endMakeFramed}

\newenvironment{ShadedTheorem} { \definecolor{shadecolor}{rgb}{.94,.96,.94}% \begin{Shaded}% \begin{theorem}% }{% \end{theorem}% \end{Shaded}% }

\begin{document}

\subsection{Bad Subsection} \begin{ShadedTheorem} Bad Theorem: is moved \end{ShadedTheorem}

\subsection{Okay without shading} \begin{theorem} Good theorem \end{theorem}

\subsection{Subsection with text first} Okay if shaded theorem is not the first object \begin{ShadedTheorem} Theorem Statement \end{ShadedTheorem}

\subsection{Subsection with space first OK}~ \begin{ShadedTheorem} Theorem Statement \end{ShadedTheorem}

\subsection{Subsection with \texttt{\textbackslash par} first: not okay}\par \begin{ShadedTheorem} Theorem Statement \end{ShadedTheorem}

\subsection{Subsection, leave vertical mode first, then enter vertical mode again.}\leavevmode\par \begin{ShadedTheorem} Theorem Statement \end{ShadedTheorem}

\end{document}

In all cases the shaded theorem should appear after the section heading. But that's not what the output shows.

enter image description here

In general as you can see there is way around. However somebody may see similar case and need some solution. Also may be there are solution different from what I found

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
  • Can you specify what you are getting at? As I see it, there is neither an issue nor a question. The code you provided compiles without errors or warnings and looks fine to me. What is this "interesting case" you are refering to? – Markus G. May 19 '21 at 11:18
  • 1
    @MarkusG. Theorem 1.2 somehow ends up printed ABOVE the second subsection, even though it is issued after the \subsection. – Willie Wong May 19 '21 at 12:18
  • Second subsection should start from theorem. But theorem precedes subsection and subsection starts from the proof – Aleks Kleyn May 19 '21 at 12:39
  • I haven't checked this, but I believe that a \subsection is meant to be run in. Thus it is assuming that the theorem statement is an implicit "argument" of \subsection. If that is indeed the case, adding \leavevmode or $ $ before the theorem should correct the order. (I will be offline for a few hours, and don't have time to check this now.) – barbara beeton May 19 '21 at 21:04
  • @barbarabeeton you are of course correct. (See both the 6th section in the MWE above and my follow up question https://tex.stackexchange.com/questions/597762/why-is-startsection-defined-this-way-and-is-there-a-way-to-fix-it?noredirect=1&lq=1.) I take it from your comment that "doing something to leave v mode" is what one should do in this case? – Willie Wong May 20 '21 at 11:55
  • @WillieWong -- "of course" is a bit strong, but thanks for your confidence. \leavevmode is something I've taken on faith, not understanding how it works well enough to explain. But after poking around, I like the solution I proposed here: Proof environment - line break after the “Proof.” It avoids a possible break after the heading at the end of a page. – barbara beeton May 20 '21 at 14:34
  • @barbarabeeton When I started my paper more then year, I used theorem environment and everything was good. I did not return to specific place for diff equations for long time. because I believed that I finished there. This winter I decided to use frame package to highlight theorems. When I see that everything works as expected, I made global change in my text. Few days ago I decided to add few theorems for diff equations and returned to place which I finished year ago. To my surprise I discovered that I lost theorem and section started from prove. The rest was experiment with code – Aleks Kleyn May 20 '21 at 21:11

0 Answers0