Tagged Questions

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

1
vote
2answers
1k views

LaTeX Class / Package / Template for programming project report

I'm looking for any useful class or package or style (template) to help me write up a programming project report. I've found many LaTeX tutorials but I found it quite hard to start from scratch.
1
vote
0answers
1k views

Why do I get the error “\caption outside float” with the algorithm / algorithmic package? [closed]

I have an algorithm in my document It looks like this: \begin{algorithm} \caption{Merge Digest: Insert\label{mergeDigestInsert}} \begin{algorithmic}[1] [....algorithm is ...
2
votes
1answer
2k views

Loop conditions in multiple lines using algorithmic package

I am working on a paper in double-column format, and I am using the algorithmic package to typeset my algorithms. One of my while loops' condition is a bit long hence doesn't fit into the column. ...
0
votes
1answer
2k views

Why am I getting this “Missing $ inserted” error in an algorithm figure just like all my other algorithm figures?

I'm writing a paper in LaTeX, and I'm getting a strange "Missing $ inserted" error when I try to compile the paper using pdflatex, but only if it contains the following code. \begin{algorithm*}[tbh] ...
5
votes
1answer
3k views

Wrap text around pseudocode

I use algorithm/algorithmic packages to write some pseudocode. The width of the box spans across the entire page and I was wondering if there is any way to constrain it (since the actual code doesn't ...
3
votes
1answer
452 views

Centering clrscode3e codebox horizontally

How can I center a codebox (from clrscode3e package) horizontally in a document ?
3
votes
1answer
850 views

Strange behavior in smooth pgfplot with sudden changes in the slope

I'm trying to plot some points with sudden changes in the slope. But I get some strange behavior like this: as you can see in the peaks, there is no smoothness in there. However, I think the ...
3
votes
1answer
372 views

Additional separation between require and algorithm

\usepackage{algorithm} \usepackage{algorithmic} ... \begin{algorithm} \caption{A good name} \begin{algorithmic} \REQUIRE something usefull \STATE $i \leftarrow 1$ \end{algorithmic} ...
0
votes
1answer
805 views

Good way to “ensure” a return value

I want to describe an algorithm, which is not changing a given input but it is producing a new element: \documentclass[a4paper, 11pt]{scrbook} \usepackage{algorithm} \usepackage{algorithmic} ... ...
3
votes
1answer
1k views

How to format multiple algorithms so that they appear together

How can I have multiple algorithms be tied together so that they all appear next to each other. Currently LaTeX places the algorithms to far from each other.
3
votes
2answers
2k views

polyglossia and algorithmicx - Missing \endcsname inserted

Trying to compile a simple document using polyglossia with Hebrew as the default language: \documentclass[a4paper]{article} \TeXXeTstate=1 \usepackage{amsmath, amssymb} \usepackage{polyglossia} ...
2
votes
1answer
5k 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 ...
4
votes
4answers
10k views

How do you add a comment to pseudocode in LaTeX?

Is there a special formatting to add comments to code? I mean I want to show comments in pseudocode that I write in LaTeX. this is code // this is comment part (the part that I want) Edit: To be ...
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 ...
4
votes
3answers
1k views

Add a phrase to an existing algorithmic command/environment

I would like to add a new command to an existing environment. The \renewenvironment command does not help a lot since I need to copy and paste the entire environment definition. For an example I ...
17
votes
3answers
8k 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} ...
3
votes
2answers
2k views

Algorithm tag and page break

I'm starting my experiment with LaTeX, i'm writing an article and all that I want is to embed an algorithm inside normal text, this is my code: \documentclass{article} \usepackage{algorithmic} ...
6
votes
2answers
4k 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 ...
7
votes
1answer
369 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 ...
4
votes
3answers
2k 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. ...
35
votes
2answers
3k 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 ...
5
votes
3answers
603 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 ...
4
votes
2answers
505 views

algorithmicx + babel + Hebrew incompatibility

When trying to create any document with babel and algorithmicx, e.g.: \documentclass{article} \usepackage[hebrew,english]{babel} \usepackage{algorithmicx} \begin{document} Hello, world. ...
4
votes
1answer
3k 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 ...
9
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 ...
4
votes
2answers
2k views

How to typeset data structures?

I am using algpseudocode for typesetting my algorithms. However, I am missing support for typesetting data structures, such as structs, classes or similar things. Can algpseudocode or some other ...
5
votes
1answer
2k views

Controlling vertical space within a “tabbing” environment

I'm using the "tabbing" environment to typeset algorithms. Because I'm using math formulas within the algorithms (yes I know about specific packages to do this), the vertical space needs a bit of ...
7
votes
1answer
3k 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 ...
8
votes
1answer
8k 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
2answers
18k 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
2answers
4k views

How do I add a blank line in the algorithmic environment?

I'm trying to learn the algorithmic package for typesetting pseudocode. One problem I'm running into is that I can't figure out how to insert blank lines, to separate blocks of code. The usual \\ or ...
21
votes
5answers
43k 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 ...
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?
1
vote
1answer
348 views

Break line inside \proc?

I'm using clrscode to typeset my algorithms. This package provides the \proc command in order to typeset the name of a procedure with some nice small-caps. In a text paragraph I refer to some ...
6
votes
5answers
5k 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 ...
1
vote
1answer
774 views

new clause in algorithmic package

I want to define a new clause in algorithmic package (sync in my case), so that the code inside that clause would be indented as it was inside a while clause for example. So far I made things work by ...
5
votes
2answers
10k views

Reduce pseudocode font size (not global)

In this example I would like to reduce the pseudocode font size, but only for this slide while keeping the others in the default font size. How can I do that?
0
votes
2answers
2k views

Problems with formatting LaTeX document pseudo code, ending while loops

I am writing a LaTeX document for some pseudo code I have written. I have a bunch of while loops, but the way latex is formatting them, it looks like: while(x) while(y) while(z) whereas I ...
7
votes
2answers
8k 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 ...
0
votes
1answer
708 views

display algorithms side by side

This is what i tried, but i can get the algorithms to display side by side. \begin{minipage}{\textwidth} \centering \begin{minipage}{0.48\textwidth} \centering %\begin{algorithm} ...
2
votes
1answer
2k views

Step numbering in algorithms

Is there an algorithm package that allows one to achieve the style of the algorithms in the book Combinatorial Optimization by Korte and Vygen? I am interested specifically in the numbering of the ...
3
votes
1answer
305 views

Prevent \listofalgorithms from producing blank page

I'm writing my thesis with latex, and there's a chapter in which are described some algorithms using the algorithmicx package. What I want to do is to place an index of algorithms at the very ...
1
vote
1answer
2k views

program, algorithmic packages conflict

I want to use both the program and algorithmic packages in a paper; however, after adding \usepackage{program}, algorithmic is now broken. For a reduced example, \documentclass{article} ...
3
votes
2answers
421 views

How to hyperref a pageref in second half of an algorithm, independent of first half

I'm struggling with something that seems pretty complicated to me, but maybe there's a way better solution already out there. If not, I'd really appreciate any help with getting the following problem ...
3
votes
2answers
331 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} ...
6
votes
2answers
1k views

How to not increment algorithm numbers when using \againframe in beamer

As is known, algorithms and equations in latex are automatically numbered. When using \againframe though, incrementing such number is undesired. How to avoid this? (I still want numbering, but it will ...
1
vote
1answer
3k views

Why does the placement of a \COMMENT in the algorithmic enviroment matter?

I'm using the algorithmic package. When I start off a FORALL with a COMMENT, LaTeX behaves as though I've created an invalid loop body. If I put it as the second line, with a STATE first, all is well. ...
2
votes
2answers
1k views

How to make really pseudo pseudocode

Is there a way to do really casual peudocode in Latex? By casual I mean pseudocode that's more like a list of plain English steps, with occasional conditional/looping operators. I've looked at the ...
2
votes
1answer
334 views

What environment to use in writing functions

I am beginner of LaTeX, and wondering how to write functions or procedures in pseudocode. Is there any existing environment for that?
8
votes
1answer
2k 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?