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

14
votes
3answers
544 views

How can I typeset an algorithm with columns as in CLRS (Introduction to Algorithms)?

In Introduction to Algorithms, by Thomas Cormen, there are some algorithm like in this image. With one column for the code, one for the cost and one for the times. I searched a lot, but I didn't ...
3
votes
0answers
52 views

How do you restate an algorithm?

I'm trying to restate/repeat/recall an algorithm in an appendix with the same numbering, etc., but I haven't found an easy way to do it. I'm using the algorithm environment and algorithm2e package. ...
1
vote
0answers
13 views

Fixing position for Algorithm2e does not work

I have the following minimal example. When I compile this, the result is fine, as expected. \documentclass[ngerman,12pt,a4paper]{report} \usepackage[left=2cm,right=2cm]{geometry} \usepackage{...
6
votes
1answer
4k views

How to insert algorithm pseudocode in Lyx?

recently I found LyX is good for writing notes. But I don't know how to add a piece of algorithm pseudocode in Lyx environment. Could you please help give some advice? Thanks! How could I implement ...
4
votes
3answers
1k views

break an long line in an algorithm

I have a long line in an algorithm and want to break it into two lines. For similar case in equations, split can be used. How do I do this within an algorithm? \documentclass{article} \usepackage{...
1
vote
3answers
546 views

Aligning Equations in LaTeX

I was trying to align the following equations but alas. Could someone guide? \begin{flalign} x \in A \cap (B \cup C) & \Rightarrow (x \in A) \lambda \Big( (x \in B)\vee(x \in C) \Big) & \\ &...
0
votes
0answers
19 views

Reporting an algorithmic step [closed]

I have an multi-step algorithm, where one of the steps would involve eliminating certain columns from a matrix. Imagine a matrix of 300 columns and I intend to remove 9 columns that would create a new ...
2
votes
1answer
41 views

Pseudo code errors in LaTeX

Can you correct my code plz ? \documentclass{article} \usepackage{amsmath} \usepackage{algorithm} \usepackage[noend]{algpseudocode} \begin{document} \begin{algorithm} \caption{Algorithme Branch \&...
-1
votes
0answers
35 views

Pseudo-code in latex

Could you help me to write this pseudo-code in latex please? Thank you
0
votes
0answers
20 views

Algorithm package, make the pseudo code span multiple pages

Is there a way to make the \begin{algorithm} \begin{algorithmic} ... \end{algorithmic}\end{algorithm} span multiple pages? Also is there an optional command perhaps after \begin{algorithm} to make ...
2
votes
1answer
39 views

Inserting caption on an algorithm in Beamer

I am trying to insert the caption on an algorithm in beamer presentation. The algorithm syntax is correct and it is working while using \documentclass{article} but it shows following error when \...
2
votes
1answer
562 views

Line break inside procedure's definition with algorithmicx

I don't know if this package is the best for my purpose, but I'm using algorithmicx (see here the documentation) to write algorithms (in pseudcode) inside my work. At now, I've just a problem: input-...
0
votes
1answer
31 views

Indentations in Algorithm floats in LYX [closed]

I am using LYX and I'm trying to enter algorithms in an algorithm float. Is there a way to have indentation?
1
vote
0answers
25 views

Combine Pre-existing Independent Documents that Use Algorithmicx and Algorithm2e?

I have a few relatively substantive pre-written documents that need to be combined together into one. Each document contains a lot of pseudocode. The complicating factor is that two documents use ...
1
vote
1answer
20 views

Using `\State` inside `beamercolorbox` causes error Missing \endcsname inserted

I have a frame in my beamer presentation. Inside a frame I have an algorithmic in a minipage. Inside that algorithmic I have the following to highlight an ares in the algorithm. \documentclass[11pt]{...
0
votes
0answers
31 views

Error: Caption outside float inside algorithm

The title suggests that this question has already been answered, but none of the similar questions that I browsed through solve my issue. The following is the contents of my algorithm.tex file : \...
2
votes
2answers
61 views

Help with algorithm2e formatting

recentely I've got into a bit more advanced LaTeX formatting, i.e algorithms. My package of choice is the algorithm2e package, but I'm having some difficulities operating it. So I've wanted to create ...
3
votes
1answer
29 views

algorithm2e command \procedure already defined

I included algorithm2e and start getting error message of "algorithm2e.sty command\procedure already defined." Here are the list of packages in my latex file \documentclass[useAMS,usenatbib]{coin.cls}...
1
vote
0answers
12 views

How to produce an extract of an algorithm using algorithmicx?

Having an algorithm written with the package algorithmicx, I'd like to rewrite two (single) lines in a later section of my document. However, if possible, I'd prefer not to write the complete ...
4
votes
2answers
44 views

How to fit an algorithm into a template?

My aim is to fit this long single-line algorithm into a double column page lay out, just as it is shown in the below, in 3 different lines, but I cannot use \State and I do not know why and how can I ...
6
votes
1answer
171 views

Algorithms and amsart

Basically, I have copied the code from an answer to this quesiton, for I have to translate some words. I have only changed documentclass from article to amsart. \documentclass[11pt]{amsart} \...
2
votes
2answers
106 views

Can I remove the word “algorithm” from the header and keep only the caption,also I “want for loop” to be indented after step 3

\begin{algorithm}[h] \begin{algorithmic} \caption{Math algorithm} \STATE \textbf {Step 1} $\rightarrow $ gather the data \STATE \textbf {Step 2} $\rightarrow $ estimate matrix \STATE \textbf {Step ...
11
votes
4answers
20k 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, ...
3
votes
1answer
47 views

autoref for algorithms

\usepackage{algorithm,algpseudocode} \usepackage{hyperref} So when I \begin{algorithm} \caption{Baseline}\label{ALG_baseline} \begin{algorithmic}[1] ... \end{algorithmic} \end{algorithm} the ...
1
vote
0answers
39 views

How to write an algorithm as a column inside the table

Let us consider the following code and the algorithm corresponding to it \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[]{algorithm2e} \begin{document} \begin{center} ...
2
votes
1answer
27 views

Not A Member sign in math mode in algorithm2e

For the below algorithm, i get the erorr ! Extra }, or forgotten $. \egroup l.759 } I think having another prantes in the if condition is also another problem, that I do not know how to cope with. ...
85
votes
5answers
62k 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 ...
18
votes
2answers
8k 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 ...
2
votes
1answer
37 views

How to reinitialize the lines counter for algorithms?

I have four algorithms in a section but the problem is that the lines numbering doesn't start with 1 in each algorithm. For example, the first one is numbered from 1 to 11 but the second one start ...
1
vote
1answer
27 views

how to write algorithm in latex?

I want to write this algorithm: for(i=0;i<nbOfPedCurr;i++){ for(j=0;j<nbOfPedPrev;j++){ int idCurr=idCurrentFrame; int idPrev=idPrevFrame; if(idCurr==idPrev){ CurrObj=...
2
votes
2answers
69 views

how to insert protocol in Lyx?

I know how to insert "algorithm" in Lyx. But how to insert "protocol" as shown in the following figure?
2
votes
1answer
25 views

How to put left aligned equation inside algorithmic

I have a one-line equation that I want to use just like a statement in algorithmic. I tried with flalign and the equation still goes into the center. Could you please tell me how to fix that? Here is ...
2
votes
2answers
72 views

list of algorithms with tufte-book

The following MWE produces a "List of Algorithms" heading but no list below it. \documentclass[a4paper,twoside,justified,marginals=raggedright,nofonts,nobib,]{tufte-book} \RequirePackage[noend]{...
1
vote
0answers
27 views

Unrecognized command in Algo, but the code can be compiled [duplicate]

I use Texstudio. I have installed package algorithm and algpseudocode. The unrecognized command are all marked in red, but they can be complied. I want to know, why this problem appears and how to ...
8
votes
2answers
6k 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} \begin{...
0
votes
1answer
46 views

List of algorithms not working with amsbook document class

I am using \listofalgorithms in a document with \documentclass{amsbook}. It seems the two clash for some reason. When I run pdflatex, I get the following error message: (./main.loa ! Undefined ...
0
votes
0answers
29 views

No compilation errors but my pseudocode is not visible in the pdf file. I am using a two-column template

Are some packages incompatible with some templates? I am trying to write pseudocode using the algorithm/algorithm2e package. I am using a template downloaded from a latex templates website. http://www....
1
vote
1answer
38 views

Insert indent in algorithm at line break of the same \State

I have the following code: \documentclass[12pt,a4paper,twoside]{book} \usepackage{graphicx} \usepackage{algorithm} \usepackage{algpseudocode} \begin{document} \begin{algorithm*}[t!] \caption{...
4
votes
2answers
3k views

Write Procedure Name correctly formated in algorithm environment

I want to call a function in an algorithm environment. \documentclass{article} \usepackage{algorithm} \usepackage{algpseudocode} \begin{document} \begin{algorithm} \caption{Recursion} \begin{...
3
votes
1answer
44 views

Make listing a floating image

I have used the listings package for including a program into a LaTeX document. But the program splits into two when a page is finished. I want to make the listing behaved like an image, so that it ...
1
vote
1answer
37 views

Cases inside an algorithm environment

I need to write an algorithm where multiple cases are handled. I have succeeded but the output shows a lot of vertical space below and above the cases statement. Anyone help me to fix this. I am using ...
9
votes
2answers
4k views

Vertical loop/block lines in algorithmicx with 'noend' option

I am using the algorithmicx package to write an algorithm. However I am using the noend option: \usepackage[noend]{algpseudocode} Is there anyway to get vertical lines for each block of code? This ...
0
votes
0answers
49 views

Formatting an algorithm with a nice presentation

I was reading this paper and I think is really nice the format how they present the algorithms, how can I do this? what packages are needed and the styles. Thanks in advance.
4
votes
2answers
140 views

Writing results of some code

I am doing some homework on Newton's method and would like to display results after five (or so) iterations. I was hoping for something along the lines of > 0.001 > 0.011 > 0.111 > 0.111 &...
0
votes
0answers
17 views

How to add line numbers to my Algorithm in Latex

I am writing an algorithm in LaTeX. I am already using the following packages for algorithms: \usepackage{algorithmic} \usepackage{algorithm} \usepackage{amsmath} i am also using the \STATE tag. i ...
0
votes
0answers
32 views

How to write the algorithm with bold keywords and line numbers

I wish to write an algorithm like the following, with keywords bold and line numbers in each line. Could someone help on how to use latex to write this kind of algorithms?
1
vote
0answers
174 views

Genetic Algorithm pseudocode [closed]

Hi everyone, this is my first post, so apologise if not doing it properly. I need the following GA pseudocode (Photo) in LaTex, but couldn't do it very well. I really appreciate your help.
4
votes
1answer
119 views

Collecting algorithm captions in WinEdt

I've installed the add-on Figures&Tables in WinEdt, which lets me collect table and figure captions in WinEdt's Tree. I would like to be able to collect algorithm captions, as well. With the ...
0
votes
1answer
46 views

Write down the algorithm

I am trying to write down my algorithm and faked I wrote Foreach loop. Otherwise there is no command \Foreach. The followingmy program could not be executed. Also I use package \usepackage{...
1
vote
0answers
14 views

Getting Error in writing algorithm in latex

I am facing error saying "! Missing number, treated as zero.\ALG@b@2@ELSE@0 \ELSE" in writing the following algorithm in Latex.I can't understand what is the problem. \begin{algorithm}[H] \caption{...