How to set theorem title in middle of box

The following MWE

\documentclass{book}
\usepackage[many]{tcolorbox}
%%%teorema%%%
\newtcolorbox{mybox}[1]{%
tikznode boxed title,
enhanced,
arc=0mm,
interior style={white},
attach boxed title to top center= {yshift=-\tcboxedtitleheight/2},
fonttitle=\bfseries,
colbacktitle=white,coltitle=black,
boxed title style={size=normal,colframe=white,boxrule=0pt},
title={#1}}
\newtheorem{theo}{}[chapter]
newenvironment{teo}
\begin{mybox}{Theorem  }\begin{theo}}
{\end{theo}\end{mybox}}
%%%fin teorema %%%
\begin{document}
\begin{teo}
Let $$V$$ be a vectorial space.
\end{teo}
\end{document}


produces the output

So the question is, How to get numeration and "Theorem" together in middle? also, if theorem has a name like \begin{teo}{Fermat Last Theorem} How to set this name in the actual position of the numeration, i.e inside the box?

Since there's nothing magical with a theorem (it just has a number and is printed out using italic) you can just drop the \newtheorem stuff and use only \newtcolorbox. The following code creates theorems in boxes (as far as I understand what you need):

\documentclass{book}
\usepackage{amsmath}
\usepackage[many]{tcolorbox}
%%%teorema%%%
\makeatletter
\newcounter{theo}
\numberwithin{theo}{chapter}
\newtcolorbox{theo}[1][]{%
tikznode boxed title,
enhanced,
arc=0mm,
interior style={white},
attach boxed title to top center= {yshift=-\tcboxedtitleheight/2},
fonttitle=\bfseries,
fontupper=\itshape,
colbacktitle=white,coltitle=black,
boxed title style={size=normal,colframe=white,boxrule=0pt},
title={Theorem \thetheo},
before title={\refstepcounter{theo}},
before upper={\def\temp{#1}\ifx\temp\empty\else\textbf{#1.} \fi
\def\@currentlabel{\p@theo\thetheo}}
}
\makeatother
%%%fin teorema %%%
\begin{document}
\begin{theo}
Let $$V$$ be a vectorial space.
\end{theo}
\begin{theo}[Cool theorem]
Let $$V$$ be a vectorial space.
\end{theo}
\end{document}


The result is:

It can be referenced in a common way using \label{} inside the theorem, and \ref{} for the actual reference.

• can this be referenced with a \label and \ref? if so, adding an example of that would be very helpful to the op and future readers. Commented Aug 12, 2017 at 0:23
• Apparently it wasn't, though meant to be. I've added a small hack which sets \@currentlabel in the theorem body, so it fixed now. Thank you for pointing this out. Commented Aug 12, 2017 at 4:37

Why don't you use the \newtcbtheorem command? In addition, it cooperates with cleveref:

\documentclass[svgnames]{book}
\usepackage[utf8]{inputenc}
\usepackage[many]{tcolorbox}
\usepackage{varwidth}
\usepackage{cleveref}

\tcbuselibrary{theorems}
\newtcbtheorem[number within=chapter, crefname={theorem}{theorems},Crefname={Theorem}{Theorems}]{Theo}{Theorem}%
%
{enhanced, frame empty, interior empty, arc=0mm,
coltitle=black, fonttitle=\bfseries, colbacktitle=white,
borderline={0.5mm}{0mm}{},%
attach boxed title to top center={yshift=\dimexpr-\tcboxedtitleheight/2},
boxed title style={boxrule=-1pt},varwidth boxed title,
fontupper=\itshape, }{Th}

\begin{document}

\setcounter{chapter}{3}

\begin{Theo}{}{test}
Let $V$ be a vector space.
\end{Theo}

\Cref{Th:test} is contained in \cref{Th:test} and conversely.

\end{document}