Math & ScienceCan't set vertical whitespace in the preamble

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Can't set vertical whitespace in the preamble

Post by Keta »

Hi all,

I was redefining vertical whitespace between formulas and text, which is controlled by four lengths, according to Voss' Math mode: \abovedisplayskip, \abovedisplayshortskip, \belowdisplayskip and \belowdisplayhortskip. Surprisingly for me, setting up those lengths in the preamble did nothing, I can only redefine them inside the document. Please test the following example (don't pay much attention to the typeset text ;) ), in which I try to introduce a huge whitespace just before the formula:

Code: Select all

\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\setlength\parindent{0pt}

% This won't work
\setlength\abovedisplayskip{40pt}

\begin{document}

This is the first line, which just fills space with text before the formula:
\[
f(x) = \int_0^{\infty} \frac{\sin x}{x}\ dx
\]
after the formula, this line works as a reference to see the vertical spacing.
\vspace{2\baselineskip}

% This time it will work
\setlength\abovedisplayskip{40pt}

This is the first line, which just fills space with text before the formula:
\[
f(x) = \int_0^{\infty} \frac{\sin x}{x}\ dx
\]
after the formula, this line works as a reference to see the vertical spacing.

\end{document}
Could somebody explain me this behavior? Why won't it let me set these lengths in the preamble, while I can set others?

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Can't set vertical whitespace in the preamble

Post by localghost »

The values of these lengths are determined by the font size. Hence it is not enough to set them in the preamble.


Best regards
Thorsten¹
Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Re: Can't set vertical whitespace in the preamble

Post by Keta »

Thanks localghost, I understand it now. So, no matter what I put in the preamble, once the document starts these lengths will be reset to a value depending on font size, right? OK, now I know what to do if it happens again with other length commands, thanks! :)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Can't set vertical whitespace in the preamble

Post by localghost »

Keta wrote:[...] OK, now I know what to do if it happens again with other length commands, thanks! [...]
You must not generalize this for all lengths. The most length registers can be set very well in the preamble. But there may be others apart from these here which can't.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Can't set vertical whitespace in the preamble

Post by Juanjo »

Keta,

If you need to set \abovedisplayskip in the preamble, write there a line like

Code: Select all

\AtBeginDocument{\setlength\abovedisplayskip{40pt}}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Re: Can't set vertical whitespace in the preamble

Post by Keta »

Thanks Juanjo, very helpful! :D
User avatar
Stefan Kottwitz
Site Admin
Posts: 10340
Joined: Mon Mar 10, 2008 9:44 pm

Can't set vertical whitespace in the preamble

Post by Stefan Kottwitz »

Hi Keta!

Commands like \normalsize, \small and \footnotesize could change the length of \abovedisplayskip, \belowdisplayskip etc. You could read it for example in bk12.clo in the directory where the LaTeX base classes are located.
Juanjos approach could work, but if some macro calls for instance \normalsize the value of \abovedisplayskip etc. would be changed back.

You could redefine \normalsize etc. according to the class. But here's a short way, using this you don't need to rewrite the original definition of \normalsize:

Code: Select all

\makeatletter
\g@addto@macro\normalsize{\setlength\abovedisplayskip{40pt}}
\makeatother
or alternatively

Code: Select all

\expandafter\def\expandafter\normalsize\expandafter{%
\normalsize\setlength\abovedisplayskip{40pt}}
See perhaps Using \expandafter for macro redefinitions.

This will work in the preamble, tested with your example.

Stefan
LaTeX.org admin
Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Re: Can't set vertical whitespace in the preamble

Post by Keta »

Thanks a lot for the hint Stefan, I'll use that instead. Nice explanation too! :D
Post Reply