我有简单的代码:
\documentclass{article} \usepackage{algorithm} \usepackage{algpseudocode} \begin{document} \begin{algorithm} \caption{Examples}\label{alg:Examples} \begin{algorithmic}[1] \State $X=45$ \State $X=45$ \State $X=45$ \State $X=45$ \State $X=45$ \end{algorithmic} \end{algorithm} \end{document}
如何在算法的数字后面加一个点?
我使用的章节如下
report
:\documentclass[a4paper,12pt]{report} \usepackage{algorithm} \usepackage{algpseudocode} \begin{document} \chapter{Chapter 1} \begin{equation} X_2=4 \end{equation} \begin{algorithm} \caption{Examples}\label{alg:Examples} \begin{algorithmic}[1] \State $X=45$ \State $X=45$ \State $X=45$ \State $X=45$ \State $X=45$ \end{algorithmic} \end{algorithm} \end{document}
如何更改编号以考虑章节?
答案1
这里的最终目标似乎是<chapter>.<algorithm>.
在算法标题内进行编号,但要有<chapter>.<algorithm>
编号以供参考。caption
包裹可以在这里帮助设置labelsep
为period
:
\documentclass{report}
\usepackage{algorithm,algpseudocode}% http://ctan.org/pkg/{algorithms,algorithmicx}
\usepackage{caption}% http://ctan.org/pkg/caption
\captionsetup[ruled]{labelsep=period}
\makeatletter
\@addtoreset{algorithm}{chapter}% algorithm counter resets every chapter
\makeatother
\renewcommand{\thealgorithm}{\thechapter.\arabic{algorithm}}% Algorithm # is <chapter>.<algorithm>
\begin{document}
\chapter{A chapter}
\begin{algorithm}
\caption{Examples}\label{alg:Examples}
\begin{algorithmic}[1]
\State $X=45$
\State $X=45$
\State $X=45$
\State $X=45$
\State $X=45$
\end{algorithmic}
\end{algorithm}
See Algorithm~\ref{alg:Examples}.
\end{document}
之所以不直接重新定义\thealgorithm
为包含尾随句点,是因为否则在引用算法时会包含尾随句点,这可能会导致问题。算法编号重置计划在每一章进行。