GeneralText Spacement Problems with Equations

LaTeX specific issues not fitting into one of the other forums of this category.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Text Spacement Problems with Equations

Post by Cham »

I'm experiencing a problem with spacement above many displayed equations (not all of them).

I'm currently using a solution which works, but it's a kind of "hack" and it's certainly not in the spirit of LaTeX. My solution is annoying since I can't predict the result, if I edit the text above an equation. I frequently have to "hack" the code after I see the output, so this is certainly NOT the way to go with LaTeX.

Here's a complete compilable example.

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{setspace}
\setstretch{1.1}
\usepackage{anysize}
\marginsize{1.5in}{1in}{0.5in}{0.5in}

\newcommand*{\topless}{\setlength{\abovedisplayskip}{0pt}}
\newcommand*{\topmore}{\setlength{\abovedisplayskip}{12pt}}

\begin{document}

\section{Code with spacement problems}
Bla bla bla bla bla bla bla blabla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla :
	\begin{equation}
		A + B - C = 0.
	\end{equation}
Bla bla blabla bla bla blabla bla bla bla
	\begin{equation}
		D + E = F.
	\end{equation}
bla bla bla bla :
	\begin{equation}
		P - G + H = K - L,
	\end{equation}
bla bla bla blabla bla bla blabla bla bla blabla bla bla blabla bla bla blabla bla bla blabla bla bla blabla bla bla bla.
	\begin{equation}
		A + B - C + G - H = J - K.
	\end{equation}
bla bla bla blabla bla bla
	\begin{equation}
		A + B - C + G - H = J - K.
	\end{equation}
bla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla
	\begin{equation}
		C + D - H = FG - HK
	\end{equation}

\section{Same code with "hacks"}
Bla bla bla bla bla bla bla blabla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla :
\topless
	\begin{equation}
		A + B - C = 0.
	\end{equation}
Bla bla blabla bla bla blabla bla bla bla
\topmore
	\begin{equation}
		D + E = F.
	\end{equation}
bla bla bla bla :
	\begin{equation}
		P - G + H = K - L,
	\end{equation}
bla bla bla blabla bla bla blabla bla bla blabla bla bla blabla bla bla blabla bla bla blabla bla bla blabla bla bla bla.
	\begin{equation}
		A + B - C + G - H = J - K.
	\end{equation}
bla bla bla blabla bla bla
\topless
	\begin{equation}
		A + B - C + G - H = J - K.
	\end{equation}
bla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla bla blabla
	\begin{equation}
		C + D - H = FG - HK
	\end{equation}

\end{document}
Here's a preview of part of the output (with colorized indicators added by hand).
spacements.jpg
spacements.jpg (97.6 KiB) Viewed 5360 times
The first section isn't using any "hack" and the problems are showing there (red cross). The second section is using some hacks to solve the issue (see both macros I defined in the preamble).

Apparently, the problem is caused by the following commands in the preamble :

Code: Select all

\usepackage{setspace}
\setstretch{1.1}
\usepackage{anysize}
\marginsize{1.5in}{1in}{0.5in}{0.5in}
Of course, if I change any of these commands, the output is completely different!
I need those margin sizes and the 1.1 stretch between text lines (because of some intext equations). The spacements should be as shown in the second section.

So what should I do to solve the issue, without using a special macro before some equations ?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Text Spacement Problems with Equations

Post by Cham »

No idea on this ?

I suspect I should use the geometry package, instead of anysize, but I don't know yet how to setup the margins to get exactly what I have with anysize.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Text Spacement Problems with Equations

Post by cgnieder »

Cham wrote:I suspect I should use the geometry package, instead of anysize, but I don't know yet how to setup the margins to get exactly what I have with anysize.
Doesn't

Code: Select all

\usepackage{geometry}
\geometry{left=1.5in,right=1in,top=.5in,bottom=.5in}
do it?

Regards
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Text Spacement Problems with Equations

Post by Cham »

Yes, I just found it :

Code: Select all

\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
But it doesn't solve the spacement problem with the displayed equations (subject of this topic).

Any idea ?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Text Spacement Problems with Equations

Post by cgnieder »

Well, the vertical space before a displayed equation is determined by \abovedisplayskip or \abovedisplayshortskip, respectively. TeX does some calculation depending on (roughly) \displaywidth (the width of the display equation) and \predisplaysize (the width of the last line before the displayed equation). What you could do to interfere with this calculation is shorten the \predisplaysize at the beginning of a displayed equation by, e.g., saying

Code: Select all

\everydisplay{\predisplaysize=\dimexpr\predisplaysize-2em\relax}
(you should probably play with the 2em to find a value that suits your wishes).

Regards
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Text Spacement Problems with Equations

Post by Cham »

Thanks for this suggestion. It appears to work on my test file, but it's also changing the spacement between the sction title and the following text. I'm not sure this is ok yet.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Text Spacement Problems with Equations

Post by cgnieder »

Cham wrote:it's also changing the spacement between the sction title and the following text.
This is quite impossible unless the definition of the sectioning commands has been changed in some weird way or the section titles are followed directly by a displayed equation (which also seems strange to me). Do you have a Infominimal working example that shows this behaviour?
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Text Spacement Problems with Equations

Post by Cham »

I applied your suggestion to the previous example I gave above, to which I added these packages :

Code: Select all

\usepackage[french]{babel}
\usepackage{microtype}
EDIT : However, on my main (large) document, it appears to have no effect on the spacement between the section title and its text below it.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Text Spacement Problems with Equations

Post by cgnieder »

I see no changes with these packages (except for the paragraph indent, but that is \usepackage[french]{babel}'s fault and has nothing to do with \predisplaysize).
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Text Spacement Problems with Equations

Post by Cham »

I'm testing further your suggestion on my main document. Let's see...
Post Reply