# Questions tagged [pseudocode]

{pseudocode} is a compact and informal description of a computer programming algorithm.

215 questions
Filter by
Sorted by
Tagged with
63 views

### In pseudo-codes, how to get newline in the same state?

I want to generate a pseudo-code similar to the image: Here's what I tried (I modified a bit the content of the code, but the idea is clear). In Inputs, splitting components in different lines with ...
1 vote
25 views

### algorithm2e does not set \texttt

I have algorithms that I wrote in algorithm2e. But I want the name of the function written in typewriter. As you see in the picture, this does not work, I get this strange font: Here is my MWE: \...
• 471
23 views

### pseudocode, clever-ref. display (algorithm number, line of code)

I have several algorithms and want to be able to have clever-ref automatically generate citations like \cref{alg1-line1}: Algorithm 1, Line 1 \cref{alg2-line44}: Algorithm 2, Line 44 preferably with ...
40 views

### Latex Pseudocode missing number cannot resolve

\begin{algorithm} \caption{LexBFS Algorithm} \begin{algorithmic}[1] \Function{LexBFS}{$G=(V, E)$} \State Let $P$ be an empty list \Comment{Initialize the permutation} \State Let $Q$ be an empty queue \...
• 1
55 views

### Algpseudocode, for-next loop: control variable in next line

In this pseudo-code excerpt, is it feasible to add a new argument for the variable v with a syntax like \ForAll {$v$}{$v \in V(G)$} to get the output next v? \documentclass{article} \usepackage{...
68 views

### How can I achieve this non-restrictive pseudocode style?

What is the best way (as in most efficient) way of writing pseudocode like below? In particular I like that it is well-structured but gives enough freedom in writing (in reality it it is just ...
• 131
1 vote
15 views

### How do I create an aligned column of text before the numbers in a "pseudo" environment?

I want to create a "diff" effect using the pseudo package, inspired by GitHub/Gerrit diffs. However, the symbols at the start of the line aren't lined up - they move when the digits go from ...
• 182
39 views

### I am facing problem in Pseudocode overleaf error Underfull \hbox (badness 10000) in paragraph at lines 615--615 ,Extra }, or forgotten \endgroup

this error I am getting Extra }, or forgotten \endgroup. Extra }, or forgotten \endgroup. Argument of \Return has an extra }. Underfull \hbox (badness 10000) in paragraph at lines 615--615 Runaway ...
30 views

### if else loops and repeat until loops doesn't work with algorithm package

code: \begin{algorithm}[!t] \begin{algorithmic}[1] \caption{Adaptive Random Search}\label{algo_ARS} \State define the probability of local search as $P_s$ and global search as 1 - $P_s$ \Repeat ...
42 views

### how to fix the issue in pseudo code algorithms with multiple precedures in latex?

I am formetting pseudo code algorithms with multiple procedures in it, but formatting has somes issues such as endProcedure=0in latex output though. How can I fix this? thanks my current script \...
• 103
959 views

### How to write a "repeat n times" loop in algorithmic?

In algorithmic, I would like to write a loop that will look like the following: repeat $n$ times: [command] end I found this question, explaining how to do this in algorithms2e, but it ...
• 6,191
1 vote
54 views

### Why is my symbol look so sparse in the pseudo code?

