# Latex resize algorithm

I have to resize an algorithm in Latex. I have tried \resizebox and \scalebox but I get this error:

Error: Not in outer par mode


Anyone has a suggestion?

Here is the code

\scalebox{0.8}{%
\begin{algorithm}[!htb]
\caption{Basis Pursuit solver}
\label{alg:L1}
\begin{algorithmic}
\STATE{Input: $A = \Phi \Psi, \; y, \; K$}
\vspace{0.2cm}
\STATE{Inizialize:}
\vspace{0.2cm}
\STATE{
$\left\{ \begin{array}{l} P = [ p_1 \ldots p_N ], \; P = I - A^{\dagger} A, \\ x_0 = A^{\dagger} y \quad \text{ \emph{\mbox{\scriptsize // Compute with QR factorization}}} \\ t=0 \end{array} \right.$
}
\vspace{0.2cm}
\STATE{Output: $K$-sparse coefficient vector $x$}
\vspace{0.2cm}
\WHILE {$t < \text{max}\_\text{iter}$}
\vspace{0.2cm}
\STATE{$s_t = \text{sign}(x_t), \; w_t = (s_t+1)/2$
\emph{\mbox{\scriptsize // reduce $s_t$ to binary vector $w_t$}}
}
\vspace{0.2cm}
\IF{$t > 0$}
\vspace{0.2cm}
\STATE{$v_t = w_t \oplus w_{t-1}$}
\vspace{0.2cm}
\STATE{$\Omega_t = \{ j/ v_t(j) = 1\}$
\textit{\scriptsize // define the changing elements set $\Omega_t$ from $s_{t-1}$ to $s_t$}
}
\vspace{0.2cm}
\STATE{$q_t = q_{t-1} + 2\displaystyle{\sum_{j \in \Omega_t}} p_j s_t(j)$}
\vspace{0.2cm}
\ELSE
\vspace{0.2cm}
\STATE{$q_t = P s_0$}
\vspace{0.2cm}
\STATE{$\mu = \dfrac{\epsilon_{tol}N}{\lVert q_0 \rVert_2}$}
\vspace{0.2cm}
\ENDIF
\vspace{0.2cm}
\STATE{$x_{t+1} = x_t - \mu \dfrac{\norm{x_t}{1}}{N} q_t$}
\vspace{0.2cm}
\STATE{$t = t+1$}
\vspace{0.2cm}
\ENDWHILE
\STATE{$\Lambda_K=\underset{K,\Psi}{\text{supp}}(x)$}
\STATE{$x \leftarrow F(x,\Lambda_K)$}
\end{algorithmic}
\end{algorithm}
}

• you can not put a float on a box, you could put the scalebox just around the algorthmic or better don't scale but use a smaller font such as \small or \footnotesize Feb 7, 2022 at 10:27

You can issue a \footnotesize instruction.

I provided a guess for the definition of \norm and also a simpler way to input comments in the style you seem to prefer.

Note \operatorname or \mathrm instead of \text.

\documentclass{article}
\usepackage{algorithm,algorithmic,amsmath}

\newcommand{\norm}[2]{\lVert#1\rVert_{#2}}
\newcommand{\algcomment}[1]{%
\mbox{\scriptsize\itshape // #1}%
}

\begin{document}

\begin{algorithm}[!htb]
\caption{Basis Pursuit solver}
\label{alg:L1}
\footnotesize
\begin{algorithmic}
\STATE{Input: $A = \Phi \Psi, \; y, \; K$}
\vspace{0.2cm}
\STATE{Inizialize:}
\vspace{0.2cm}
\STATE{%
$\begin{cases} P = [ p_1 \ldots p_N ], \; P = I - A^{\dagger} A, \\ x_0 = A^{\dagger} y \quad \algcomment{Compute with QR factorization} \\ t=0 \end{cases}$%
}
\vspace{0.2cm}
\STATE{Output: $K$-sparse coefficient vector $x$}
\vspace{0.2cm}
\WHILE {$t < \max\_{\mathrm{iter}}$}
\vspace{0.2cm}
\STATE{$s_t = \operatorname{sign}(x_t), \; w_t = (s_t+1)/2$
\algcomment{reduce $s_t$ to binary vector $w_t$}%
}
\vspace{0.2cm}
\IF{$t > 0$}
\vspace{0.2cm}
\STATE{$v_t = w_t \oplus w_{t-1}$}
\vspace{0.2cm}
\STATE{$\Omega_t = \{ j/ v_t(j) = 1\}$
\algcomment{define the changing elements set $\Omega_t$ from $s_{t-1}$ to $s_t$}%
}
\vspace{0.2cm}
\STATE{$q_t = q_{t-1} + 2\displaystyle{\sum_{j \in \Omega_t}} p_j s_t(j)$}
\vspace{0.2cm}
\ELSE
\vspace{0.2cm}
\STATE{$q_t = P s_0$}
\vspace{0.2cm}
\STATE{$\mu = \dfrac{\epsilon_{tol}N}{\lVert q_0 \rVert_2}$}
\vspace{0.2cm}
\ENDIF
\vspace{0.2cm}
\STATE{$x_{t+1} = x_t - \mu \dfrac{\norm{x_t}{1}}{N} q_t$}
\vspace{0.2cm}
\STATE{$t = t+1$}
\vspace{0.2cm}
\ENDWHILE
\STATE{$\Lambda_K=\underset{K,\Psi}{\operatorname{supp}}(x)$}
\STATE{$x \leftarrow F(x,\Lambda_K)$}
\end{algorithmic}
\end{algorithm}

\end{document}


I'd avoid all those \vspace instructions.