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



\def\FrameCommand{\fboxsep1pt \colorbox{shadecolor}}%
  \MakeFramed {\FrameRestore}}%



\subsection{Bad Subsection}
        Bad Theorem: is moved

\subsection{Okay without shading}
        Good theorem

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

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

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

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


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

  • 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, 2021 at 11:18
  • 1
    @MarkusG. Theorem 1.2 somehow ends up printed ABOVE the second subsection, even though it is issued after the \subsection. May 19, 2021 at 12:18
  • Second subsection should start from theorem. But theorem precedes subsection and subsection starts from the proof May 19, 2021 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.) May 19, 2021 at 21:04
  • @barbarabeeton you are of course correct. (See both the 6th section in the MWE above and my follow up question tex.stackexchange.com/questions/597762/…) I take it from your comment that "doing something to leave v mode" is what one should do in this case? May 20, 2021 at 11:55


You must log in to answer this question.

Browse other questions tagged .