我需要在我的算法中将字幕大小减小到脚本大小。我找不到合适的答案。这是我的代码的 MW E:
\documentclass[12pt,a4paper]{book}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{caption}
\begin{algorithm}
\caption{GenerateGraph(schema)}
\scriptsize
\begin{algorithmic}[1]
....
\end{algorithmic}
\end{algorithm}
另外,有没有办法减少数字大小?(它们看起来比文本大)我已将我的算法附在下面。非常感谢您的帮助。
答案1
这个问题已经有一个很好的答案了,我不清楚为什么它被删除了...:-( 不过,既然它已被删除,我会尝试自己回答:
使用caption
包可以设置标题的字体大小\captionsetup{font=scriptsize}
:
\documentclass[12pt,a4paper]{book}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{caption}
\begin{document}
\begin{algorithm}
\captionsetup{font=scriptsize} % set size of caption font
\caption{Euclid’s algorithm}
\scriptsize % set size of algorithm itself
\begin{algorithmic}[1] % example taken from the algorithmicx documentation
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Euclid’s algorithm}
\begin{algorithmic}[1] % example taken from the algorithmicx documentation
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
(由于\captionsetup{font=scriptsize}
应用于 内部algorithm
,因此它仅影响当前algorithm
。)
没有caption
包时,宏\floatc@ruled
用于排版算法标题,因此可以修补它以应用于\scriptsize
以下算法(仅限):
\documentclass[12pt,a4paper]{book}
\usepackage{algorithm}
\usepackage{algpseudocode}
\makeatletter
\newcommand\setalgorithmcaptionfont[1]{%
\let\my@floatc@ruled\floatc@ruled % save \floatc@ruled
\def\floatc@ruled{%
\global\let\floatc@ruled\my@floatc@ruled % restore \floatc@ruled
#1\floatc@ruled}}
\makeatother
\begin{document}
\setalgorithmcaptionfont{\scriptsize} % set size of next algorithm caption font
\begin{algorithm}
\caption{Euclid’s algorithm}
\scriptsize % set size of algorithm itself
\begin{algorithmic}[1] % example taken from the algorithmicx documentation
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Euclid’s algorithm}
\begin{algorithmic}[1] % example taken from the algorithmicx documentation
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}