我希望我的算法的标题位于顶部并向左对齐:
\documentclass{article}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Sketch of our Compression Algorithm}
\label{fig:GENIDEA}
\begin{algorithmic}[1]
\While{Input contains characters}
\State Find matching reference block $B$ for current input position
\State Perform referential compression with respect to $B$ until we cannot find ``long'' matches anymore
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
\restylefloat
“on top” 可以通过使用包提供float
的选项来实现algorithm
。(不幸的是,algorithm
包没有提供plaintop
这个选项。)
可以使用包\captionsetup[algorithm]{...}
提供的实现“向左刷新” caption
。
\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
% Change float style of algorithm from "ruled" to "plaintop"
\floatstyle{plaintop}
\restylefloat{algorithm}
% Make algorithm captions left-aligned
\usepackage{caption}
\captionsetup[algorithm]{singlelinecheck=off}
\begin{document}
\begin{algorithm}
\caption{Sketch of our Compression Algorithm}
\label{fig:GENIDEA}
\begin{algorithmic}[1]
\While{Input contains characters}
\State Find matching reference block $B$ for current input position
\State Perform referential compression with respect to $B$ until we cannot find ``long'' matches anymore
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}
答案2
我找到了我自己问题的答案。
\documentclass{article}
\usepackage{floatrow}
\usepackage[plain]{algorithm}
\floatsetup[algorithm]{capposition=top}
\usepackage{caption}
\captionsetup[algorithm]{singlelinecheck=off}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Sketch of our Compression Algorithm}
\label{fig:GENIDEA}
\begin{algorithmic}[1]
\While{Input contains characters}
\State Find matching reference block $B$ for current input position
\State Perform referential compression with respect to $B$ until we cannot find ``long'' matches anymore
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}