算法和表格都有水平线。如你所见,这些线有不同的线强度和间距。
我希望算法和其标题周围的水平线和间距与 的精美设计完全匹配booktabs
。
\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{booktabs}
\begin{document}
\begin{algorithm}
\caption{Euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\begin{table}
\centering
\begin{tabular}{ccc}
\toprule
First name & Last Name & Age \\
\midrule
John & Doe & 30 \\
John & Doe & 30 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
好主意!
我们可以通过修改来创建新的浮动样式ruled
:
\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{booktabs}
\makeatletter
\newcommand\fs@booktabsruled{%
\def\@fs@cfont{\bfseries\strut}\let\@fs@capt\floatc@ruled
\def\@fs@pre{\hrule height\heavyrulewidth depth0pt \kern\belowrulesep}%
\def\@fs@mid{\kern\aboverulesep\hrule height\lightrulewidth\kern\belowrulesep}%
\def\@fs@post{\kern\aboverulesep\hrule height\heavyrulewidth\relax}%
\let\@fs@iftopcapt\iftrue
}
\makeatother
\floatstyle{booktabsruled}
\restylefloat{algorithm}
\begin{document}
\begin{algorithm}
\caption{Euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\begin{table}
\centering
\begin{tabular}{ccc}
\toprule
First name & Last Name & Age \\
\midrule
John & Doe & 30 \\
John & Doe & 30 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}