Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I just got a short algorithm on my page, and it keeps getting aligned at the center of the page. But I want to have it aligned at the top, what do I have to do?

share|improve this question
Are you talking about an algorithm in a floating environment on a single page? However, it would be good if you show by a minimal example what you are doing. – Thorsten Donig Sep 15 '11 at 15:44

1 Answer

up vote 11 down vote accepted

To display a short algorithm (an object that LaTeX labels a "float") on a page by itself and to align it along the top of the page (instead of getting it to be centered vertically), try adding the following instructions to your document's preamble:

\makeatletter
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother

Happy TeXing!


Addendum: I've been asked to explain what exactly this code snippet does. The LaTeX "kernel" (see latex.ltx, ca. line 7260) sets up several parameters to help position a float (or floats) on a floats-only page. Among these, the parameters \@fptop and @fpbot -- short for "floating page top" and "floating page bottom", I suppose -- govern how much space is inserted above the top float and below the bottom float on a floats-only page. The default value for both parameters is 0\p@ \@plus 1fil. (\p@ is defined earlier in latex.ltx to be equal to 0pt.) The component 1fil is "infinitely stretchable glue" (in TeX jargon), i.e., it will expand to take up all available space within its scope (here, the vertical page dimension not already occupied by other material -- such as the float itself!). Thus, the float(s) will be centered vertically by default on the floats-only page, and (happily) no unnecessary warnings about under-full pages will be issued by LaTeX.

To force the first float on a floats-only page to be top-aligned, then, it should suffice to issue the command

\setlength{\@fptop}{0pt}

The second instruction, \setlength{\@fpbot}{0pt plus 1fil}, is there mostly to "play it safe", just in case some package has been loaded that fiddles with the \@fptop and \@fpbot parameters in a way that would make LaTeX start issuing warnings about under-full pages on floats-only pages should you reset just the \@fptop parameter...

share|improve this answer
That was exactly what I was looking for, thank you – chris Sep 16 '11 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.