I am using the algorithm2e
package for my pseudo code since I like the like the options this package offers. However, the boxed
option gives a text-width sized box and it doesn't look appealing to me when the code is much more narrow. This is a MWE.
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath} %
\usepackage{amssymb}
% real R
\newcommand{\R}{\mathbb{R}}
\usepackage[noline, boxed]{algorithm2e}
\begin{document}
% ALGORITHM
\begin{algorithm}
\DontPrintSemicolon
% \SetKwData{Left}{left} % normal
\SetKwFunction{SDud}{SDud}\SetKwFunction{Tol}{tol}\SetKwFunction{Break}{break}% tt
\SetKwInOut{Input}{input}
\BlankLine
\Input{$A \in \R^{m \times n} (m<n), \:\: b \in \R^m, \:\: x_{(0)}\in \R^n$.}
\BlankLine
\emph{\% Initialization}\;
$x = x_{(0)}$\;
$r = b - Ax$\;
$p = A^Tr$\;
\BlankLine
\emph{\% Start \SDud}\;
\For{$t = 0,1,2\ldots,t_{\max}$}{
\BlankLine
\emph{\% Compute $\alpha_{(t)}$}\;
$q = Ap$ \;
$\rho = p^Tp, \: \sigma = q^Tq, \: \alpha = \rho / \sigma$ \;
\BlankLine
\emph{\% Check for convergence}\;
\lIf{$\rho \leq$ \Tol}{\Break}
\BlankLine
\emph{\% Compute new iterate $x_{(t+1)}$}\;
$x \leftarrow x + \alpha p$
\BlankLine
\emph{\% Update residual $p_{(t+1)}$}\;
$w = A^Tq$ \;
$p \leftarrow p - \alpha w$
}
\caption{My alg}
\end{algorithm}
\end{document}
And this is how it looks:
I don't like the white space on the right, so I wish it was a tight, centered box around the pseudo code. Unfortunately the algorithm2e documentation
doesn't provide me with any insight regarding this issue. Can somebody here help me out?
Cheerse