# tcbtheorem: Multiline centered title

I'm using the tcolorbox package for creating an algoritm environment. Now, in one algorithm, my title text spans two lines, and I'd like to have it centered. However, the second line is only centered under the title, but not the part "Algorithm 1:". I'd like to have this centered as if "Algorithm 1" was part of the text, but I don't see how I could achieve this.

A 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}


• I think you should not use newtcbtheorem for this but \newtcolorbox rather. The name for a theorem is set left (Algorithm) and is not part of the title here – user31729 Mar 2 '17 at 22:47
• Hmm...but this means that I can't keep the automatic numbering, does it? I'm using a numbering within chapters, so that I get Algorithm 1.1, Algorithm 1.2,... including the options for safely referencing the numbers. – proMath Mar 2 '17 at 22:56
• \newtcolorbox allows for autonumbering – user31729 Mar 2 '17 at 22:57
• Ah, okay, then I'll go to the manual and check it! Thanks! – proMath Mar 2 '17 at 22:59
• In fact, I think you're misusing the bundle of theorem name, number and description like a caption. – user31729 Mar 2 '17 at 23:16

The tcolorbox library for theorems does use the theorem title (Algorithm here) and fixes it to the left margin of the title. The real title (called 'description' is independent of this, so center title will only center the description but not the number and name of the environment.

Using a \newtcolorbox this can be fixed and almost the same features of the \newtcbtheorem command can be achieved.

\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}


• I'll try to find a cleaner way later on – user31729 Mar 2 '17 at 23:24