Questions tagged [algorithmic]

algorithmic is an environment for typesetting {algorithms}.

Filter by
Sorted by
Tagged with
195
votes
1answer
107k views

algorithm, algorithmic, algorithmicx, algorithm2e, algpseudocode = confused

I am confused about the packages for writing simple "algorithms". There are too many options, and it is confusing when to use what. For example, if I use algpseudocode, then I can't add algorithmic ...
42
votes
1answer
143k views

ELSE IF in algoritmic package

Is there a command in algorithmic package which is similar to \ElsIf in algorithmicx? ( I do not want each nested if to be indented).
15
votes
2answers
23k views

Unnumbered lines in algorithm

My question is similar to this one, I need to skip number for some lines of the algorithm. However the solution from that question does not work for me. How can I disable numbers for some lines using ...
13
votes
2answers
28k views

“For” loop without “do”; “if” statement without “then”

How can I get rid of the do in a for loop and the then in an if statement when typesetting algorithms using the algorithm and algorithmicx packages?
11
votes
2answers
33k views

Algorithm in IEEE format

I want to type an algorithm in ieee format. I have used algorithmic package. But using that package, I couldn't type a caption to the algorithm and "Algorithm " above the written algorithm. What ...
11
votes
2answers
42k views

Pseudocode: \Function vs. \Procedure?

The title says it all. What is the difference between a Function and a Procedure? When should I use which?
11
votes
1answer
31k views

Undefined control sequence \State \For \While

I am trying to write a pseudo code in MiKTeX. I have used \usepackage{algorithm} \usepackage{algorithmic} but I get: Undefined control sequence' for every structure (\State, \While, \For, \If). \...
10
votes
1answer
10k views

Placing a single algorithm in two columns

I have a single-column document and to save space I would like to make a long algorithm (produced using packages algorithm and algorithmic) to be double-column. That is, I would like the float content ...
10
votes
1answer
12k views

comment in algorithmic on a line beginning with if

I'm working with algorithmic to create some pseudo-code with comments. With a macro found on this site (see header), comments will be aligned on the right, which is wonderful. However, I don't get it ...
8
votes
3answers
13k views

Use algorithmic in LyX

I'm used to using the algorithmic package in LaTeX, but don't see an easy way to use it in LyX. I even tried this, but it didn't work. Further, it required me to change my document type, which is a ...
8
votes
1answer
11k views

Algorithmic: Put If and EndIf into same line

I use the algorithmic package to create a pseudo-code-source in latex. I have a source with many short if-statements. The fact that the END (from EndIf) is put in a new line every time leads to a ...
8
votes
2answers
2k views

How to indent a long sentence in an algorithm

In this algorithm format I want the the "Considering the jth...." to be having the same indentation throughout even in newline. The Code is as follows: \documentclass{article} \usepackage{amsmath} \...
8
votes
1answer
3k views

Faulty right alignment for comments in algorithmic package

I'm trying to right align comments in a pseudocode environment using the algorithmic package. So I renewed the algorithmiccomment command. There's a different way to create comments for "normal" ...
8
votes
1answer
501 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 \...
7
votes
1answer
10k views

How can very long algorithms be automatically split over multiple pages?

I have a very long algorithm than spans several pages. I can not get Latex to make it span across several pages. I know that several questions similar to this one have already been asked, but I haven'...
6
votes
3answers
559 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 ...
6
votes
2answers
2k views

How to make “for all xxx do” appear on one line?

This is an example \documentclass[12pt,oneside,a4paper,onecolumn]{article} \usepackage{graphicx,color,setspace,hyperref} \usepackage[left=1.5in,top=1.25in,bottom=1.25in,right=1.25in]{geometry} \...
6
votes
1answer
462 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} \...
6
votes
1answer
4k views

Ruled Algorithms in columns/minipages

