{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.

learn more… | top users | synonyms (1)

63
votes
5answers
33k 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 ...
32
votes
2answers
2k 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 ...
20
votes
5answers
36k 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 ...
15
votes
1answer
11k 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} ...
15
votes
3answers
7k 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} ...
14
votes
2answers
1k 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 ...
14
votes
1answer
2k 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: ...
13
votes
1answer
2k 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
2answers
1k 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 ...
12
votes
1answer
2k 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?
11
votes
3answers
187 views

Can I locally switch to a 'greedy' justification algorithm?

I'm not optimistic about this since this is a core part of TeX's algorithm, but is there any way to switch to a 'greedy' justification algorithm? That is, instead of working on the paragraph as a ...
11
votes
1answer
4k 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 ...
11
votes
2answers
2k 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?
11
votes
1answer
2k 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 ...
10
votes
4answers
433 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.
10
votes
2answers
4k 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 ...
10
votes
1answer
493 views

Algorithm as figure and without italic and bold formatting?

I want to include an algorithm in my latex document, however without printing most of it in italic and all the keywords in bold font like it's done by default by e.g. the algorithmicx package. I like ...
10
votes
2answers
4k 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 ...
10
votes
1answer
2k 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 ...
10
votes
1answer
975 views

cleveref and algorithm2e

I'm currently working on a document where I was using algorithm+algorithmic along with cleveref. With this everything worked perfectly. Now I had to replace algorithm+algorithmic with algorithm2e. ...
9
votes
2answers
12k views

Write pseudo code in latex

I am trying to write pseudo code in my paper. Here is the snippet and image like what I want. Can some one please help me to format it. \begin{algorithm} \caption{Euclid’s algorithm}\label{euclid} ...
9
votes
3answers
3k 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 ...
9
votes
3answers
9k 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, ...
9
votes
2answers
689 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
4answers
2k 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 ...
8
votes
2answers
2k 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" ...
8
votes
1answer
3k 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
7k 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} ...
8
votes
1answer
525 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} ...
8
votes
1answer
3k 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
7k 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
1k 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} ...
8
votes
1answer
1k 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?
8
votes
1answer
80 views

Suppress line numbers in front of 'repeat' and 'until' keywords in algorithmic

Here is my minimal example: \documentclass{article} \usepackage{algorithm} \usepackage{algorithmic} \begin{document} \begin{algorithm} \caption{Test} \begin{algorithmic}[1] \REQUIRE ...
8
votes
1answer
2k views

Translate “Algorithm” in the caption

This is my code \begin{algorithm} \caption{Funkcija ACO} \label{alg:aco} \begin{algorithmic} \STATE{do something} \end{algorithmic} \end{algorithm} it produces a caption like this ...
8
votes
1answer
5k 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? ...
8
votes
2answers
270 views

How to automatically keep the indentation level when a line has to be broken

I'm using the algpseudocode package with two custom commands, \Let and \LongState to handle automatic indentation of (broken) long lines in the spirit of Werner's answer, which uses \parbox to wrap ...
8
votes
1answer
4k 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 ...
7
votes
1answer
10k 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 ...
7
votes
1answer
353 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
3k views

Commands argmin and argmax in algorithm

I am trying to use the argmin and the argmax commands that I defined in an algorithm but I keep getting the argument not in the middle but on the right. Does anyone have an idea how to put the ...
7
votes
1answer
4k views

Referencing line numbers in an algorithm

Referencing figures is simple: \begin{figure} \caption{Blah blah blah blah blah} \label{fig:name} %shtuff goes here \end{figure} See figure~\ref{fig:name}. I would like to know if it ...
7
votes
2answers
15k 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} ...
7
votes
3answers
6k 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 ...
7
votes
1answer
2k 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 ...
7
votes
1answer
82 views

How to remove end-if in algorithms

I am writing an algorithm in latex, but there are lots of end-if and end-whiles in my algorithms which makes it un-professional and ugly. Is there a way to remove them from output of latex? ...
7
votes
2answers
1k views

algorithm2e Command \algorithm already defined

I want to draw vertical line by using \SetAlgoLined, but LaTeX told me Undefined control sequence. Then I add \usepackage{algorithm2e} to the end of my preamble. Then it said Command\algorithmalready ...
7
votes
1answer
2k 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. ...
7
votes
2answers
77 views

algorithm with partial borders/frames

I use the algorithm float environment for pseudocode and want some algorithms to span two pages. That works fine with \algstore and \algrestore. However, I would like to omit these borders at the end ...
7
votes
1answer
1k 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. ...