How to decrease spacing before single space environment in LaTeX?

In summary: 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.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
  • #1
Master1022
611
117
TL;DR Summary
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:
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}
Below is some quick code I have put together to demonstrate the issue:
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}

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
  • #3
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?
 
  • #4
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?
 
  • #5
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

  • Title_spacing_testing.pdf
    44.8 KB · Views: 303
  • #6
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.
 
  • #7
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?
 
  • #8
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.
 
  • #9
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.
 

1. How do I decrease the spacing before a single space environment in LaTeX?

To decrease the spacing before a single space environment in LaTeX, you can use the command \setlength{\parskip}{0pt}. This will set the spacing between paragraphs to zero, which includes the spacing before a single space environment.

2. Can I change the spacing before a single space environment without affecting the spacing between paragraphs?

Yes, you can change the spacing before a single space environment without affecting the spacing between paragraphs by using the command \setlength{\parskip}{0pt} and then adding a specific amount of space before the single space environment using the command \vspace{amount}.

3. How do I adjust the spacing before a specific single space environment?

To adjust the spacing before a specific single space environment, you can use the command \vspace{amount} before the environment. This will add the specified amount of space before that particular environment.

4. Is there a way to globally change the spacing before all single space environments in my document?

Yes, you can globally change the spacing before all single space environments in your document by using the command \renewcommand{\arraystretch}{amount}. This will change the spacing before all single space environments, including tables and equations.

5. How can I adjust the spacing before a single space environment in a specific section or paragraph?

To adjust the spacing before a single space environment in a specific section or paragraph, you can use the \vspace{amount} command within that section or paragraph. This will only affect the spacing before the single space environment in that specific section or paragraph.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
11K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
46K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
275
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top