Tag Info

New answers tagged

2

Probably the user who asked this question is not interested in my answer anymore. But I was in the same quest didn't find any good-looking algorithm package (for my taste). Since I'm a fan of the Listings package I followed Ruben's suggestion and created my own environment. Features: higlights my own specific keywords (but a predefined language can be ...


3

It's not really well documented in algorithm2e manual, but to achieve what you want, you have to issue the command \SetProcNameSty{textsc} The argument of \caption when using the procedure environment can only contain something like name(arg). In the following MWE I've also added \SetProcArgSty{textsc} just in case you are using procedure captions ...


1

The following works for me. \documentclass[journal]{IEEEtran} \usepackage{algorithmic} \usepackage{algorithm} \usepackage{lipsum} \usepackage{filecontents} \begin{filecontents*}{\jobname.alg} \REQUIRE $n \geq 0 \vee x \neq 0$ \ENSURE $y = x^n$ \STATE $y \leftarrow 1$ \IF{$n < 0$} \STATE $X \leftarrow 1 / x$ \STATE $N \leftarrow -n$ ...


5

The only reason for not having the "end for" is that you are using the noend option when loading algpseudocode. In fact, the following MWE \documentclass{article} \usepackage{algorithm} \usepackage[noend]{algpseudocode} \begin{document} \begin{algorithm} \caption{My algorithm}\label{alg:myalgo} \begin{algorithmic}[1] \Procedure{Algo1}{} ...


1

The following minimal example provides \phase{<desc>} which sets a Phase X - <desc> description within the algorithm. Note that it's usage only works as expected at the top level of indentation. However, I would think this is sufficient in terms of the presentation of one's algorithm. \documentclass{article} ...


1

Something like this. Need algpseudocode package. Code \documentclass{article} \usepackage{algorithm} \usepackage{algpseudocode} \begin{document} \begin{algorithm} \caption{My algorithm}\label{alg:myalgo} \begin{algorithmic}[1] \Procedure{Algo1}{} \For{\texttt{<condition>}} \State \texttt{<my stuff>} \EndFor \EndProcedure ...


3

Here it is: Code: \documentclass{article} \usepackage{amsmath} \usepackage[linesnumbered,ruled]{algorithm2e} \begin{document} \begin{algorithm} \SetKwInOut{Input}{Input} \SetKwInOut{Output}{Output} \underline{function Euclid} $(a,b)$\; \Input{Two nonnegative integers $a$ and $b$} \Output{$\gcd(a,b)$} \eIf{$b=0$} { ...


4

You can always force the algorithms not to float using the the floating specifier H. MWE \documentclass{scrbook} \usepackage[utf8]{inputenc} \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{lipsum} %just for the example \begin{document} \lipsum[1-3] \begin{algorithm}[H] \caption{My algorithm} \begin{algorithmic} \Require ...


6

You could make algorithm unfloatable and box it with another floatable environment which adapts the width. In the following, an invisible tcolorbox is used for this purpose. Adapt the grow to left by and grow to right by options for the width needed. Also, the float settings are done by the float option. \documentclass[a4paper]{article} ...


3

If you're comfortable to not let the algorithm float, then you can put it in a box that you can readjust to suit your needs: \documentclass{article} \usepackage{algorithm,lipsum,changepage} \usepackage[noend]{algpseudocode} \begin{document} \lipsum[1] \noindent\hspace*{-.1\textwidth}% \begin{minipage}{1.2\textwidth}% \begin{algorithm}[H] ...


5

The problem is that algorithm is a floating environment and cannot be boxed. But you can tell it not to float using H as a floating specifier (\begin{algorithm}[H]) and use, for example, the fullwidth environment from the fullwidth package in this way \begin{fullwidth}[width=\linewidth+2cm,leftmargin=-1cm,rightmargin=-1cm] <your stuff here> ...


4

Your issue is algorithm is a float environment by default, and you can't have floats inside a minipage. However, you can specify the [H] option to suppress floating and have it work as you intend: \documentclass{article} \usepackage{algorithm2e} \begin{document} \begin{minipage}{.5\linewidth} \begin{algorithm}[H]\small {Start}\; ...


9

You have to use \State instead of \\ to indent your lines inside the \For statement. MWE \documentclass{article} \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{pifont} \begin{document} \begin{algorithm} \caption{CH election algorithm} \label{CHalgorithm} \begin{algorithmic}[1] \Procedure{CH\textendash Election}{} \For{each node $i$ ...


3

This is very similar in nature to John's answer, using mathtools's math overlapping tools: \documentclass{article} \usepackage{mathtools,algorithm} \usepackage[noend]{algpseudocode} \begin{document} \begin{algorithm} \caption{Euclid's algorithm} \begin{algorithmic}[1] \Procedure{Euclid}{$m,l$}\Comment{The g.c.d.\ of~$m$ and~$l$} \State ...


3

If you really want to do it, you can use \makebox set to a constant width. \documentclass[a4paper]{article} \usepackage[english]{babel} \usepackage[utf8]{inputenc} \usepackage{algorithm} \usepackage[noend]{algpseudocode} \newlength{\maxwidth} \newcommand{\algalign}[2]% #1 = text to left, #2 = text to right {\makebox[\maxwidth][r]{$#1{}$}${}#2$} ...



Top 50 recent answers are included