我正在使用该tcolorbox
包创建algoritm
环境。现在,在一个算法中,我的标题文本跨越两行,我想让它居中。但是,第二行只在标题下方居中,而不是“算法 1:”部分。我想让它居中,就好像“算法 1”是文本的一部分一样,但我不知道如何实现这一点。
一位 MWE 表示:
\documentclass{standalone}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem{algorithm}{Algorithm}%
{
colback = white,
colbacktitle = white,
coltitle = black,
center title,
fonttitle = \bfseries,
sharp corners,
boxrule = 1pt,
titlerule = 1pt,
width = 0.8\linewidth,
center
}{}
\begin{document}
\begin{algorithm}{This is a very long title that causes a break}{}
\begin{center}
\textbf{Algorithm 1: This is the optics that I'd like to have, with the second line centered. }
\end{center}
\end{algorithm}
\end{document}
答案1
定理库tcolorbox
确实使用了定理标题(Algorithm
此处),并将其固定在标题的左边距。真正的标题(称为“描述”)与此无关,因此center title
只会将描述置于中心,而不会将环境的编号和名称置于中心。
使用这个可以修复并且可以实现\newtcolorbox
几乎相同的命令功能。\newtcbtheorem
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{hyperref}
\tcbuselibrary{theorems}
\newtcolorbox[auto counter]{algorithm}[3][]{%
colback = white,
colbacktitle = white,
coltitle = black,
center title,
fonttitle = \bfseries,
sharp corners,
boxrule = 1pt,
titlerule = 1pt,
width = 0.8\linewidth,
center,
title={Algorithm \thetcbcounter: #2},
label={#3},
#1
}
\begin{document}
See the nice Algorithm \ref{firstalgo}
\begin{algorithm}{This is a very long title that causes a break}{firstalgo}
\begin{center}
\textbf{Algorithm 1: This is the optics that I'd like to have, with the second line centered. }
\end{center}
\end{algorithm}
\end{document}