{algorithms} is about the presentation, numbering, and layout of algorithms or pseudocode in documents. Popular packages are algorithms, {algorithmicx}, {algorithm2e} and {listings}. For questions about the specific package, use the appropriate tag instead.
25
votes
2answers
756 views
Why does an environment's label have to appear after the caption?
\documentclass{article}
\usepackage{algorithm}
\begin{document}
\setcounter{section}{54}
\section{A section with no label}
\begin{algorithm}
\label{myalg}
\caption{An algorithm with the label ...
8
votes
1answer
797 views
Is it possible to have connecting loop lines (like algorithm2e) in algorithmic?
I am using the algorithmic package to typeset an algorithm. I would like to have connecting lines between the beginning and end of a loop or conditional like in the algorithm2e package. Is there an ...
12
votes
1answer
964 views
Mark a pseudocode block and insert comments near it
I am currently working on a LaTeX beamer presentation where I have to explain an algorithm. So I wrote this algorithm with
\usepackage{algorithm,algpseudocode}
This is the current algorithm:
...
47
votes
3answers
16k views
What is a good package for displaying algorithms?
I found this page with some examples:
http://en.wikibooks.org/wiki/LaTeX/Algorithms_and_Pseudocode
I'm wondering which one to use. Any suggestions? I'm using other packages too so whichever is less ...
13
votes
3answers
3k views
Include a line break in algorithmic while maintaining indentation
I have this code:
\DeclareCaptionFormat{algor}{%
\hrulefill\par\offinterlineskip\vskip1pt%
\textbf{#1#2}#3\offinterlineskip\hrulefill}
...
6
votes
3answers
2k views
How to put algorithm and figure(s) side by side?
How can I put an algorithm and figure(s) side by side?
Say,
XXXXXXXXXXX FIG ONE
XXXXXXXXXXX FIG ONE
XXXXXXXXXXX FIG ONE
XALGORITHMX FIG TWO
XXXXXXXXXXX FIG TWO
Please, only post working solution ...
5
votes
1answer
3k views
Algorithm over 2 pages
I am writing a few rather large pseudocode functions using algorithm and algorithmic, i.e. my code looks something like:
\begin{algorithm}
\caption{Coolest Algorithm ever} ...
6
votes
3answers
1k views
Neural Network representation
I would like to translate to Spanish a diagram that represents a neural network, the diagrama is something like this:
I would like to clone the design and effects, so I need some examples to do ...
13
votes
2answers
849 views
Typesetting algorithms in LaTeX like Knuth
Is there any LaTeX package for typesetting algorithms in the style Donald Knuth uses in The Art of Computer Programming?
I know about the algorithm2e package, but I am looking for something that ...
4
votes
1answer
384 views
How to place a float at the top of a floats-only page?
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?
5
votes
3answers
4k views
Rename “Algorithm” to “Listing”
Background
Syntax-highlighted source code image listings are being used as Algorithm floats with the lst: prefix for captions.
Problem
The following LaTeX code in the preamble renames the caption ...
8
votes
1answer
4k views
Vertical spacing in the algorithm environment
I'm using the algorithm/algorithmic packages and want to condense some of the vertical space between an algorithm's line numbers in order to save space. Ideally, I would like to remove 1 to 2mm of ...
5
votes
1answer
635 views
Indenting lines of code in algorithm
I am writting algorithm which has two stages. How can I indent code for stage one and for stage two?
\begin{algorithm}[H]
\caption*{my algorithm}
\begin{algorithmic}
\STATE \textbf{Stage one:} ...
8
votes
2answers
497 views
How to put an algorithm and a tikz drawing (objects of different type) side-by-side in the same float environment?
I am trying to put an algorithm and a tikz' drawing side-by-side inside a figure environment. I am aware of this question but I would like to have a single caption for them. For instance, in the text, ...
8
votes
1answer
3k views
How to add unnumbered lines in an algorithm?
I am typesetting algorithms with the algorithm package, and I would like to add unnumbered lines in them.
Is there a way to create a \State* command, the same way there is an equation* environment?
...
7
votes
1answer
155 views
The line spacing in the list of algorithms
This is my code:
\documentclass[12pt,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[chapter]{algorithm}
\renewcommand{\baselinestretch}{1.5}
\begin{document}
\begin{spacing}{1.2}
...
4
votes
1answer
2k views
Set width of algorithm environment (preferably document wide)
Looking for a way to set the width of an algorithm environment, preferably document wide (as opposed to per-algorithm). Thought it should be fairly easy, but couldn't find a particularly good ...
3
votes
1answer
364 views
Option in the algorithm with Latex
This is my algorithm:
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}[H]
\caption{My algo}
\begin{algorithmic}[1]
\STATE instruction 1
\STATE instruction 2
...
2
votes
2answers
4k views
How to remove/change the vertical spacing before and after an \algorithm environment?
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 ...
5
votes
1answer
405 views
Removing the borders from algorithm listings
I am relatively new to LaTeX. If I use standard algorithm and algorithmic environment for my algorithm listings I'm getting the borders displayed around the table with the pseudocode. How to remove ...
4
votes
2answers
7k views
Algorithmic package in LaTeX
I want to write the following algorithm in LaTeX:
V <- AllUnigramsInTraining(D)
N <- NumberOfTweets(D)
**for** each c ∈ C do
Nc <- Number of tweets in Class c
prior(c) <- [...]
...
4
votes
1answer
1k views
Renaming Algorithm to Heuristic in algorithm2e package
I am trying to write some heuristics for a problem using the algorithm2e package.
However as you may know, when you write :
\begin{algorithm}
\caption{Heuristic 1: Name of Heuristic}
...
...
3
votes
1answer
1k views
LaTeX algorithmic package: Undefined Control Sequence in for-Loop
I'm trying to specify an algorithm in pseudocode in a LaTeX document, but I'm having trouble with the for-Loop. My statement:
\for{$bin=0 to binCount$}
\item blablabla
\endfor
keeps on generating ...
2
votes
2answers
366 views
algorithmicx conflicts with babel with Hebrew
When trying to create any document with box algorithmicx and algorithmicx:
\documentclass{article}
\usepackage[hebrew,english]{babel}
\usepackage{algorithmicx}
\begin{document}
Hello, world.
...
10
votes
4answers
353 views
Looking for style files for writing a programming language book
I am looking for LaTeX style files for writing a programming language book (OO programming with Java examples). I'd appreciate if anyone can point me to style files that I can use.
5
votes
2answers
2k views
Horizontal line in Algorithmic Environment
I'd like to separate two sections in an algorithmic environment with a horizontal line, like:
-------------
Algorithm 1: MyAlgorithm
-------------
Part 1:
Do some stuff
-------------
Part 2:
...
4
votes
3answers
1k views
How to create an unnumbered algorithm with a caption?
I want to do something like:
\begin{algorithm*}
\caption{My unnumbered algorithm}
% etc. etc.
\end{algorithm*}
or
\begin{algorithm}
\nonumbercaption{My unnumbered algorithm}
% etc. etc.
...
3
votes
2answers
2k views
How to typeset gotos and labels using LaTeX pseudocode environments?
Is there any way to typeset gotos and labels using LaTeX pseudocode environments (algorithmic, pseudocode, clrscode, algorithm2e, etc.)? Automatic and correct indentation of labels would also be ...
2
votes
1answer
47 views
cleveref fails to reference algorithms
In the following example document, both \autoref and plain ref will correctly link and number an algorithm reference, but cleveref fails that task. It will just insert question marks instead. In ...
2
votes
1answer
2k views
Algorithm over two pages, with itemized lists
I am trying to split an algorithm over two pages. This has already been addressed before, with the closest result being this question. However, I have a wrinkle - I need the algorithm to have two ...
9
votes
1answer
1k views
What “smooth” plot interpolation algorithm does pgfplots use?
In the pgfplots manual it says:
\addplot+[smooth]
Smooth plots interpolate smoothly between successive points.
In order to choose the right sampling of points from a function evaluation for ...
7
votes
2answers
1k views
How can I put a curly brace inside an algorithm to group code lines?
I am using the algorithmic package (or even algorithm2e is fine). Is it possible to use curly braces to group some lines in the algorithm so as to be able to put an explanation to the right?
6
votes
3answers
4k views
Change FORALL to FOREACH in algorithms package
\FORALL gives a "for all" loop, i would like to redefine it so that it shows "for each" instead. Any way to do that?
By the way, foreach is more often used in real programming languages than forall, ...
4
votes
1answer
601 views
put two algorithm side by side
I want to put two algorithm side by side to gain place in the document, but when I use \documentclass{llncs} instead of \documentclass{article}, the following code does not work (errors):
...
4
votes
1answer
5k views
Algorithm and IEEEtran
I'm trying to write an algorithm in a IEEEtran LaTeX template and it doesn't work in any way.
\usepackage{algorithm}
\usepackage{algorithmc}
%\begin{algorithm}[H]
\begin{algorithm*}
\caption{ASGP ...
4
votes
1answer
3k views
Override \centering to left justify an image
Background
Dozens of source code snippets inserted into a document as images inside of Algorithm floats. Other images are screen captures, inserted as Graphics floats, to make a distinction. All ...
4
votes
2answers
2k views
Customizing “Algorithmic” or generating output of the same style
The algorithmic sample code that I am using is something like this:
\begin{algorithm}[h]
\caption{Caption Here.} \label{alg:Name}
\begin{algorithmic}[1]
\REQUIRE
\ENSURE
...
3
votes
2answers
279 views
algorithmic + babel with Hebrew conflict: Numbering missing
If I use algorithmic with babel, having both Hebrew and English, the line numbers go missing. Using MikTeX 2.9.
\documentclass{article}
\usepackage[hebrew,english]{babel}
\usepackage{algorithm}
...
2
votes
1answer
183 views
Problem with algorithm(ic) and hyperref
The following code works ... fine!
\documentclass{book}
% \usepackage{subfig}
% \usepackage{subcaption}
\usepackage[colorlinks]{hyperref}
\usepackage{algorithm}
\usepackage[noend]{algorithmic}
...
2
votes
2answers
2k views
Disable the numbering of algorithms
My problem is that I do not know how to disable the numbering for algorithms. I have created an algoritm and its number is "Algorithm 1", but I want to have "Algorithm".
\documentclass{article}
...
8
votes
1answer
1k views
IEEE-Template: Algorithm over both columns
I'm currently working on a paper using the IEEEtran template. I do have a pseudocode I would like to put into this paper. In a former paper I saw that it is possible to put this algorithm in a box ...
5
votes
1answer
393 views
Add algorithm label to list of algorithms
I'm using the classicthesis package along with the algorithmic package.
I'm trying to get the list of algorithms to look the same as the list of figures/tables etc., but cant find a way to make it ...
4
votes
1answer
239 views
Modify Algorithm name in French
This is my code:
\usepackage[section]{algorithm}
\usepackage{algorithmic}
\begin{document}
\makeatletter\renewcommand{\ALG@name}{Algorithme}
\renewcommand{\listalgorithmname}{Liste des \ALG@name ...
4
votes
2answers
2k views
algorithm package: Comment on “for” loop does not work?
It seems that \COMMENT in the algorithm package is broken. It gives an error when used in a FOR or FORALL line, so the first comment gives a compilation error:
\begin{algorithm}[ht]
\caption{My ...
3
votes
1answer
106 views
Add the word “Algorithm” before each entry in the List of Algorithms
I'm trying to add the word "Algorithm" before each entry in the List of Algorithms (because of unavoidable thesis guidelines).
I saw similar questions but the solutions listed there don't work for ...
2
votes
1answer
85 views
No italics in algorithm2e if-clause
Why does algorithm2e typeset the variables anychange and done in italics, and how can I turn this off? How can I remove the semicolon after done in the until-clause?
$\textsf{anychange} \gets ...
2
votes
1answer
104 views
algorithmic package, get rid of algorithms numbers
My question is about algorithmic package.
I have an algorithm which I called A1.
\begin{algorithm}
\caption{\bf A1:}
\label{algorithm-A1}
...
I have something like this:
Algorithm 1 A1
How can ...
2
votes
1answer
3k views
Customizing the algorithm/algpseudocode package
After asking this question: Change FORALL to FOREACH in algorithms package, some issues arose in the comments. I have created the following sample document, and have three questions.
...
2
votes
1answer
2k views
Adjust spacing of algorithm float caption
Background
Using the algorithm package to display source code listings.
Problem
The LaTeX (LyX) code (test.lyx) is at: http://pastebin.com/QRWDhA7E
An example graphics (query.png) file is at: ...
1
vote
1answer
88 views
Increase Spacing in an algorithm
Please, how can i increase spacing in an algorithm, between instruction 1 et instruction 2 ?
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}[H]
\caption{My ...