我必须调整 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
指示。