How to decrease spacing before single space environment in LaTeX?

  • Context: LaTeX 
  • Thread starter Thread starter Master1022
  • Start date Start date
  • Tags Tags
    decrease Latex Space
Click For Summary

Discussion Overview

The discussion revolves around how to decrease the extra spacing above a single-space equation environment in LaTeX. Participants explore various methods and commands to adjust spacing while maintaining a double-spaced document format.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant shares their LaTeX code and expresses the need to reduce spacing above equations wrapped in a single-space environment.
  • Another participant references the command \ignorespacesafterend as a potential solution but does not provide a clear application example.
  • Some participants question the ability to demonstrate the function of \ignorespacesafterend within the forum's LaTeX implementation.
  • There are requests for clarification on how to apply the suggested command in the provided code.
  • Participants discuss the limitations of sharing code and rendering environments, with suggestions to use different LaTeX compilers for better compatibility.

Areas of Agreement / Disagreement

There is no consensus on the best method to reduce the spacing, and multiple competing views and suggestions remain unresolved.

Contextual Notes

Participants mention the need for specific environments and rendering capabilities, which may affect the applicability of suggested solutions. There is uncertainty regarding the behavior of the code across different LaTeX compilers.

Master1022
Messages
590
Reaction score
116
TL;DR
I have wrapped equations in single space environments within a double spaced document. This has lead to some extra superfluous space above the equations, which I would like to remove. How can I do that?
Hi,

Question: How can I remove the extra spacing above the single-space equation environment. I have wrapped the equations in a single-space environment as the document has to be double spaced (and I wanted to save as much space as possible)

