Latex 调整大小算法

Latex 调整大小算法

我必须调整 Latex 中的算法的大小。我尝试过\resizebox\scalebox但出现此错误:

Error: Not in outer par mode

有人有建议吗?

以下是代码

\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}
}

答案1

您可以发出\footnotesize指令。

我提供了对定义的猜测,\norm以及以您喜欢的样式输入评论的更简单的方法。

注意\operatorname\mathrm代替\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}

在此处输入图片描述

我会避免所有这些\vspace指示。

相关内容