更改算法标题的字体大小时行距错误

更改算法标题的字体大小时行距错误

我正在使用该algorithm2e软件包,想更改图形标题和算法标题的字体大小。问题是,这两种方法的行距不同(算法标题的间距太大)。目标是让两个标题看起来一样。下面是一个最小的工作示例。

\documentclass{book}

\usepackage{caption}
\usepackage{algorithm2e}

\captionsetup{font=footnotesize}

\SetAlCapNameFnt{\footnotesize}
\SetAlCapFnt{\footnotesize}

\begin{document}

\begin{algorithm}[h]
\caption{Some very very long caption that illustrates the problem. Some very very long caption that illustrates the problem. Some very very long caption that illustrates the problem. Some very very long caption that illustrates the problem.}
\end{algorithm}

\begin{figure}[h]
\caption{Some very very long caption that illustrates the problem. Some very very long caption that illustrates the problem. Some very very long caption that illustrates the problem. Some very very long caption that illustrates the problem.}
\end{figure}

\end{document}

答案1

快速评估显示,字幕的重新定义来自algorithm2e并且设置其格式的能力在切换字体时可能会产生冲突的结果。\endgraf在标题末尾插入可恢复与当前字体相关的行距。这是通过使用补丁实现的etoolbox

补丁前:

在此处输入图片描述

补丁之后:

在此处输入图片描述

\documentclass{book}
\usepackage{etoolbox,caption,algorithm2e}% http://ctan.org/pkg/{etoolbox,caption,algorithm2e}
\makeatletter
\patchcmd{\algocf@latexcaption}{#3}{#3\endgraf}{}{}
\makeatother
\captionsetup{font=footnotesize}

\SetAlCapNameFnt{\footnotesize}
\SetAlCapFnt{\footnotesize}

\begin{document}
\begin{algorithm}[h]
\caption{Some very very long caption that illustrates the problem. 
  Some very very long caption that illustrates the problem. 
  Some very very long caption that illustrates the problem. 
  Some very very long caption that illustrates the problem.}
\end{algorithm}

\begin{figure}[h]
\caption{Some very very long caption that illustrates the problem. 
  Some very very long caption that illustrates the problem. 
  Some very very long caption that illustrates the problem. 
  Some very very long caption that illustrates the problem.}
\end{figure}

\end{document}

相关内容