LaTeX forum ⇒ Math & ScienceCan't set vertical whitespace in the preamble

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

Can't set vertical whitespace in the preamble

Postby Keta » Tue Jan 27, 2009 5:04 pm

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:

\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?

User avatar
localghost
Site Moderator
Posts: 9203
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Tue Jan 27, 2009 6:16 pm

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¹
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Postby Keta » Tue Jan 27, 2009 8:42 pm

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: 9203
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Tue Jan 27, 2009 9:00 pm

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.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Postby Juanjo » Wed Jan 28, 2009 2:49 am

Keta,

If you need to set \abovedisplayskip in the preamble, write there a line like
\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

Postby Keta » Wed Jan 28, 2009 12:55 pm

Thanks Juanjo, very helpful! :D

User avatar
Stefan Kottwitz
Site Admin
Posts: 9705
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Jan 28, 2009 11:17 pm

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:
\makeatletter
\g@addto@macro\normalsize{\setlength\abovedisplayskip{40pt}}
\makeatother

or alternatively
\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

Postby Keta » Thu Jan 29, 2009 12:31 pm

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


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 3 guests