Tag Info

New answers tagged

2

Your code uses nothing involving the algorithm2e package and the use of the packages conflict with one another. Instead add the algorithm package to your preamble. \documentclass{article} \usepackage{algorithm,algpseudocode} \begin{document} \begin{algorithm} \caption{Euclid's algorithm}\label{euclid} \begin{algorithmic}[1] ...


3

The minimal example below uses code from the answer to algorithm2e: Exclude functions from \listofalgorithms with the addition of \renewcommand{\addcontentsline}[3]{} in the appropriate location where contents is written to the List of Algorithms: \documentclass{scrreprt} \usepackage{algorithm} \usepackage[ruled,algosection,algo2e]{algorithm2e} ...


2

The algorithm environment increases left and right margins of its contents, so you have to substract them from textwidth: \documentclass[a4paper,draft]{article} \usepackage[utf8]{inputenc} \usepackage[ruled]{algorithm2e} \usepackage{framed} \begin{document} \begin{algorithm}[h] \begin{framed} something in a framed environment \end{framed} ...


1

Instead of mathmode $\leftarrow$ (as suggested in comments) can also use \textleftarrow from textcomp package \documentclass[]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[]{algorithm2e} \usepackage{textcomp} \usepackage{lmodern} \begin{document} \title{Title} \author{Author} \date{Today} \maketitle \begin{algorithm}[H] ...


1

How 1010011010 user said, you must use $\leftarrow$ instead of \leftarrow.


2

If you're sticking to a single-line \KwInput, you can use the following: \documentclass[a4paper]{article} \usepackage[ruled]{algorithm2e} \usepackage{calc} % Define keywords \SetKwInput{KwInput}{Input} \SetKwInput{KwOutput}{Output} \let\oldKwInput\KwInput \renewcommand{\KwInput}[1]{% \makebox[\widthof{\KwOutput{}}][l]{\oldKwInput{}#1}% } ...


1

Here's an unusual way to achieve it... using tabular. \documentclass[a4paper]{article} \usepackage[ruled]{algorithm2e} % Define keywords \SetKwInput{KwInput}{Input} \SetKwInput{KwOutput}{Output} % This aligns the colons %\SetKwInOut{KwInput}{Input} %\SetKwInOut{KwOutput}{Output} \begin{document} \begin{algorithm}[h] \tabcolsep=0pt ...


2

\documentclass[a4paper]{article} \usepackage[ruled]{algorithm2e} \usepackage{etoolbox} \makeatletter \renewcommand{\SetKwInOut}[2]{% \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo:}% \expandafter\ifx\csname InOutSizeDefined\endcsname\relax% if first time used \newcommand\InOutSizeDefined{}\setlength{\inoutsize}{\wd\algocf@inoutbox}% ...


2

I have re-listed the original non-automated approach here, since the automated approach (below) was shown to exhibit deficiencies. With the manual approach, the comment is placed in a \parbox, but the user must specify the width of it. The underfull boxes cited by the OP are remedied by making the comment explicitly \raggedright. \documentclass{article} ...


3

Setting the breakable portion in a \parbox of sufficient width allows you to break it at will as well as properly align the content: \documentclass{article} \usepackage{mathtools} \usepackage[boxed,vlined,linesnumbered,noresetcount]{algorithm2e} \begin{document} \begin{algorithm}[tp] \texttt{out} $\vcentcolon=$ \textsc{foo}($\texttt{x} \rightarrow ...


2

Something like this, with adjustable indentation. The solution defines a new command called \myindent constituted with \newline and \makebox{#1}{}, taking one argument for length. Code \documentclass{article} \usepackage{amsmath} \usepackage[boxed,vlined,linesnumbered,noresetcount]{algorithm2e} \newcommand{\myindent}[1]{ \newline\makebox[#1cm]{} } ...



Top 50 recent answers are included