Tag Info

New answers tagged

0

I'm continuing egreg's answer, which fixes "bug" #2 by reducing font size or widening the text and thus avoiding line breaks. You can format the procedure's name in any way you like, by redefining the \textproc macro, e.g.: \algrenewcommand\textproc{\textit} If you don't like the italics that I chose, try \textrm instead. If you don't want to use ...


2

The problem is due to the narrow size of the column. You have two choices. Declare \footnotesize before \begin{algoritmic} \begin{algorithm} \caption{Equivalent Method Handle (MH) Detection} \label{alg:equivalentmap} \footnotesize \begin{algorithmic}[1] \State $mh$: A method handle to be proceeded. ... \EndProcedure \end{algorithmic} \end{algorithm} ...


1

A quick solution is to use \setcounter inside each algorithm. Moreover, to get the algorithms aligned in the list of algorithms you need to redefine \listof and \l@algocf commands and set \@dottedtocline with the desired horizontal spacing. Here is the code: \documentclass{article} \usepackage{algorithm} \usepackage{algorithmic} ...


6

This is what I'd do, if I were not to use clrscode. \documentclass[11pt]{article} \usepackage[noend]{algorithmic} \newcommand{\TITLE}[1]{\item[#1]} \renewcommand{\algorithmiccomment}[1]{$/\!/$ \parbox[t]{4.5cm}{\raggedright #1}} % ugly hack for for/while \newbox\fixbox \renewcommand{\algorithmicdo}{\setbox\fixbox\hbox{\ {} }\hskip-\wd\fixbox} % end of ...


6

(Only a partial answer) Cormen used his clrscode package for the second edition of CLRS, but a "beefed-up" version of it, called clrscode3e, for the third edition, from which the Insertion Sort algorithm in your screenshot is taken. For more details, see this. The code for typesetting the algorithm (but without the "cost" and "times" columns) can be found ...


3

algorithm uses the float package to style the algorithm environment using \floatstyles. Here are the float styles for plain and ruled: % The 'plain' float style \newcommand\fs@plain{\def\@fs@cfont{\rmfamily}\let\@fs@capt\floatc@plain \def\@fs@pre{}\def\@fs@post{}% \def\@fs@mid{\vspace\abovecaptionskip\relax}% \let\@fs@iftopcapt\iffalse} % The 'ruled' ...


2

Temporarily change \chapter into \section: \documentclass{book} \usepackage{algorithm} \begin{document} \chapter{A chapter} \begingroup \renewcommand{\listalgorithmname}{Algorithmenverzeichnis} \let\chapter\section \listofalgorithms \endgroup \begin{algorithm} \caption{An algorithm} \end{algorithm} \end{document} The grouping above limits the ...


2

You can change the linespacing by inserting \onehalfspacing soon after the algorithm environment. If this is wanted for all such instances, you may use \AtBeginEnvironment from etoolbox like \usepackage{etoolbox} \AtBeginEnvironment{algorithmic}{\onehalfspacing} in the preamble. Obligatory code: \documentclass{article} \usepackage{algorithm} ...


2

Regular line-breaks and associated indentation is discussed in Line-break in package algorithm2e. For conditional adjustments, perhaps the following might be of interest: \documentclass{article} \usepackage{algorithm2e} \SetKwIF{If}{ElseIf}{Else}{if~(\endgraf}{\endgraf)~then}{else if}{else}{end if}% \begin{document} \begin{algorithm}[H] \SetAlgoLined ...


2

The \label command saves the index of counter that was last used in the \refstepcounter command. As the \caption command always calls \refstepcounter{algorithm}, the \label is always associated with the algorithm counter and hence cleveref prints Algorithm instead of Kernel. The easiest solution I can think of is just calling \label before calling ...


4

This is all much easier if you use the algoritmicx package, it has a lot more functionality and works better with other packages: \documentclass[12pt]{report} \usepackage[a4paper,margin=1.25in]{geometry} \usepackage{algorithmicx} %Defines the \If command, ending in \EndIf \algblockdefx[If]{If}{EndIf}[0]{\textbf{if} $($}{$)$} %Defines the alternative ending ...


2

After studying the cleveref package documentation further, I stumbled across a warning in section 14.1 Non-bugs. Even though I did not use \label in an optional argument to another command (as the third bullet suggests), it seems that it should be enclosed with curly braces in order to work properly. Correcting \label[opC]{line:1} into {\label[opC]{line:1}} ...


-2

After the graphics or listing, add this code: \vfill \rule[\baselineskip]{0pt}{\baselineskip}


5

The vlined option suppresses the printing of “end”. Just remove the option, keeping just ruled: \documentclass{article} \usepackage[ruled]{algorithm2e} \begin{document} \begin{algorithm}[H] \caption{How to write algorithms} \KwData{this text} \KwResult{how to write algorithm with \LaTeX2e } initialization\; \While{not at end of this document}{ read ...



Top 50 recent answers are included