# Unnecessary space after \end{spacing}

This is my latex file:

\documentclass[11pt]{article}
\usepackage{setspace}
\begin{document}
\section*{Section 1}
\begin{spacing}{1.5}
Unnecessary\\
space\\
after\\
this1
\end{spacing}
\section*{Section 2}
Perfect\\
space\\
after\\
this2
\section*{Section 3}
\end{document}


This is the output:

I want as much space after 'this1' as there is after 'this2'. Any help would be appreciated.

• I don't think you should be switching spacing on and off like that; changing the spacing around section titles is better (and easier). – egreg Oct 14 '13 at 7:20
• Please be a bit more specific regarding your objectives. E.g., should there be an expanded amount of vertical whitespace between paragraphs within a spacing{1.5} environment, but just not after the final paragraph of such an environment? Should the reduced spacing (i.e., as if singlespacing were in effect) regardless of whether or not a spacing{1.5} environment is followed by a sectioning command? – Mico Oct 14 '13 at 7:26
• @Mico: Any of them should do, because both satisfy my objective here, which is to have the same amount of vertical space between 'this1' and 'Section 2' as there is between 'this2' and 'Section 3' – user34812 Oct 14 '13 at 10:00

You can achieve your goal by modifying the spacing environment provided by the setspace environment. This may be done along the following lines, which uses the calc package and changes what's done at the end of a spacing environment.

\documentclass[11pt]{article}
\usepackage{setspace}
%% insert the following material in preamble
\usepackage{calc}
\newlength\modparskip
\newlength\modbaselineskip
\def\baselinestretch{1} % this parameter will be redefined at start of 'spacing' environment
\setlength\modparskip{\parskip/\real{\baselinestretch}}%
\setlength\modbaselineskip{\baselineskip/\real{\baselinestretch}}%
\makeatletter
\renewenvironment{spacing}[1]{\par%
\def\baselinestretch{#1}%
\ifx\@currsize\normalsize\@normalsize\else\@currsize\fi%
}%
{\par%
\vskip \modparskip%      % originally: \vskip \parskip
\vskip \modbaselineskip% % originally: \vskip \baselineskip
}
\makeatother
%% end of material to be inserted in preamble

\begin{document}
\section*{Section 1}
\begin{spacing}{1.5}
Now also correct'' space after this1
\end{spacing}
\section*{Section 2}
Perfect space after this2
\section*{Section 3}
\end{document}

• I just re-compiled a LuaLaTeX document, using a new TeX installation, that I hadn't compiled since January 2015. A change in the output was the addition of extra vertical space after ending a spacing environment, compared to my 2015 output. A web search only turned up this as anything remotely relevant. So I gave your solution a try, even though I wasn't using the setspace package, but its memoir class emulation. All I get is an error, "Environment spacing undefined." Is there a modification that will make it work, or at least produce some output, even if it doesn't end up solving the problem? – Stonefeather Grubbs Oct 20 '16 at 6:17
• @StonefeatherGrubbs - If I understand your setup correctly, you're not loading the setspace package because the memoir document class provides something (fairly) equivalent. If this understanding is correct, all you would need to do with my code is to change \renewenvironment{spacing}[1]{... to \newenvironment{spacing}[1]{..., i.e., remove the "re" particle. Do let me know if this works for your document. – Mico Oct 20 '16 at 6:47
• Thank you. It did compile, but did not correct the spacing changes, so the problem must be in the way my new LiveTeX installation is handling vertical spacing that is different from my old MikTeX did. – Stonefeather Grubbs Oct 20 '16 at 7:08
• @StonefeatherGrubbs - I would like to suggest that you post a new query, in which you provide all details needed to replicate the issue(s) you're facing. That way, many more people will have a chance to read your posting and (hopefully) come up with a satisfactory solution. – Mico Oct 20 '16 at 8:08