I'm using Benoit Guillon's algo styles for Lyx (at http://bgu.perso.libertysurf.fr/) in 2.0 to get nice algorithms ruled with line numbers. This is just a wrapper for the algorithm and algorithmic ...
5
votes
2answers
34k views

How to put \algorithm and \algorithmic environments inside a box?

I want to put an algorithm inside a box. Here is the code \fbox{\parbox{0.8\linewidth}{ \begin{algorithm} \caption{My algorithm} \begin{algorithmic}[1] \scriptsize ... \end{algorithmic} \end{...
5
votes
1answer
4k views

Alignment in algorithmic environment

I don't like how there is often a slight misalignment between assignment statements in an algorithmic environment. For example, the first version of the algorithm given below looks strange to me. I ...
5
votes
1answer
933 views

Remove the colon from line numbering in algpseudocode

Is there a way to remove the colon (:) from the line numbering in algorithms (using the algpseudocode package)? \documentclass{article} \usepackage{algpseudocode} \begin{document} \begin{...
5
votes
1answer
2k views

Input and output in latex algorithm [duplicate]

In latex, I am writing a pseudocode where I want to have output (of input and output) in the following fashion: This is my code: \documentclass[sigconf]{acmart} \usepackage{amsmath} \usepackage{...
5
votes
1answer
174 views

Does parbox has any conflict with the loop in algorithm?

I start to draw an algorithm using the algorithm package. And, I meet the problem that I can't well indent the parbox block which includes the loop, and it seems the parbox still effect the later ...
5
votes
2answers
1k 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
908 views

How to write sentences in an algorithm in latex?

Hi I am trying to write an algorithm which looks something like the image below: I was wondering how to write the "Step 1 (Update)" and also the rest of the line which says "When an edge e...." ...
5
votes
1answer
911 views

How to make the line number in algorithm shown in bold

I have tried following which works (making the number in second line bold) \begin{algorithm}[h] \begin{algorithmic}[1] \State TSO.assignStartTs() {\bf\State} TSO.assignCommitTs() \end{algorithmic} \...
5
votes
1answer
585 views

Inserting multiple columns in algorithm

I am currently working on runtime in my algorithm. I have currently set the algorithm up, and it looks like the following: I need to insert 2 new columns beside the current text. Each column should ...
5
votes
1answer
474 views

Conflict between arabtex and algorithmic

Below is a minimal working example which recreates the problem I'm facing. \documentclass{article} \usepackage{algorithmic} \usepackage{arabtex} \begin{document} \section{Introduction} \RL{d} \begin{...
5
votes
0answers
3k views

typing in bold font in algorithmic environment [closed]

Is there a way to type some words in bold in an algorithmic environment? I want to have the word stop typed, but when I use \STOP, this gives me an error.
4
votes
1answer
2k views

Change font for function names within algorithmic

Using the following code, the function name foo is printed as \textsc{foo}. \usepackage{algorithmic} \begin{document} \begin{frame} \begin{algorithmic}[1] \Function{foo}{$a$} \EndFunction \...
4
votes
1answer
1k views

How to change font style of all algorithm/algpseudocode keywords?

In detail I want to change the font style of all keywords like If Return For to bold/sans serif, but only the keywords. MWE: \documentclass{article} \usepackage{algorithm} \usepackage[noend]{...
4
votes
1answer
617 views

Increase width of caption's horizontal lines in algorithmic and listings

I've been able to increase the width of the horizontal lines honoring the second answer in LaTeX tables: How do I make thicker or thinner horizontal lines (typically \hline)?. Now, I'd like to do the ...
4
votes
1answer
9k views

! LaTeX Error: Something's wrong--perhaps a missing \item

I am using TEXMAKER. Here is a code segment. \usepackage{algorithmic} begin{algorithmic} \FOR {$i\gets0$ to $n$} \do \FOR {$j \gets$0 \TO $min(i,k)$} \do \IF {$j=0$ \OR $j=i$} ...
4
votes
1answer
4k views

Array inside Algorithm with underbrace and sidebrace

I'm writing my master's thesis (using LyX's thesis template) and am trying to display an algorithm. Since LyX's algorithm support doesn't quite cut it for me, I've decided to go ERT with LaTeX code (...
4
votes
1answer
89 views

Tabular-like alignment in algorithm

Is there a way to encapsulate every line in some dotted lines, and add on the right side 2 columns such that it would look the the picture below? And on every line I can write math equations or ...
4
votes
1answer
227 views

Referencing line numbers in an algorithm using autoref

What is the autoref command to reference a line number of an algorithm? I tried to define stepautorefname, linenoautorefname and alglinenoautorefname commands as shown below but they don't work like ...
4
votes
1answer
173 views

Changing line numbering format using algorithmic package

The following code numbers each line in the algorithm as <number><colon>. Is there a way to number each line as <number><period>? \documentclass{article} \usepackage{algorithm,...
4
votes
1answer
1k views

Left alignment in the algorithm and reset the numbers

I'm using algorithmic package and I would like to have certain text be left aligned. Also, would like to reset the numbering for each line inside the algorithm after certain text. The MWE provided to ...
4
votes
0answers
127 views

LyX: Can't compile with \usepackage{algpseudocode} with Language that isn't English

I'm pretty new to LyX and Latex. I'm writing a paper in Hebrew and I want to add an algorithm in English. So I'm adding \usepackage{algpseudocode} to the Preamble and pasting some example algorithm. ...
3
votes
2answers
11k views

Align Input and Output of algorithm to left

I use the following template for KDD 2017 - for conference (sample-sigconf file): here. This is the code I use for the my algorithm: \documentclass[sigconf]{acmart} \usepackage{booktabs,makecell,...
3
votes
2answers
986 views

New algorithm environment with a separate counter

I am trying to define a new environment called protocol, which is the same as the algorithm environment, except for the title and counter. I used this as my guideline. However, it does not reset the ...
3
votes
2answers
903 views

Wrap a few lines of Algorithmic in a box

I have some pseudocode where I want to reveal an algorithm little-by-little. Currently I highlight the code that is revealed by coloring it red and this looks good onscreen. However, on print, this ...
3
votes
2answers
8k views

Algoritmic return command = 0

Can you suggest me what is wrong with using return command in algorithms. when I add \RETURN $C to my LaTeX document I get return C =0, what I need is just return C. \begin{algorithm} ...
3
votes
2answers
1k views

Divide algorithm in two parts without incrementation of version

This is my code: \documentclass{article} \usepackage[paperheight=6\baselineskip]{geometry}% just for the example \usepackage{algorithm} \usepackage{algcompatible} \begin{document} \begin{algorithm}[...
3
votes
1answer
9k views

Why this 'Perhaps a missing \item' error with the algorithmic package?

I am trying to imitate an example I found in the LaTeX wikibook to write my own algorithm using the algorithmic package. I can't understand it clearly, though, and I am getting errors all the time. \...
3
votes
1answer
189 views

spacing problem for more than three algorithms in one page

I use algorithm and algpseudocode package. Problem is, when I tried to start the fourth procedure\function, the fourth one starts in the middle of the next page instead of right below to the third ...
3
votes
1answer
2k views

Algorithm problem in poster with tikzposter

I am creating a poster using tikzposter. But it seems to have a bug with algorithm packages. I use the following code but the borders of algorithm block span to the whole width of the poster: \...
3
votes
1answer
280 views

Statement (\STATE) indentation in Algorithmic package

I have the following code, \documentclass[]{memoir} \usepackage[utf8x]{inputenc} \usepackage{amssymb} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{algorithmic} \newcommand{\algorithmname}{...
3
votes
1answer
35 views

Footnote does not appear under algorithm

I have created pseudocode for an algorithm and would like to add a footnote under the algorithm. However, when I try to apply the answer provided here, no footnote does appear. See the following ...