GeneralAligning Algorithm

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
dragonfly
Posts: 2
Joined: Tue Jun 26, 2007 6:07 am

Aligning Algorithm

Post by dragonfly »

Hey guys,
I was wondering, is there a way to align an algorithm in latex? For example I want an algorithm to stay in the certain section of the paper, and not just randomly jump to pages. Is there a way to do it?

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Ted
Posts: 94
Joined: Sat Jun 23, 2007 4:11 pm

Aligning Algorithm

Post by Ted »

dragonfly wrote: I was wondering, is there a way to align an algorithm in latex? For example I want an algorithm to stay in the certain section of the paper, and not just randomly jump to pages. Is there a way to do it?

See Section 3.4.1 (Placement of Algorithms) of the documentation (linked from here).
Section 3.4.1 (Placement of Algorithms) of [i]algorithms[/i] documentation wrote: One important fact that many users may not have noticed is that the algorithm
environment is actually built with the float package and float, in turn, uses
David Carlisle’s here style option. This means that the floats generated by the
algorithm environment accept a special option, namely, [H], with a capital ‘H’,
instead of the usual ‘h’ offered by plain LaTeX.

This option works as a stronger request of "please put the float here": instead
of just a suggestion for LaTeX, it actually means “put this float HERE”, which
is something desired by many. The two algorithms typeset in this document use
this option.

Warning. You can’t use the ‘H’ positioning option together with the usual ‘h’
(for “here”), ‘b’ (for “bottom”) etc. This is a limitation (as far as I know) of
the float.sty package.

So I think you want...

Code: Select all

\begin{algorithm}[H]
%...
\end{algorithm}
-- Ted [home/blog]
Post Reply