0

I created an environment to shade some text I deem important. However, what I have within this environment can vary from a simple paragraph to an actual section or subsection. The problem is that the spacing before the text increases with the importance of the heading. I believe this is normal behavior, but in the book I'm writing it is too exaggerated for even subsubsection. Is there a way to reduce this space in a simple manner? I guess one could try to determine in the macro whether a new section, subsection, or just a paragraph is passed, and subtract vertical space with negative \vspace but I guess this would not be a simple solution. This is the MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{lipsum}
\usepackage{framed}
\definecolor{shadecolor}{gray}{.85}%

\newenvironment{advanced}{\par \begin{shaded} \small}{\par\end{shaded}}

\begin{document}

\begin{advanced} \section{Section} \lipsum[1] \end{advanced}

\begin{advanced} \subsection{Subsection} \lipsum[1] \end{advanced}

\begin{advanced} \lipsum[1] \end{advanced} \end{document}

which produces this:

enter image description here

aaragon
  • 3,041
  • Can https://tex.stackexchange.com/questions/108684/spacing-before-and-after-section-titles help you? For example, add \usepackage{titlesec}and \titlespacing*{\section}{0pt}{0pt}{0pt} in the preamble (but the spacing is also modified for non framed sections ; it's probably also better to provide rubber lengths as 1ex plus 1ex minus 0.5ex instead of fixed lengths as 1ex, in particular for vertical space after the title). Change \subsection in the same way. – quark67 Feb 18 '23 at 00:45
  • If it will modify non-framed sections then it's not a solution to the problem. I need this to happen only locally to the advanced environment I created. – aaragon Feb 18 '23 at 11:17

0 Answers0