From reading online, I have the following code at the top of my LaTeX:
[CODE title="LaTeX spacing package code"]\usepackage{titlesec}
\titlespacing\section{0pt}{0pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{0pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}
\titlespacing\subsubsection{0pt}{0pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}

% this code is to decrease the spacing between equations and text
\newcommand{\zerodisplayskips}{%
\setlength{\abovedisplayskip}{0pt}%
\setlength{\belowdisplayskip}{0pt}%
\setlength{\abovedisplayshortskip}{0pt}%
\setlength{\belowdisplayshortskip}{0pt}}
\appto{\normalsize}{\zerodisplayskips}
\appto{\small}{\zerodisplayskips}
\appto{\footnotesize}{\zerodisplayskips}
[/CODE]Below is some quick code I have put together to demonstrate the issue:
[CODE title="Example code"]\documentclass{article}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{parskip}
\usepackage{multicol}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[margin= 20mm]{geometry}
\usepackage{hyperref}
\usepackage{subcaption}
\usepackage{verbatim}
\usepackage{etoolbox}
\doublespacing\titlespacing\section{0pt}{0pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{0pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}
\titlespacing\subsubsection{0pt}{0pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}

% this code is to decrease the spacing between equations and text
\newcommand{\zerodisplayskips}{%
\setlength{\abovedisplayskip}{0pt}%
\setlength{\belowdisplayskip}{0pt}%
\setlength{\abovedisplayshortskip}{0pt}%
\setlength{\belowdisplayshortskip}{0pt}}
\appto{\normalsize}{\zerodisplayskips}
\appto{\small}{\zerodisplayskips}
\appto{\footnotesize}{\zerodisplayskips}

\begin{document}
\section{Section}
\lipsum[1]
Look how much space is below this sentence:
\begin{singlespace}
\begin{align*}
y = a x^2 + bx + c \\
y = mx + b
\end{align*}
\end{singlespace}

\lipsum[2]. When I would prefer it to look like this:
\begin{equation}
y = ax^2 + bx + c
\end{equation}
\lipsum[3]

\end{document}[/CODE]

As shown in that code, the second equation has no spacing above it. The first set of equations (in the align environment) have more spacing when using the single-space environment and I was wondering how I can get rid of it? I needed to use the single-space environment around some equations as there are some examples in my document which take up a lot of space.

Thanks in advance for any help.
 
Physics news on Phys.org
sysprog said:
According to https://www.texfaq.org/FAQ-spaftend since 1996 you can use \ignorespacesafterend
Thanks for your reply. I can't seem to understand how to apply this command in the code. Would you be able to provide an example please?
 
The subset of ##\mathrm{\LaTeX}## that is implemented here on PF doesn't readily allow for demonstration of the function of \ignorespacesafterend, or of your posted code ##-## can you point to a location at which we can see your code rendered?
 
sysprog said:
The subset of ##\mathrm{\LaTeX}## that is implemented here on PF doesn't readily allow for demonstration of the function of \ignorespacesafterend, or of your posted code ##-## can you point to a location at which we can see your code rendered?
Thanks for your response. I wrote that exact code within Overleaf, so if you paste that into a blank document it should render what I am seeing. I have also attached a PDF version of what the code renders for me in Overleaf below. I will also see if I can share a URL, but I am not sure whether that is possible as I am on the free account. Does that work?
 

Attachments

Master1022 said:
Thanks for your response. I wrote that exact code within Overleaf, so if you paste that into a blank document it should render what I am seeing. I have also attached a PDF version of what the code renders for me in Overleaf below. I will also see if I can share a URL, but I am not sure whether that is possible as I am on the free account. Does that work?
I'm not a Mentor/Moderator here, which means, among other things, that what I say regarding Physics Forums policy isn't to be taken as authoritative. Please read the documentation available via the Terms link on the footer if you are in doubt, and please contact a Mentor via Conversation if you are still unsure about a policy after you've read the Terms.

As far as I know, you can/may post on-topic links. Of course, you should please not publicly post anything that you would not want made public. You have the same liberty to post links that any other member has. If you are interested in Gold Membership, there are some benefits to you that you can read about; however, greater liberty to post links is not among them.

The pdf that you uploaded isn't especially informative, as it doesn't include any of what is being rendered, or of what renderer you're using, or of what inclusions or customizations you've emplaced in your environment, etc. ##-## I suggest that you might go to https://www.tug.org/protext/ and install MikTex ##-## that way, you can post complete code for others who have MikTex installed, and they can observe the behavior that you're observing, and test their ideas before making suggestions to you ##-## if we don't know the platform from which you're working, we can't rely on specific applicability of the suggestions.
 
sysprog said:
As far as I know, you can/may post on-topic links. Of course, you should please not publicly post anything that you would not want made public. You have the same liberty to post links that any other member has. If you are interested in Gold Membership, there are some benefits to you that you can read about; however, greater liberty to post links is not among them.

The pdf that you uploaded isn't especially informative, as it doesn't include any of what is being rendered, or of what renderer you're using, or of what inclusions or customizations you've emplaced in your environment, etc. ##-## I suggest that you might go to https://www.tug.org/protext/ and install MikTex ##-## that way, you can post complete code for others who have MikTex installed, and they can observe the behavior that you're observing, and test their ideas before making suggestions to you ##-## if we don't know the platform from which you're working, we can't rely on specific applicability of the suggestions.

Apologies, I may not have been clear. I was referring to Overleaf (the online Latex editor) for which I only have the free account. The website is https://www.overleaf.com/ and it is an online compiler for latex. Does that provide more information?
 
Master1022 said:
Apologies, I may not have been clear. I was referring to Overleaf (the online Latex editor) for which I only have the free account. The website is https://www.overleaf.com/ and it is an online compiler for latex. Does that provide more information?
Thanks for clarifying ##-## I don't have an Overleaf account, and I don't know what environment it establishes, so I can't predict the line spacing behavior in that environment ##-## I looked cursorily at Overleaf paragraph formatting , but 'open an example' led to a 'register' prompt, and I didn't opt to register.

Perhaps you can post code that you have, on a site that doesn't require registration, verified to be on that site renderable verbatim.
 
sysprog said:
Perhaps you can post code that you have, on a site that doesn't require registration, verified to be on that site renderable verbatim.

Sure, but does the code in the original post not work in other Latex compilers? Asking out genuine curiosity as I have never tried any other ones.
 
  • #10
Master1022 said:
Sure, but does the code in the original post not work in other Latex compilers? Asking out genuine curiosity as I have never tried any other ones.
It seems to me that you might try to reduce the problem to something that is more universally renderable. Please consider what the impact of \usepackage is. I can't experiment with your code if I don't have all of those packages available, but if some of them are not essential for the limited purpose of demonstrating the specific concern that you have, then your problem statement need not include them.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
13K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 3 ·
Replies
3
Views
46K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K