Take the 2-minute tour ×
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 saw a question that tells me how to change the spacing in an algorithm environment, but I don't know how to do remove/change the space before and after an algorithm environment like:

% remove the space here
\begin{algorithm}
\begin{algorithmic}
[...]
\end{algorithmic}
\end{algorithm}
% remove the space here 
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Okay, I solved it in an "ugly" way by adding a

\vspace*{-.4cm}

at the respective places. For my case, this is fine, since I only have one algorithm environment in my tex file, however if you want it automatically be done in all your algorithm environments, there should be another way.

share|improve this answer
add comment

LaTeX has three length variables to control (i) the distance between two adjacent floating objects (such as figure, table, or algorithm objects), (ii) the distance between a float at the top (bottom) of a page and the text below (above) it, and (iii) the distance between an in-text float and the text above and below it; they are called \floatsep, \textfloatsep, and \intextsep, respectively. (LaTeX also has three more such variables to control the spacing above and/or below floats on floats-only pages; these are \@fptop, \@fpbot, and \@fpsep, respectively.)

To completely suppress the in-text separation of a float (not recommended, by the way!!), you'd type (in the preamble)

\setlength{\intextsep}{0pt}

i.e., you'd set \intextsep to a fixed length of 0 points. A better solution, if you're pressed for space (pun intended), would be to set

\setlength{\intextsep}{1\baselineskip}

Here's a MWE that uses the algorithm2e package:

\documentclass{article}
\usepackage{algorithm2e}
\newcommand{\lipsone}{Lorem ipsum dolor sit amet, consectetuer 
adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, 
adipiscing vitae, felis.}
\newcommand{\lipstwo}{Donec vehicula augue eu neque. Pellentesque 
habitant morbi tristique senectus et netus et malesuada fames ac 
turpis egestas.}
\begin{document}

\subsubsection*{With default setting of \texttt{\textbackslash intextsep}} 
\lipsone

\begin{algorithm}
\caption{A random example}
\SetAlgoLined
\KwData{Some input}[h]
\KwResult{Some output}
initialization\;
\While{not at end of this document}{read}
{go back to beginning\;}
\end{algorithm}

\lipstwo


\subsubsection*{After setting \texttt{\textbackslash intextsep} to 0pt}
\setlength{\intextsep}{0pt} 
\lipsone

\begin{algorithm}
\caption{Another random example}
\SetAlgoLined
\KwData{Some input}
\KwResult{Some output}
initialization\;
\While{not at end of this document}{read}
{go back to beginning\;}
\end{algorithm}

\lipstwo

\end{document}
share|improve this answer
add comment

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.