{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.
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 ...
25
votes
2answers
761 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 ...
14
votes
4answers
16k views
How to install the algorithms package?
According to my ubuntu 11.04 my texlive is the latest version. But when I tried to \usepackage{algorithm} it says file algorithm.sty is not found. I read the algorithm.pdf manual and tried latex ...
13
votes
2answers
858 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 ...
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}
...
12
votes
1answer
972 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:
...
10
votes
4answers
354 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.
9
votes
2answers
596 views
Coloring lines in an algorithm
I am using Beamer for creating a presentation and I am trying to highlight some lines in an algorithm. I am actually using algcompatible.
I found a solution here and created a couple of new commands ...
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 ...
8
votes
1answer
1k views
algorithm numbering
I am having trouble numbering and referencing algorithms.
I want to have the references labeled by the chapter, then within the chapter, such as:
First algorithm in chapter 1 - Algorithm 1.1
...
8
votes
1answer
926 views
Change Indentation Size in algorithmicx package
I'm using and enjoying the algorithmicx package, but would like to adjust the size of its indentations.
In the algorithms package, I could do this with \algsetup{indent=1em}, but that doesn't seem to ...
8
votes
2answers
499 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
2answers
2k views
IEEEtrans template requires not to use algorithm package?
During the IEEEtrans.tex, there is a comment below package algorithmic saying that
Do NOT use the algorithm
floating environment provided by algorithm.sty (by the same authors) or
...
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 ...
8
votes
1answer
2k views
Algorithm spanning more than one page
I have an algorithm which is too long to fit on one page. Someone suggested splitting the algortithm manually and then altering the second algorithm's line numbers to follow on the first. I know ...
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 ...
8
votes
1answer
803 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 ...
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
290 views
How to compile pseudocode into pdf without margins?
I want to compile a pseudocode for an algorithm into a separate pdf and then include it into my main document as a figure. However, the compiled pseudocode gets compiled into a pdf with margins and I ...
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?
7
votes
2answers
758 views
Which package to use for writing algorithms?
I am looking for a package that will allow me to write pseudocode
of algorithms. The pseudocode may include mathematical symbols, like
\forall, \in and subscripts. But I would like also to "talk" ...
7
votes
1answer
157 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}
...
7
votes
1answer
686 views
How to print in algorithmic package for some If condition or For loop in one line?
How to print
\FOR{$j:=0,\ldots,i-1$}
\STATE{$\C_{ij}:=\C_{ii}\cdot\C_{ij}$};
\ENDFOR
in one line instead of two line?
7
votes
1answer
243 views
What is the best looking pseudo code package?
I have stumbled across various pseudo code packages but can't seem to find that's simple and eye-candy and practical.
What I'm looking for:
Visually attractive structure (eye-candy) ( easy to look ...
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 ...
6
votes
2answers
423 views
How do I create an algorithmic Tikz code to obtain a list of numbers which is conditionaly defined by a recurence relation?
Suppose, our initials are $a_{1,0}=0$, $a_{1,1}=1$ and $a_{1,j}=0$ for $j<0$. For given an integer $n$, define
$$a_{i,j}=\begin{cases} a_{i-1,\frac{j}{2}} & \text{ if $j$ is even},\\
...
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 ...
6
votes
2answers
2k views
Number Algorithm floats with dependency (subalgorithms environment)
What I have: 3 algorithms, like so:
\begin{algorithm}
\caption{Caption One}
...
\label{alg:one}
\end{algorithm}
\begin{algorithm}
\caption{Caption Two}
...
\label{alg:two}
\end{algorithm}
...
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, ...
6
votes
1answer
88 views
How to prevent indent on \listofalgorithms?
How can I prevent the \listofalgorithms from being indented? I tried everything I could find on the internet, but the index of my algorithms refused to be aligned along with the title.
Here is a MWE:
...
6
votes
1answer
716 views
Algorithms package ignores caption package
I'm using the algorithms package in my document to get a floating environment for algorithms to live in.
\usepackage{algorithm}
I'm using the caption package to make the captions on my figures ...
6
votes
1answer
178 views
algorithmic, arbitrary names for algorithms
The question is advanced version of my previous one.
I need to name algorithms (package algorithmic) with arbitrary names so it appears like:
Algorithm MyAlgo
and \ref{...} will appear like MyAlgo.
...
6
votes
1answer
372 views
Adjust the indentation whithin the algorithmicx-package when a line is broken
I have this code
\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Minimal Working Example for my Problem}
...
6
votes
1answer
1k views
algpseudocode font size
I want to change the default font size of the algorithm in algpseudocode environment to small. This is because my algorithm is lengthy and i have page limitations. Please help
6
votes
1answer
6k views
including algorithms in latex
I am using the
\usepackage{algpseudocode}
\usepackage{algorithm}
packages and creating a sample algorithm using the \COMMENT, \IF, \ENDIF and \FOR constructs. When I compile this and view the PDF ...
6
votes
1answer
1k views
Hide closing statements for algorithms
I would like to generate an algorithm with the algorithmic package which does not show the annoying closing statements when I typeset it. I have done this before but have now forgotten how to do it. ...
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:
...
5
votes
1answer
5k views
How to put a line number every line of algorithmic
I am looking for a way to have a number for every line in algorithmic:
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}
...
5
votes
5answers
2k views
Aligning pseudocode in LaTeX
My algorithms class is following strict guidelines for pseudocode. Let's say I have something like the following:
y = 0
for i = n downto 0
y = a_i + x * y
I want this to appear left-aligned on ...
5
votes
2answers
7k views
How to use algorithmicx package?
I found the algorithmicx package on this page, and tried to compile this example from the pdf file.
\documentclass{article}
\usepackage{algorithmicx}
\begin{document}
\begin{algorithm}
...
5
votes
1answer
2k views
Adding comments to pseudocode
I would like to find a pseudocode package that support the possibility to wrote a comment at the right side of a if and that it wont be between { } but rather at the right side of the page, after a ...
5
votes
2answers
294 views
Can't manage to use algorithm packages
I'm trying to write some simple pseudocode but I just can't get it to work. It's pseudocode from another paper and I want to change it a little and put it in my paper.
This is the pseudocode I want ...
5
votes
1answer
210 views
Package Algorithmic in French
I use
\usepackage[section]{algorithm}
\usepackage{algorithmic}
to create an algorithm, I'd like to change "algorithm, begin, end while ..." to French. Is that possible?
This is my example with ...
5
votes
1answer
324 views
How can I translate keywords of algorithmic package?
How do I translate standard keywords of the algorithmic package like (if, then,...) to my language?
If possible, I would like to do it without looking into source of algorithmic or algorithm.
5
votes
3answers
440 views
Insert white line before algorithm
I am using the algorithm environment to create a simple list of pseudo-code, but I don't like it that the first line is so close to the rule. Therefore, I would like to insert a single white line like ...
5
votes
2answers
175 views
Phantom malfunction in algorithm caption
I am trying to use \phantom in the context of an algorithm caption. I am using the algorithm and algorithmic packages. \phantom will work properly in normal text in my document, but not in a caption. ...
5
votes
1answer
377 views
Creating sub-algorithms in latex using the algorithm package
I want to do something like this (see image below)
where I can describe my algorithm in smaller steps or "phases" as this person calls them. I've used the algorithm and algorithmic package before but ...
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 ...
5
votes
1answer
2k views
Floating an algorithm?
I'm typesetting an algorithm using the algorithmx package as follows:
\begin{algorithm}
\caption{\textsc{Whatever}}
\begin{algorithmic}[1]
...
\end{algorithm}
However, I would like it to ...
5
votes
1answer
931 views
How do I define a new command in algorithmicx
The algorithmicx package defines two commands \Require and \Ensure for providing initial conditions. However, I'd like some custom commands such as \Assume, \Define, \Input, etc. At present, I merely ...
