我对算法环境中标题的对齐方式有疑问。例如,以下代码示例
\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithm}[t]
\caption{Text Text\newline Text}
\begin{algorithmic}[1]
\State bla
\end{algorithmic}
\end{algorithm}
\end{document}
生产
但是,第三个“文本”应该直接位于第一个“文本”下方。我该如何实现这一点?
答案1
您可以使用caption
具有悬挂缩进样式的包,如下所示:
\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{caption}
\captionsetup[algorithm]{format=hang,singlelinecheck=false}
\begin{document}
\begin{algorithm}[t]
\caption{Text Text\newline Text}
\begin{algorithmic}[1]
\State bla
\end{algorithmic}
\end{algorithm}
\begin{algorithm}[t]
\caption{Text text text text text text text text text text text text
text text text text text text text text text text text text\newline
More text}
\begin{algorithmic}[1]
\State bla
\end{algorithmic}
\end{algorithm}
\end{document}
答案2
加载caption
包并声明:
\DeclareCaptionFormat{custom}{%
\begin{minipage}[t]{0.2\linewidth}\vspace*{0pt}#1#2\end{minipage}%
\begin{minipage}[t]{0.8\linewidth}\vspace*{0pt}#3\end{minipage}%
}
在那之后,
\captionsetup[algorithm]{format=custom}
梅威瑟:
\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{caption}
\DeclareCaptionFormat{custom}{%
\begin{minipage}[t]{0.2\linewidth}\vspace*{0pt}#1#2\end{minipage}%
\begin{minipage}[t]{0.8\linewidth}\vspace*{0pt}#3\end{minipage}%
}
\captionsetup[algorithm]{format=custom}
\begin{document}
\begin{algorithm}[t]
\caption{Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text\newline Text on a new line}
\begin{algorithmic}[1]
\State bla
\end{algorithmic}
\end{algorithm}
\end{document}