[Tex/LaTex] Reduce the space between a quotation and a title

line-spacingquotingsetspacespacing

When I use the quotation environment at the start of a section I get too much space between the title and the start of the quotation. How to modify spacing around quotation environment? has ways to set the spacing manually, which is 0, but I'd rather LaTeX handle the spacing for me, as I am not sure how much to put.

So I started with this

\documentclass[12pt,letterpaper]{article}
\usepackage{setspace}           %Allows double spacing with the \doublespacing command

\begin{document}
\doublespacing

\section{Too much space}
\singlespacing 
\begin{quotation} 
    \noindent Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{quotation}

\doublespacing
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

\section{The right spacing}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\end{document}

And I really like the output, except for the giant space between the title and the quotation.

I tried one of the answers from the last question, but it kills all the whitespace, so I put in \baselineskip instead of 0, but that doesn't seem to work.

\documentclass[12pt,letterpaper]{article}
\usepackage{setspace}           %Allows double spacing with the \doublespacing command

\makeatletter
\renewenvironment{quotation}
               {\list{}{\listparindent=0pt%whatever you need
                        \itemindent    \listparindent
                        \leftmargin=0pt%  whatever you need
                        \rightmargin=10pt%whatever you need
                        \topsep=\baselineskip%%%%%  whatever you need
                        \parsep        \z@ \@plus\p@}%
                \item\relax}
               {\endlist}
\makeatother


\begin{document}
\doublespacing

\section{Too much space}
\singlespacing 
\begin{quotation} 
    \noindent Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{quotation}

\doublespacing
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

\section{The right spacing}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\end{document}

But as you can see if you compile that (I'm not sure how to put in images of the output) the spacing is the large at both the top and bottom of the environment.

And yes, I know double spacing is horrible, but the essay must be double spaced so the TA can write in comments.

Edit: I just found out that I should be using quote, not quotation, but it gives the same problem.

Best Answer

Add code to quotation based on the fact that after a section the switch \if@nobreak is true:

\usepackage{etoolbox}
\makeatletter
\AtBeginEnvironment{quotation}{\if@nobreak\vspace*{-\topskip}\fi\singlespacing}
\makeatother

Now you don't have to issue \doublespacing after quotation, because the environment will keep the single spacing confined into it.

It seems to work right even when the section falls near the bottom of a page.

Using lockstep suggestion you can also say

\usepackage{etoolbox}
\BeforeBeginEnvironment{quotation}{\par\begin{singlespace*}}
\AfterEndEnvironment{quotation}{\end{singlespace*}}