TransWikia.com

make latex to automatically choose the placement of algorithms

TeX - LaTeX Asked by arunmoezhi on May 15, 2021

I have several algorithms written down in a single file and would like latex to spread them across the document to save spaces. For example an algorithm can be just 3 or 4 lines and another can be 20 to 30 lines. So how do I tell latex to squeeze the smaller algorithms among the text in a document.

documentclass{llncs}
usepackage{llncsdoc}
usepackage{lipsum}
usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}
AlgoDisplayBlockMarkers 
begin{document}
lipsum
begin{algorithm}
caption{alg1label{1}} 
...;
...;
...;
...
end{algorithm}
begin{algorithm}
caption{alg2label{2}} 
...;
...;
...
end{algorithm}
begin{algorithm}
caption{alg3label{3}} 
...;
...;
...;
...
end{algorithm}
begin{algorithm}
caption{alg4label{4}} 
...;
...;
...;
...;
...
end{algorithm}
lipsum
end{document}

One Answer

This is not really an answer, but I have a feeling no one else is about to propose one soon. This comes as a collection of the previous comments on the question.

The quick answer is no, it is not possible to influence the order of algorithms, to optimize overall whitespace around them.

The long answer is, as pointed out by Werner not limited to algorithms but more generally to floats. This is very well explained by Frank Mittlebach in his extensive answer https://tex.stackexchange.com/a/39020/141947.

I will only reproduce part of his answer here for the sake of eas acces to the precise information I believe is relevant here :

For floats, this means that the algorithm is greedy, i.e., the moment it encounters a float it will immediately try to place it and, if it succeeds, it will never change its decision. This means that it may choose a solution that could be deemed to be inferior in the light of data received later on.

Answered by BambOo on May 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP