{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
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
41 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
163 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
96 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
32 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
36 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
2answers
51 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 ...
2
votes
1answer
25 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. ...
84
votes
5answers
61k 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
29 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
24 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
66 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
22 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
64 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
45 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
28 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
36 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
2k 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
42 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 ...
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
1answer
35 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
45 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
139 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
16 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
29 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
163 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.
3
votes
1answer
116 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
43 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{...
1
vote
0answers
69 views

No algpseudocode-package in TeXstudio

I am using TeXstudio for writing my thesis. I am tying to use the algpseudocode-package, but it says that the package isn't found. Here is the screenshot of the error that I am getting:
0
votes
0answers
38 views

footnotes just after algorithm

I am trying to add footnotes at the end of an algorithm environment (not at the end of the page). I found this post where this is done but there are no numbers to refer to the footnote. So if I want ...
1
vote
0answers
9 views

alignment within algorithm environment [duplicate]

I would like to align some statements so that it's more pleasing to the eye. I have the following code, where the first version the two statements are not aligned. I use \phantom to force alignment ...
2
votes
1answer
36 views

sub-algorithms using algorithmic, part a part b

I am currently displaying algorithms in a sequence 1-9. Now I have for example algorithm 7 and I would like to name it algorithm 7a and the next one will be algorithm 7b and then algorithm 8 again. ...
5
votes
1answer
13k views

Subroutine in algorithm2e

I am looking for a tiny example of writing in algorithm2e an algorithm using a subroutine. The algorithm is called algo, and it recursively calls a subroutine called proc. It should be something like ...
1
vote
0answers
72 views

Multiple conditions in a “If” algorithm

I've done a lot of searching in google but not found any answer to my question. I'm searching for a way to write this in latex : if ( (t<-3) || ((s>4)&&(t<3)&&(tendency>-3)...
2
votes
1answer
30 views

How to remove the tab from the listofalgorithms (ToA)

How can I remove the tab from the \listofalgorithms so that it always starts without indent? \documentclass[12pt,a4paper,twoside]{book} \usepackage{algorithm} \usepackage{algorithmic} \begin{...
3
votes
1answer
59 views

How do I rename “Data” (from \KwData{}) and “Result” (from \KwResult{}) in \begin{algorithm} to something else?

Say I have the following code: \begin{algorithm} \KwData{my data} \KwResult{my output} my algorithm \caption{my caption} \end{algorithm} It will produce something like this: Algorithm 1: my ...
2
votes
1answer
53 views

If algorithm in Latex

I want to create a simple algorithm in my latex document. I have a variable which comes to my latex template from the web-form it can have just two values "yes" or "no", so in case if this value "yes" ...
7
votes
1answer
895 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 ...
3
votes
2answers
110 views

Ampersand symbol algorithm environment

How to make a "normal" looking ampersand symbol within the algorithm environment? I'm using \& but this results in a strange looking character as shown below: Here is a minimal example how I ...
0
votes
0answers
24 views

Change the format of an algorithm from a table to any algorithm typesetting

I have been struggling to format the pseudocode of my algorithm from the current state (in a table) to the one provided by the algorithm package. After several tries with answers like: one, another, ...
0
votes
2answers
61 views

Pseudo code for this algorithm

I am new to LaTeX ... I have searched many examples of algo pseudocode for this type of code.I don't know which package to use to write this algorithm. Please help me with the code.
7
votes
2answers
2k 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 ...
2
votes
1answer
66 views

Symbols between figures

I would like to add symbols between Figures Figure 1 + Figure 2 ---> Figure 3 Please redirect on how it can be achieved.
3
votes
1answer
33 views

SetKwInOut error

I'm having some problems with the algorithm2e package. Here's the code: \begin{algorithm} \caption{Tree merge algorithm\label{alg:merge}} \SetKwData{H}{H}\SetKwData{M}{M}\SetKwData{C}{C}\...