在 LaTeX 中,Algorithm 环境默认会占据整栏的宽度。如果你想调整算法的宽度,可以使用 minipage 环境来控制其占用的空间。
原程序:
\begin{center} % center algorithm
% \begin{minipage}{.7\linewidth}
\begin{algorithm}[H]
\caption{The process of ......}\label{alg:alg2}
\begin{algorithmic}
\STATE
\STATE {\textsc{\bf Input: }}$a $;$b $;$c $;$\rho $;
\STATE $\text {1: } {\gamma}=\frac{a}{b}$
\STATE {\text{2: }}{\textsc{\bf repeat}}
\STATE {\text{3: }}$\textbf{ \ \ for } n\in\{0,1,\cdots,N-1\} \textbf{ do}$
\STATE $\text{4: } \ \ \ \ \ r_n=\frac{1}{\rho}(1-a^3) \text{ according to (12) }$
\STATE {\text{5: }}$\textbf{ \ \ end for }$
\STATE $\text{6: }\textbf{ \ \ } s=s+1$
\STATE {\text{7: }}{\textsc{\bf until}} $ \frac1s\gamma<r_n $
\STATE $\text{8: }\bm{\Re }=[\mathbf{R}_1,\mathbf{R}_2,\cdots,\mathbf{R}_S]$
\STATE $\bf{\text {\bf{Output: }}} \bm{\Re}$
\end{algorithmic}
\label{alg1}
\end{algorithm}
% \end{minipage}
\end{center}
修改后程序:
添加语句:
\begin{minipage}{.7\linewidth}
\end{minipage}
\begin{center} % center algorithm
\begin{minipage}{.7\linewidth}
\begin{algorithm}[H]
\caption{The process of ......}\label{alg:alg2}
\begin{algorithmic}
\STATE
\STATE {\textsc{\bf Input: }}$a $;$b $;$c $;$\rho $;
\STATE $\text {1: } {\gamma}=\frac{a}{b}$
\STATE {\text{2: }}{\textsc{\bf repeat}}
\STATE {\text{3: }}$\textbf{ \ \ for } n\in\{0,1,\cdots,N-1\} \textbf{ do}$
\STATE $\text{4: } \ \ \ \ \ r_n=\frac{1}{\rho}(1-a^3) \text{ according to (12) }$
\STATE {\text{5: }}$\textbf{ \ \ end for }$
\STATE $\text{6: }\textbf{ \ \ } s=s+1$
\STATE {\text{7: }}{\textsc{\bf until}} $ \frac1s\gamma<r_n $
\STATE $\text{8: }\bm{\Re }=[\mathbf{R}_1,\mathbf{R}_2,\cdots,\mathbf{R}_S]$
\STATE $\bf{\text {\bf{Output: }}} \bm{\Re}$
\end{algorithmic}
\label{alg1}
\end{algorithm}
\end{minipage}
\end{center}
显示效果对比:
注意:
- \begin{minipage}{.7\linewidth} 中数值大小可以更改实际宽度
- 环境位置使用H
- 使用默认的浮动环境位置,例如h、t、b等:在minipage环境外套一个figure环境:
\begin{figure}[htb]
\begin{minipage}{.7\linewidth}
\begin{algorithm}[H]
...
\end{figure}
参考链接:
LaTeX 算法环境宽度调整 Algorithm Width
在Latex使用minipage调整图伪代码宽度踩的坑
END
2024年9月3日11点06分