\documentclass[twocolumn]{ltxdoc} \usepackage{amsmath} \usepackage{newtxtext,newtxmath} % \usepackage{lineno} \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{amsmath} \usepackage{...
• 415
60 views

### How to write table in overleaf?

I hope you are doing very well. I am writing a report for my class. I need to add code like this in my latex report. But I haven't found any similar example from google. I just recently started using ...
• 35
1 vote
191 views

### Reduce font size of particular line in algorithm and algorithmic pseudocode

I want to reduce the font size of a particular line in an algorithm pseudocode where I use algorithm and algorithmic package. How can I do it? For example in the following I want to fit line 9 in one ...
• 281
156 views

### Background coloring in algorithm2e pseudocode in beamer

I tried to highlight parts of my pseudocode in algorithm2e with the following answer to a similar question: https://tex.stackexchange.com/a/51590/287916. I copied the code exactly the same and run it, ...
• 27
1 vote
180 views

### Cryptocode pseudocode: ignore a single line's column sizes

I'm writing a 2-player protocol with cryptocode's pseudocode, and have a while condition which applies to both players. Since the while condition is long it shifts the other columns far to the right, ...
34 views

### How to get the correct number corresponding to the line in pseudocode? [closed]

\begin{algorithm} \caption{Random Vector Generation} \begin{algorithmic} \State Generate $\mathit{n}$ random variables $\mathit{U_{1},...,U_{n}}$ as iid variables from $\mathit{U(0,1)}$ \newline \...
384 views

### Does anybody know how to draw this pseudo code diagram?

I want to draw this pseudo code in latex, can anybody help me? This is the code I created, however, it somehow doesn't match the requirement, can anybody help me to modify the code? \documentclass[...
• 415
329 views

### The LaTex template offered by AIP cannot be inserted pseudocodes [duplicate]

In order to submit to Chaos, I downloaded the Latex Template AIP requests. But when I was going to insert the pseudo code like \begin{algorithm} %\textsl{}\setstretch{1.8} \renewcommand{\...
54 views

I am writing a research paper using an official template. When I run .tex file, it shows all the text and images, but it does not show tables and pseudo code (Even packages are included). Please have ...
52 views

### How can I have two spaces before the broken lines in inputlisting?

I am using the solution from How can I write line numbers inside boxed code. Its code with slightly changes: \begin{filecontents*}{\jobname.sol} function hello_world(uint a, uint b, uint c, uint d,...
• 1,515
308 views

### Goto command in algorithm2e package

I use the following code N(a,n,i,j,y){ $p \gets 1$\; $z \gets 1$\; \While {$z \leq n$}{ \eIf{$a[y][z] = 0$} { $z \gets z+1$\; }{ ...
438 views

### How can I write line numbers inside boxed code

I am trying to show a code-piece inside a box. I was wondering is it possible to has its line numbers inside the box as well, shifting code little to the right? I have following code: \expandafter\def\...
• 1,515
1 vote
464 views

### How to remove Algorithm 1 from header and how to declare a variable with its type

I'm trying to write my first pseudocode algorithm with MikTEX and algorithm2e package but there are at least two things that I cannot understand. The image below shows what I want to achieve in term ...
• 111
60 views

### Conventions for Distinguishing a Property when Describing Different Objects

I have several objects, in this case they are indexed sequences which are used in an algorithm written in pseudo-code and in mathematical expressions. For example, there is $V$ and $S$, and there is a ...
• 101
93 views

### How to add vertical line next to code numbers and change background colors

I am using the listings package. With the code below I get a result like this I want to draw a line next to the line numbers like below. Also if possible I would like to change the background color ...
• 183
1 vote
185 views

### Loop statement without ending

I'm using usepackage{algpseudocode} for my pseudocode in latex, but I found after the loop statement there's only an end statement rather than end for. What went wrong with my algorithm. The rest of ...
• 75
1 vote
343 views

### Disable algorithmic line numbers with IEEE template

I want to disable line number in pseudo-code blocks, even though there isn't 1 in the \begin block. I am using the IEEE template This is the code \begin{algorithm} \caption{Test} \begin{algorithmic} ...
2k views

### Best practices for typesetting pseudocode

I need to typeset the pseudocode of several pieces of code in latex. I found in this answer a good overview of the three main packages available to render pseudocode. In the following I will adopt the ...
• 245
1 vote
980 views

### Placing pseudocode between paragraphs

I am trying to re-write a line of an algorithm's pseudocode, and I would like to be able to present it in-text rather than introducing another floating algorithm environment. How can I do this? Here ...
• 113
857 views

### How can I adjust nested if statements in the algpseudocode package

I have the following code: \documentclass{article} \usepackage{algorithm} \usepackage[noend]{algpseudocode} \begin{document} \begin{algorithm} \caption{Main D Algorithm}\label{alg:cap} \begin{...
• 169
1k views

### Highlighting pseudocode in algorithm

Edit: I "solved" my main issues now. It's a bit ugly/hacky, but at least the result looks ok. With this edit I'm replacing the now obsolete old code with what I have now. But suggestions for ...
• 91
1 vote
25 views

### How to eliminate indentation when using command "\For{}" in the "algorithm environment"

I do not want an indentation for the "For loop." How can I make it aligned with the "Require" text? \documentclass{article} \usepackage{amsmath,amssymb} \usepackage[utf8]{inputenc} ...
• 1,474
1 vote
55 views

### how to eliminate automatic indentation in pseudo code

In the code, one of the lines has an automatic indentation. How can I eliminate the indentation(it is the line after the command "\Endwhile")? \documentclass{article} \usepackage{amsmath,...
• 1,474
298 views

### How to format really long sentence in for loop pseudocode?

I have the following code for an algorithm. \begin{algorithm} \label{alg:script} \caption{Algorithm to calculate something} \begin{algorithmic}[1] \State One line sentence \...
• 125
1 vote
79 views

### How to Display Pseudocode with New Commands [duplicate]

I want to write pseudocode in TeXShop, with my own commands. The only commands I need to have are save, repeat, return, and if/elif/else. Can someone please help me with that? I was trying to figure ...
• 11
475 views

### Writing multiline equation inside algorithmic pseudocode environment

I have the following code which produces the algorithm in the image. \documentclass{article} \usepackage{algorithm} \usepackage{algorithmicx} \usepackage{algpseudocode} \begin{document} \begin{...
• 101
515 views

### Not able to get proper for loop and if

\usepackage{algorithm} \usepackage{algpseudocode} \begin{document} \begin{algorithm} \caption{Brute-Force algorithm} \begin{algorithmic}[1] \For {$s'$ \in ${\mathbb{F}^n_2}$}{ \If {$wt(As'+b)$ \...
244 views

### Formatting a Pseudocode using Algorithm2e

I'm trying to format a pseudocode using the Algorithm2e package. The desired output has the following format: Here's the code I've tried to format this pseudocode: \usepackage[ruled,vlined]{...
• 121
827 views

### How to make the pseudo code more compact?

I wrote the following piece of pseudo code. It shows the result as shown in the figure below. I think there is too much white space above the horizontal line in the picture. I want to make them more ...
• 175
78 views

### how can i correct this mistakes, i tried a lot

\documentclass[a4paper,11pt]{article} \usepackage{algorithm} \usepackage{commath} \usepackage{algpseudocode} \begin{document} \begin{algorithm} \caption{Game Theory Controller} {\textbf{...
117 views

### ! LaTeX Error: \caption outside float. when creating pseudocode algorithm in Latex

Here's my code : \usepackage{algorithmic} \begin{algorithm} \caption{Calculate $A_{nxn}$} \label{Algorithm 1} \begin{algorithmic} \begin{enumerate} \item ... \end{enumerate} \end{algorithmic} \...
• 101
1 vote
2k views

### Pseudocode: "If not" control structure

I use the following packages: \usepackage{algorithm} \usepackage{algpseudocode} to display pseudocode of some algorithms in my latex document. For conditionals I use the follow \If{success = 0} \...
• 113
300 views

### Can you show me how to make this pseudocode using LaTeX?

Can you show me how to make this pseudocode using LaTeX?
197 views

### Pseudocode in the style of Algorithm Design (Kleinberg & Tardos)

How do you write pseudocode in the style below? I tried using the verbatim environment but I can't seem to get the variables italicized and symbols like \in to work. I also tried using the algorithmic ...
• 23
13k views

### Why do I get "Require" and "Ensure" instead of "input" and "output" phrases in my pseudocode in IEEE Access format?

When I wrote the following pseudocode in \documentclass{article} format, I get "Input" and "Output" phrases after the compilation but when I write the same latex code in the IEEE ...
• 173
2k views

### Cannot write my pseudocodes in IEEE Access format?

I am trying to write an IEEE Access paper by using the template on their website. But I am having trouble writing my pseudocodes since there is no pseudocode example in their template. When I use ...
• 173
1k views

### Using a matrix as a parameter in an algorithm

I'm trying to write a pseudocode algorithm in LaTeX, where one of the functions needs to have matrices as a parameter. I need to get it to look like this: I've been using the algorithm package, but ...
In pseudocode, how do you state comparisons and statements? Should I use == and = like in programming languages or should I completely switch to $=$ for comparison and $:=$ for each statement? What ...