Questions tagged [algorithms]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
24 views

Incorrect indentation for the “end” word of a for loop

I'm writing a pseudo code in latex using algorithm package, however, I have problem with indentation of the last end word for the for-loop if this for-loop contains an if statement. If it doesn't ...
1
vote
1answer
26 views

algorithmic package dont automatically break page when too long [duplicate]

I have an algorithm defined with algorithmc like this: \documentclass{article} \usepackage{algorithm} \usepackage{algorithmicx} \begin{document} \begin{algorithm} \begin{...
0
votes
0answers
26 views

Pseudocode split into parts

I'm trying to write a block of pseudocode like here I know how to remove line numbers and get the black lines at the top and the bottom. I don't know how to label each section like 'Process' and '...
0
votes
1answer
15 views

Using \cref for algorithm step

What \crefname do I provide for referring to a step of an algorithm (not the algorithm float itself!)? I am able to label the steps of an algorithm and refer them using \ref but how do I use \cref ...
3
votes
1answer
59 views

TiKZ arrows and text inside of lslisting code

I have some lslistings code and I want to add some text and math elements as is shown in red color in the image below I tried using TiKZ but I got many errors. I'm attaching a MWE and thanks in ...
0
votes
0answers
26 views

How can I make my Latex algorithm look like this? [duplicate]

I need one Algorithm with functions seperated by a line like this one.I really need this, thanks in advance. If you know another method that you think looks better, I would also appreciate your ...
0
votes
1answer
31 views

Algorithm missing \state

I am writing this algorithm and this what I have as a result. The \for and \while ... doesn't appear. \usepackage{algorithm} \usepackage{algorithmic} \begin{algorithm} \caption{Calculate the exact ...
0
votes
0answers
40 views

Code formating in LaTeX [duplicate]

Any suggestions on how to achieve a look for a code as seen in the picture? Maybe with "listings" or do I need to do it manualy? Thanks in advance!
0
votes
1answer
39 views

Beamer citation footnote: Algorithm environment

Following up on this, I encounter a problem when using the algorithm environment. See the minimal working example below (mostly copied from an answer): Here, the algorithm environment simply treats ...
1
vote
1answer
58 views

Indent at automatically generated line breaks is lost for long single statements in algorithm

MWE: \documentclass[11pt,a4paper,notitlepage]{report} \usepackage{amsmath} \usepackage{amsthm} \usepackage{amssymb} \usepackage{algorithm}% http://ctan.org/pkg/algorithms \usepackage{algpseudocode}% ...
3
votes
2answers
262 views

How can I properly write this equation in Latex?

The equation is basically Bellman equation essential to the Q-learning algorithm. If there's any way to include the notes below (such as "New Q-Value") aswell that'd be even better!
0
votes
0answers
53 views

Breakable algorithm

Can anyone help? I am using the code below for a breakable algorithm environment defined in the preamble. However, when I use this code with the template from https://github.com/kks32/phd-thesis-...
0
votes
1answer
35 views

why algorithm appears like this?

I am trying to write algorithm but its not working. \usepackage[options ]{algorithm2e} \usepackage{amsmath} \usepackage{algorithm} \usepackage[noend]{algpseudocode} \begin{algorithm} \...
3
votes
1answer
55 views

Algorithm writing in latex

How can I write this algorithm in left align latex of 2 column? I have tried this but its not working \textit{repeat till convergence} \begin{equation}\small \label{eq_04} { W_{i+1} = W_i - \...
2
votes
1answer
42 views

LaTeX - Change the overall indentation of algorithms in a book

I am writing on a document that is formatted as a book (two pages with an indentation on the left side for even page numbers and on the right side for odd page numbers). \documentclass[10pt,twoside,...
2
votes
2answers
64 views

How to add comment in algorithm

How can I add comments in the following algorithm based on package algorithmic? \documentclass[10pt,conference]{IEEEtran} \IEEEoverridecommandlockouts \usepackage{cite} \usepackage{amsmath,...
0
votes
0answers
30 views

algorithm with vertical line

i created the following algorithm but i am not satisfied with the output.So i was wondering is there a way to add vertical lines in my algorithm but also keep the same structure and be able to put it ...
8
votes
2answers
489 views

TikZ/PGF draw algorithm

I have TikZ code that draws an ellipse. Here is the code that, AFAIK, draws the actual ellipse: \draw [rotate around={0.:(0.,0.)},line width=0.8pt] (0.,0.) ellipse (5.cm and 4.cm); Can anyone tell ...
0
votes
0answers
25 views

My latex (algorithm2e ) algorithm did not fit on one page, how I can continue to the next page (without resetting the line number)

%%Here is my algorithm : \documentclass{article} \usepackage[linesnumbered,ruled,vlined,boxed,commentsnumbered]{algorithm2e} \newcommand{\forcond}{$i=0$ \KwTo $n$} \SetKwProg{Fn}{Function}{}{end}\...
1
vote
1answer
36 views

remove space in the if statement

I would like to remove the spaces within my if statement, how can I do that? \documentclass[conference]{IEEEtran} \IEEEoverridecommandlockouts \usepackage{cite} \usepackage{amsmath,amssymb,...
0
votes
0answers
27 views

How to put texts on a newline in an algorithm (in a nested for-loop)?

I am making an algorithm with a nested for loop, and there are multiple in the loop. They are presented on the same line, but I want them to start on a newline. Any ideas how I can do this? This is ...
1
vote
1answer
37 views

Remove \Endif from algorithm

I want to write the following algorithm in LaTeX. The code I used is as follows: \documentclass{article} \usepackage{algorithm} \usepackage{algorithmic} %\usepackage{algpseudocode} %\algtext*{EndIf} ...
3
votes
2answers
104 views

How do I write a simple if-elseif protocol in Latex?

I've tried using algorithm, algorithmic, etc.. but I can't seem to find what I need. I want something similar to this: This is the closest I got using tcolorbox and align: \begin{tcolorbox}[...
1
vote
1answer
50 views

Error Message in Displaying Algorithm

I am writing a thesis, and there I have three files, one is main, another one is Chapter and the last one is a.tex. main.tex is using to call the chapter. I have written main algorithm in a.tex. So ...
2
votes
2answers
128 views

Else If is not working on algorithm in algpseudocode

I tried to add \Else in my pseudocode using packages algorithm and algpseudocode but it is not showing and I am getting Missing number, treated as zero. This is my code and the current outcome. \...
1
vote
2answers
54 views

How to format the algorithm

I have the text for the following algorithm, but I am unable to format it, with the numbers and spacing as in the image: $COVERABILITY-GRAPH((S,T,F,M_0))$\\ $(V,E,v_0):=(\{M_0\},\emptyset,M_0);$\\ ...
0
votes
0answers
25 views

The algorithm does not execute in IEEE transaction template. Please help [duplicate]

\documentclass[journal]{IEEEtran} \usepackage[classicReIm]{kpfonts} \usepackage{booktabs,tabularx,lipsum} \usepackage{longtable} \usepackage{float} \usepackage{graphicx} \usepackage{subfigure} \...
1
vote
1answer
87 views

How do I make d = function(x,y)

I am using the algorithm package and read it knowing there is \function to use. I want to make my output look like: Function d = dotproduct(x,y). How can I accomplish this? And this is what I ...
1
vote
1answer
38 views

algorithm syntax in latex

I use latex for my thesis but my language is persian and I have to use xepersian package . recently I have a problem and when I use algorithm and algorithmic package , my algorithm'code become ...
0
votes
0answers
32 views

Pseudocode in latex with fractions with text [duplicate]

So I´ trying to re-write this pseudocode in latex My pseudoce is like this: \begin{document} \begin{algorithm} \caption{Učící mechanismus obcí} \begin{algorithmic}[1] \While {Obce ještě ...
1
vote
0answers
57 views

latex pseudocode with fractions

I´trying to write this pseudocode in Overleaf - cant do the fraction (line 15) \begin{algorithm} \caption{Učící mechanismus obcí} \begin{algorithmic}[1] \While {Obce ještě nedokonvergovaly} \State $...
0
votes
1answer
46 views

How to keep whitepaces between words in algorithm

I am new to LaTeX. When I tried to write an algorithm all spaces between words get removed after \gets. See the image. \begin{algorithm} \caption{Filtering lexicon file} \label{algo1} \begin{...
0
votes
0answers
76 views

How to cite algorithms?

\documentclass{article} \usepackage[utf8]{inputenc} \usepackage{latexsym} \usepackage[linesnumbered,ruled,vlined]{algorithm2e} \SetCommentSty{mycommfont} \usepackage[linkbordercolor={0 0 1}]{...
0
votes
0answers
15 views

Start numbering Algorithm [duplicate]

Usually, in a document the algorithms numbering start: First algorithm Algorithm 1 Second algorithm Algorithm 2 and so on Is there a way to start numbering algorithms from a different number ...
0
votes
1answer
47 views

Representing Objects/Classes in Latex

I was curious... I couldn't find this in any of the documentation of the algorithm2e and algorithmicx packages. I'm wondering if there's a way to represent objects with attributes in LaTeX. Would help ...
2
votes
1answer
58 views

Pseudocode in latex cannot be formated

I´m writting my work and for some reasone my pseudocode in final pdf cannot be formated: Mistake report is this: The code I'm using: \documentclass[11pt,a4paper,openright]{report} \let\openright=\...
0
votes
0answers
31 views

What is the reason of extra '=0' [duplicate]

I know the reason is the incompatibility of the packages, but I tried all the possibilities and I couldn't reach to the point of removing '=0' without changing the algorithm style I want. . \...
0
votes
1answer
22 views

How do I get rid of the commands (for, do, if …) in Algorithmic?

I am writing a paper in LATEX like the picture. I tried many times but there I haven't yet shown the way to do them. I tried to type this example with Algorithm but it can not. Could you say to me ...
0
votes
0answers
17 views

How to include algorithm in JFM template

I'm writing with the template offered by the Journal of Fluid Mechanics, downloadable here. I'm wondering how can an algorithm be added into the paper. I tried to use the \usepackage{algorithm} but it ...
0
votes
1answer
42 views

I want to write an algorithm in overleaf, but it comes up with errors [duplicate]

\begin{document} \usepackage{savesym} \usepackage{program} \savesymbol{AND} \savesymbol{OR} \savesymbol{NOT} \savesymbol{TO} \savesymbol{COMMENT} \savesymbol{BODY} \savesymbol{IF} \savesymbol{ELSE} \...
2
votes
1answer
248 views

Is it possible to draw vertical lines in algorithm (not algorithm2e) package?

My question is if it is possible to draw vertical lines in the algorithm package. I have seen the following question: Vertical line for pseudo code But I don't want to use algorithm2e because it ...
0
votes
0answers
32 views

algorithm float environment

I would like to put 2 algorithms next to each other. I followed several suggestions and I ended up with something like: \begin{figure*}[ttt!] \begin{minipage}[t]{.38\linewidth} \begin{algorithm}...
1
vote
2answers
52 views

How to align line numbers horizontally with package algorithm2e

I'm trying to write an algorithm using the package algorithm2e. This is my code: \usepackage[linesnumbered,ruled]{algorithm2e} ... {\footnotesize \IncMargin{1em} \begin{algorithm}[H] \...
4
votes
2answers
247 views

How can I put a period right after the algorithm's number in the algorithm's title?

I wish it said "Algorithm 1.", with a period after the number, and not just "Algorithm 1". It's how I see most people using it, so I must be using an unconventional package? Would you say I should ...
1
vote
1answer
38 views

Align comment in algorithm to the end of the line

Here is my algorithm:: As can be seen the comment is aligned to the right end of the line. I would like to align the comment to the end of the same line. At the exact place where the line ends I ...
0
votes
1answer
389 views

Algorithm: ELSEIF problem

I want to compile this code in Latex (shown below). I use three libraries. I especially need elseif and \state command and line number. LaTeX Error: Command \algorithmicindent already defined.Or ...
0
votes
1answer
147 views

how to write the algorithm in latex

My code is below, I didn't find the error. \begin{algorithm}[H] \SetAlgoLined \textbf{Input} :$x_{k-1}$,$P_{k-1}$,$u_{k}$,$z_{k}$\; \textbf{Output} : $x_{k}^{-}$,$P_{k}^{-}$ \\~\\ $x_{k+1}={\Phi{x}}...
1
vote
1answer
47 views

How to have a space between algorithm lines

I have an algorithm and I would like to insert space between its steps. Here is my try: \documentclass[12pt,a4paper,openright]{report} \usepackage{amsmath} \usepackage{amssymb} \usepackage{...
2
votes
2answers
1k views

How to write algorithm like this in latex

I want to write an algorithm in a latex. There are various ways to write, but I want to write in the way given below. I have tried but I am not able to do anything similar to the given in the image. ...
1
vote
1answer
59 views

Add colon after algorithm caption/number in IEEE transactions

I am using Overleaf to write an article in IEEE transactions template. I wish to write the caption of Algorithm as, Algorithm 4: (as shown in the picture below). But when I use my code, it shows ...