如何将定理标题设置在框中间

如何将定理标题设置在框中间

以下 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}

产生输出

输出

所以问题是,如何将数值和“定理”放在中间? 另外,如果定理有这样的名字\begin{teo}{Fermat Last Theorem} 如何在编号的实际位置(即框内)设置此名称?

答案1

由于定理没有什么神奇之处(它只是一个数字,用斜体打印出来),你可以放弃这些\newtheorem东西,只使用\newtcolorbox。以下代码在框中创建定理(据我了解你需要什么):

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

结果是:

定理

\label{}既可以作为定理内部的常用参考,也\ref{}可以作为实际参考。

答案2

为什么不使用命令\newtcbtheorem?此外,它还可以配合使用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} 

在此处输入图片描述

相关内容