使用套件algorithm2e
(带figure
选项)时标题,加上双面页面布局,每隔一页的标题缩进就会不正确。最小示例:
\documentclass{book}
\usepackage{caption}
\usepackage[english]{babel}
\usepackage[figure]{algorithm2e}
\begin{document}
test test test test test test test test test test test test test test test test
test test test test test test test test test test test test test test test test
\begin{algorithm}[bht]
\Return{$\epsilon$}\;
\caption{Example example example example example example example}
\end{algorithm}
\newpage
test test test test test test test test test test test test test test test test
test test test test test test test test test test test test test test test test
\begin{algorithm}[bht]
\Return{$\epsilon$}\;
\caption{Example example example example example example example}
\end{algorithm}
\end{document}
有谁知道如何解决这一问题?
答案1
这是特定于在选项下设置为figure
s 出现在反面(偶数)页面上的算法twoside
caption
已加载。环境似乎algorithm
需要针对这些特定情况反转默认边距调整。您可以手动执行此操作:
\documentclass{book}
\usepackage{caption}
\usepackage[figure]{algorithm2e}
\begin{document}
\noindent X \dotfill X
\begin{algorithm}
\caption{Example example example example example example example}
\end{algorithm}
\newpage
\noindent X \dotfill X
\begin{algorithm}
\captionsetup{margin={\algomargin,-\algomargin}}
\caption{Example example example example example example example}
\end{algorithm}
\end{document}
或者,您可以根据页面是奇数还是偶数来自动设置边距(请参阅如果则否则奇数页/偶数页)。加载后,将以下内容添加到您的序言中algorithm2e
:
\usepackage{changepage}
\strictpagecheck
\makeatletter
\let\old@algocf@init\@algocf@init
\renewcommand{\@algocf@init}{%
\ifnum\pdfstrcmp{\algocf@float}{figure}=0
\ifalgocf@figurecaption
\checkoddpage
\ifoddpage
\captionsetup{margin={-\algomargin,\algomargin}}% Odd page
\else
\captionsetup{margin={\algomargin,-\algomargin}}% Even page
\fi
\fi
\fi
\old@algocf@init}
\makeatother