Questions tagged [pseudocode]
{pseudocode} is a compact and informal description of a computer programming algorithm.
196
questions
2
votes
2
answers
163
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\...
0
votes
0
answers
20
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 ...
0
votes
0
answers
23
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 ...
0
votes
1
answer
32
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 ...
1
vote
1
answer
25
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 ...
1
vote
1
answer
28
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}
...
5
votes
1
answer
345
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 ...
1
vote
1
answer
63
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 ...
0
votes
0
answers
5
views
Adding vertical line for pseudocode without discarding the number [duplicate]
I need to draw a vertical line between (begin -> end), (if -> end if) and (for -> end for). I have read that adding package algorithm2e would solve the problem. However, I would like to ...
0
votes
0
answers
20
views
Using algpseudocode-package in theorem
I've defined my theorem style by
\theoremstyle{definition}
\newtheorem{problem}{Problem}[section]
\newtheorem{solution}{Solution}[section]
I want to write a pseudocode in my solution section like ...
1
vote
1
answer
63
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{...
4
votes
0
answers
177
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 ...
1
vote
0
answers
20
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
vote
1
answer
46
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,...
0
votes
0
answers
24
views
How do I correctly define keywords in the \ lstdefinelanguage section?
I create my own language definition with the listings package. It's a mix of HTML and Javascript. Why are the tags <title>, <h1>, <li> not included in the syntax highlighting and how ...
0
votes
0
answers
100
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
\...
1
vote
0
answers
40
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 ...
0
votes
0
answers
100
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{...
0
votes
1
answer
78
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)$ \...
2
votes
1
answer
66
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]{...
2
votes
2
answers
155
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 ...
-1
votes
1
answer
57
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{...
-1
votes
1
answer
43
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}
\...
1
vote
1
answer
344
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}
\...
-1
votes
1
answer
119
views
Can you show me how to make this pseudocode using `LaTeX`?
Can you show me how to make this pseudocode using LaTeX?
2
votes
1
answer
63
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 ...
0
votes
1
answer
3k
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 ...
0
votes
1
answer
471
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 ...
2
votes
2
answers
485
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 ...
0
votes
1
answer
57
views
Pseudocode notation [closed]
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 ...
0
votes
1
answer
50
views
Print apexes/superscript and subscript in quote
I am trying to print apexes and subscript in my pseudocode.
I used this code to write it, but it prints it as it is without converting it in math.
\begin{quote}\linenumbersep=-5pt
\resetlinenumber[1]
\...
0
votes
1
answer
176
views
set margin 7 mm from left lineno internal line numbers
I am trying to set a 7 mm margin from the left on my pseudocode. I am using lineno package and this is what I wrote:
\lipsum[2-4]
\begin{alltt}{\footnotesize{\internallinenumbers
S = \(\emptyset\)
...
0
votes
2
answers
195
views
Adding emptyset in my pseudocode
I am trying to write some pseudocode using verbatim. The problem is, I can't get it write the right symbols. Here's my code:
\begin{verbatim}
S= $\emptyset$
while ((not ottimo(S) ) and (C \ne $...
1
vote
0
answers
41
views
Right brackets for multiple code lines [duplicate]
I'm new to latex and I was wondering is there a way to achieve something like this in latex? I have searched the internet but I achieve a good solution. This post is good but it didn't have written ...
3
votes
2
answers
910
views
Modifying the algorithm name in algorithm2e
I am using the algorithm2e package to generate pseudocode for a paper. The journal requires the format of "S1 Pseudocode", "S2 Pseudocode", etc. However, I am only able to generate the format as "...
0
votes
1
answer
381
views
Equation in Pseudocode problem
I am trying to write a pseudocode in Latex including an equation. My MWE is the following
'\begin{algorithm}
\caption{Fuzzy c-means clustering algorithm}
\begin{algorithmic}[1]
\State Choose ...
1
vote
1
answer
188
views
Indentation not aligning while using algorithm2e package
Below is my latex:
\usepackage[ruled,longend]{algorithm2e}
\begin{algorithm}
$I \gets \text{Images of objects' plane}$\newline
$Detector \gets \text{Define detector}$\newline
$Descriptor \...
0
votes
1
answer
897
views
Bold some part of algorithm in overleaf, latex
\begin{algorithm}
\FOR{$1\leq i \leq M$}
\WHILE{$x)>x_1$}
Hello world
\ENDWHILE
\STATE Set y=2
\ENDFOR
Hello everyone,
I have a question regarding the algorithm in the latex. I want to bold ...
1
vote
1
answer
129
views
algorithm2e package lines are not ending in forall loop
My code is below I checked similar questions but can't find the answer.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[]{algorithm2e}
\begin{document}
\begin{algorithm}
\...
0
votes
0
answers
27
views
Use of algorithm within minipage gives error [duplicate]
I would like to adjust column width in algorithm below:
\usepackage{amsmath,amssymb}
\usepackage[norelsize, linesnumbered, ruled, lined, commentsnumbered]{algorithm2e}
\begin{document}
%\begin{...
0
votes
0
answers
219
views
How to mimic this pseudo code? and conflicting packages
I am trying to mimic this algorithm but the layout is not working. How can I get the same layout (or something close to it)? See code below picture.
I am using the package algo and the algo.sty link ...
2
votes
1
answer
429
views
How to fix an issue about multiple output lines in algorithm
When I write a pseudo code using algorithm and algorithmic.
Output statement overflow a line like below.
\begin{algorithm}[!h]
\textbf{Input:} The set of public $parameters$\\
\textbf{Output:} ...
3
votes
1
answer
2k
views
Writing pseudocode for parallel programming
"How do you write pseudo-code for parallel programming? Especially, how do you differentiate local and shared variables? How do you represent operations like scatter, gather, reduce, broadcast, and ...
0
votes
1
answer
28
views
This algorithmic command is not executing
\documentclass{article}
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}
\caption{family}
\hspace*{\algorithmicindent} \textbf{Input}\\
\hspace*{\algorithmicindent} ...
2
votes
1
answer
2k
views
Algorithmicx Nested FOR loop in pseudocode
I have been trying to format the pseudocode below combining algorithmicx and algpseudocode commands as well as following another related post
algorithmicx or algpseudocode custom command indentation ...
1
vote
0
answers
142
views
Can I make indent over many line on overleaf in \newtheorem?
I like to make it so that when I used \begin{pf} everything in the area is indented in a bit and when \end{pf} the text after is indented back out again, and if there are others inside it is indented ...
1
vote
0
answers
223
views
How to put large pseudocode in on slide?
I have used the following beamer class for the slides. I have put some algorithms in the slide, but pseudocode not looking good
\frame[shrink=25]{\frametitle{Algorithms in Quotient Groups}
...
2
votes
2
answers
875
views
Adding vertical lines in algorithm2e outside of blocks
I am using the package algorithm2e and notice that it has a great feature where vertical lines can be connected within "blocks" of code (see Vertical loop/block lines in algorithmicx with 'noend...
4
votes
0
answers
587
views
How to display vertical lines at indents in lstlisting?
I want to display vertical lines in indentations. I already found this thread: Lstlisting and indentation lines, but it isn't what I want.
This is how my attempt looks like:
This is how I want it to ...
0
votes
2
answers
4k
views
Pseudocode - repeat-until command
Hello how can I rewrite repeat until command so ''until'' in line 15 is closer to number 15 (not in the same column as line14)
\documentclass{article}
\usepackage{amsmath}
\usepackage{algpseudocode}
...