将算法标题标签颜色更改为蓝色和粗体斜体

将算法标题标签颜色更改为蓝色和粗体斜体

我想知道如何将算法标题标签更改为蓝色和粗体斜体。到目前为止,我已经能够将标题名称更改为蓝色,但我无法将算法标题标签更改为粗体和斜体。这是我目前拥有的代码:

\documentclass{article}
\usepackage{amsmath, amsfonts, amssymb, amsthm, bm}
\usepackage{commath}
\usepackage{xcolor}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\SetAlgoCaptionSeparator{.}
\renewcommand\AlCapFnt{\textit\textbf\color{blue}}
\usepackage[font={color=mybluei,bf,it},figurename=Fig.,labelfont={it}]{caption}
\begin{document}
\begin{center}
\colorbox[gray]{0.95}{
\begin{minipage}{0.65\textwidth}
\SetAlgoLined
\SetNlSty{textbf}{}{:}
\begin{algorithm}[H]
\DontPrintSemicolon
This is line one\\
This is line two numbered\\
This should be numbered\\
This should also be numbered
\caption{Unnumbered lines}
\end{algorithm} 
\end{minipage}} 
\end{center}

\end{document} 

答案1

algorithm2e\caption格式如下:

\AlCapSty{\AlCapFnt Algorithm 1:}\AlCapNameSty{\AlCapNameFnt my algorithm}

摘自“变更日志”:

默认情况下,\AlCapSty\textbf\AlCapFnt什么都不做。\AlCapNameSty保持文本原样,也不\AlCapNameFnt执行任何操作。您可以通过将宏赋予命令来重新定义\AlCapFnt和。例如,您可以执行以查看字体打印的算法。\AlCapNameFnt\Set...\SetAlCapFnt{\large}\large

您可以使用相应的命令重新定义\AlCapSty\AlCapFnt和。对于这些命令,您必须给出一个宏的参数名称(不带\AlCapNameSty),该宏带有一个参数。例如,定义默认行为。如果您想做更复杂的事情,您应该定义自己的宏并将其提供给或。以下是两个示例:\AlCapNameFnt\Set...\...Sty\\SetAlCapFnt{textbf}\SetAlCapFnt\SetAlCapNameFnt

\newcommand{\mycapsty}[1]{\tiny #1}\SetAlCapNameSty{mycapsty}
\newcommand{\mycapsty}[1]{\textsl{\small #1}}\SetAlCapNameSty{mycapsty}

或者你可以将两者结合起来,对于最后一个例子,你也可以这样做:

\SetAlCapNameSty{textsl}\SetAlCapNameFnt{\small}

通过以上信息,以下内容可提供您所追求的内容:

\renewcommand\AlCapFnt{\itshape\bfseries\color{blue}}
\renewcommand\AlCapNameFnt{\AlCapFnt}

在此处输入图片描述

\documentclass{article}

\usepackage{xcolor}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}

% \AlCapSty{\AlCapFnt Algorithm 1:}\AlCapNameSty{\AlCapNameFnt my algorithm}
\renewcommand\AlCapFnt{\itshape\bfseries\color{blue}}
\renewcommand\AlCapNameFnt{\AlCapFnt}

\begin{document}

\begin{algorithm}
  \DontPrintSemicolon
  This is line one \;
  This is line two numbered \;
  This should be numbered \;
  This should also be numbered
  \caption{Unnumbered lines}
\end{algorithm} 

\end{document}

答案2

\caption命令行改为\caption{\color{blue} \textbf{\textit{Unnumbered lines}}}并编译,你将得到:

蓝色标题

相关内容