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

7
  • 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

0

You must log in to answer this question.

Browse other questions tagged .