{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
16 views

\ref to algorithm/algorithmic not working [duplicate]

I am trying to reference an algorithm in my thesis, made using the algorithmicx and algorithm packages, but it fails, ending up with the dreaded ?? and the following error: LaTeX Warning: Reference ...
2
votes
0answers
23 views

Using special characters with lstlisting

I am using the Algorithm2e package to use code in my LaTeX document. However, the code contains special characters such as à, é, è etc. Those characters causes errors such as Unicode character x not ...
4
votes
2answers
72 views

Algorithm environment problem

I am doing my master thesis and need to include an algorithm into my LaTeX code. I have been trying for hours now, but I still have several errors that always show up. It is my first time using the ...
5
votes
1answer
72 views

Algorithms and amsart

Basically, I have copied the code from answer to this quesiton, for I have to translate some words. I have only changed documentclass from article to amsart. \documentclass[11pt]{amsart} ...
0
votes
1answer
24 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?
0
votes
0answers
10 views

How to write “for” block with counter by Algorithmic package

How can I write a code like below using algorithmic package for (int i = 0; i < node.children; ++i) ..... I can't use foreach or forall because in a point inside the loop I should decrement i ...
0
votes
0answers
13 views

How can I include specific lines of pseudocode from a file?

In my document, I use the listings package to include listings from separate files: \lstinputlisting[firstline=6, lastline=11, firstnumber=6]{myprogram.c} (This shows the lines 6 to 11 from the ...
1
vote
2answers
75 views

Reproduce neat Algorithm Style

I've seen this nice algorithm sytle in Stachurski (2009), "Economic Dynamics", p.74. Does someone know what package, environment or settings he used?
1
vote
1answer
29 views

how remove space before algorithm (caused by layout)

i'm not an expert of latex and i can't solve the following problem. I have a long algorithm and this occupies an entire column, the problem is that compiler add a blank space before it, and i need ...
2
votes
1answer
27 views

How to put a custom tag to the algorithm environment?

I am trying a way to number algorithms 1a, 1b, 1c, 2a, 2b, 2c, etc. As I understand from the documentation of the algorithms package here, I can number them after the part, chapter, section and so on. ...
0
votes
1answer
33 views

Algorithmic in Latex

I want to write: {Step 6 for n = 0 to final do y(n) = x(n) e(k) = d(k) 􀀀 y(k) w(n + 1) = w(n) + x(n)e(n) end for} My problem is for appears in the start without identation.
1
vote
1answer
18 views

Replace “Algorithm” in algorithm package

I use the latex package algorithm. I would like the name of my algorithm ("Algorithm 1.1") to be change to the french version ("Algorithme 1.1") in the compiled pdf document. How could I do that? ...
1
vote
0answers
32 views

Error with algorithm and algorithmic packages

I have the following problem that involves the algorithm and algorithmic packages with the garamondx font. This is a minimal example: \documentclass[letterpapet,10pt]{article} \usepackage{garamondx} ...
1
vote
1answer
42 views

Algorithm nested for loops generate a blank line

%!TEX program = xelatex \documentclass{article} \usepackage{algorithm} \usepackage{algorithmic} \begin{document} \begin{algorithm}[] \caption{LDA} \begin{algorithmic}[1] \FOR{$d$} \STATE{ ...
1
vote
1answer
17 views

How to put two algorithm2e (one is large and one is small) side by side by using minipage or subfigure?

I have two algorithms wrote by the algorithm2e package. One of them is large and the other is small. My try is here: %\documentclass[runningheads,a4paper]{llncs} \documentclass{article} ...
1
vote
1answer
77 views

writing algorithm in a table

I want to write an algorithm such that what I have attached, I am somehow elementary in writing algorithms with latex. I do not want the exact answer, only a tip or an example similar to what I have ...
5
votes
2answers
50 views

Share counter between amsthm and algorithm

I am using amsthm \usepackage{amsthm} \newtheorem{thm}{Theorem}[chapter] \newtheorem{lem}[thm]{Lemma} \newtheorem{prop}[thm]{Proposition} and algorithm \usepackage{algorithm, algpseudocode} ...
0
votes
0answers
14 views

Algorithm formatting

\begin{algorithmic} \For{$i,j\gets 0, 255$} \State $j\gets (j + key [i mod keylen] + S[i] ) mod 256$ \EndFor \end{algorithmic} I want to print j= (j + key [i mod keylen]+s[i]) mod 256 My code ...
1
vote
1answer
43 views

Comment in algorithmic on a line beginning with if, and using uncover/visible

I am trying to modify this code, into the following one : \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage[plain]{algorithm} \usepackage{algorithmic} ...
5
votes
2answers
50 views

How to format line in algorithm

I use ACM conference paper template (Two columns) to write paper. The problems bug me for a long time about Algorithms format: The function name always converted to UPPERCASE. Larger blank between ...
2
votes
1answer
95 views

Table of contents of algorithm and algorithm2e together

The contents of the algorithms thinks that an algorithm that uses algorithm is one algorithm and an algorithm that uses algorithm2e is another algorithm, not the second of what was imported with the ...
0
votes
0answers
19 views

why \end{algorithmic} ends with =0? [duplicate]

I wrote some algorithms using pseudocode, but when compiling the document, each algorithm ends with =0 (at line\end{algorithmic}). What I have to do to avoid this problem?
14
votes
2answers
145 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 ...
4
votes
1answer
45 views

Algorithm environment, defining a custom style

I'm currently using the following mwe \documentclass{article} \usepackage{algpseudocode} \usepackage[plain]{algorithm} \begin{document} \begin{algorithm}[H] \hrule \vspace{0.5em} \caption{Euclide's ...
2
votes
1answer
55 views

How to make listofalgorithms behave like a section, not a chapter?

I have a problem. I included the following: \documentclass[a4paper,11pt,reqno]{book} \usepackage{algorithm} \usepackage{algorithmicx} \usepackage[noend]{algpseudocode} and wanted to create a ...
3
votes
1answer
36 views

Set linespread in algorithm environements

My algorithms are really complicated and I want to \onehalfspace their lines to make them more readable, while keeping the rest of the document singlespace. How can I do this so it will automatically ...
2
votes
2answers
158 views

Multiline statements and conditions in algorithm environment

I have an algorithm that I want to write in mathematical pseudo-code. However, some conditions and statements are very long, e.g. "if (a series of relations and constraints hold) do" or "X gets (a ...
0
votes
0answers
13 views

Linebreak with algorithm environment in two column mode [duplicate]

I want to integrate an algorithm in a two column article, but I'm not happy with the output (screenshot below). I'm wondering why the algorithm environment don't break the code and go on the next ...
4
votes
1answer
49 views

Counter not incrementing when defining crefname with cleveref and algpseudocode

I am renaming the "line" label for lines in the algorithmic environment, since I am using the default label for lstlisting environment. As soon as I add define \crefname for it, the counter does not ...
4
votes
1answer
93 views

End word is hidden in algorithm block

Suppose that i have this code: \usepackage[ruled,vlined]{algorithm2e} \begin{dcocument} \begin{algorithm}[H] \KwData{this text} \KwResult{how to write algorithm with \LaTeX2e } initialization\; ...
2
votes
1answer
72 views

“and” in algorithm

So I'm not experienced with the algorithm packages in LaTeX. I'm assuming there must be a way to do if condition1 and condition2 then... but I can't find it. I've checked what I can find of the ...
0
votes
0answers
12 views

In algorithm/algpseudocode, when writing long lines within loops how can I adjust the left indentation? [duplicate]

Q: In algorithm/algpseudocode, when writing long lines within loops how can I adjust the left indentation? To illustrate the problem, this is what I have: But this is more like what I want it ...
4
votes
1answer
80 views

Randomizing a given text

It sounds stupid, but it's useful to me. I want to randomize words. To input a text, and to get an output with the same words, in random order. I have no idea how to begin with, though. Therefore I ...
2
votes
1answer
38 views

Maintaining indentation in a long Ensure-block with algorithmicx-package

I have a long "Ensure-block" in my algorithm. How can I force the second line to be exactly under the first "Text"? \documentclass{article} \usepackage{algorithm} \usepackage[noend]{algpseudocode} ...
5
votes
2answers
179 views

Include a line break in algorithm-caption while maintaining indentation

I've a question about the alignment of the caption in an algorithm-environment. For instance, the following code-example \documentclass{article} \usepackage{algorithm} ...
6
votes
1answer
281 views

{Begin End} does not show when writing algorithm in LaTeX

I am writing an algorithm in LaTeX using \usepackage[ruled,vlined]{algorithm2e} When running the code, the produced file does not show the word "end" that should appear automatically when using ...
3
votes
1answer
117 views

Algorithm in RevTex4-1

When I run the attached code I get this error: ************************************ Missing \endcsname inserted. <to be read again> \c@float@type l.23 \end{algorithm} ...
2
votes
1answer
59 views

Changing name of the label Algorithm [duplicate]

When using algorithmx you get "Algorithm 1 algorithm name". How can you change the label "Algorithm"? I do not mean individually for each algorithm, but instead changing it globally the whole latex ...
5
votes
1answer
121 views

Change name of algorithm

I've been trying to use this answer Changing label name for algorithm to no avail. I use the packages: \usepackage{algorithm} \usepackage{algpseudocode} And this code for defining new environment: ...
1
vote
0answers
21 views

Algorithm pseudo code not published beyond one page [duplicate]

My algorithm pseudo code is not being published beyond one page though there is no syntax error. The PDF produced via LaTeX is of only one page but my entire algorithm requires more than one page. So ...
4
votes
3answers
73 views

Spacing issue with algorithmic and eqparbox

I am using the algorithmic package to display code. In order to get flush-right, left aligned comments, I also use the eqparbox package and redefine \algorithmiccomment; see minimal example below. As ...
15
votes
1answer
1k views

algorithm, algorithmic, algorithmicx, algorithm2e, algpseudocode = confused

I am getting confused about the package structure for writing simple "algorithms". There are too many options, and also got totally clueless about when to use what. Is there any definitive guidelines ...
1
vote
0answers
44 views

Too long algorithm

I would like to know how it is to write a long algorithm beyond the edges of a page, knowing I used algorithm and algorithmic packages?
3
votes
1answer
69 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 ...
2
votes
1answer
59 views

Moving caption of the algorithm upwards

I have the following code: \documentclass{scrbook} \usepackage[linesnumbered,ruled]{algorithm2e} \begin{document} AAAA BBBB \begin{algorithm} \vspace*{-1cm} \caption{My Caption\ldots} My ...
1
vote
1answer
54 views

Conflict between image and algorithm style

I'm trying to write an article with both figures and algorithms. The commands related to images should be these: \usepackage{float} \usepackage{graphicx} \usepackage[margin=1.5cm]{caption} ...
3
votes
1answer
64 views

Changing the font of algorithm name in algo.sty

I am using algo.sty to write algorithm in LaTeX. I want that the algorithm names are in \texttt font. I guess I need to change something about the \a@paralgo (from algo.sty) in the below code, but I ...
2
votes
1answer
47 views

redundant number in the border

I have a piece of latex code and I would like to remove the redundant number 1 form top left of the border. How can I do this? \begin{algorithm}[t] \centering \small \resizebox{\linewidth}{!}{ ...
1
vote
0answers
40 views

Creating sub-algorithms

I want to have two algorithms together that I can refer to as 1a and 1b (rather than seperately as Algorithm 1 and 2). So very similar to how subfigures work. Is this possible using any of the ...
4
votes
1answer
100 views

How to write begin and end statement at the top and bottom of algorithm?

How can I write 'begin' and 'end' statement at the top and bottom the following code like this?A sample pseuodcode with begin and end statement Besides using algorithm and algopseudocode package I ...