我认为这个简单的代码片段可以定义我的问题:
\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage[margin=28mm
]{geometry}
\usepackage{amsmath,amssymb,amsthm,mathpazo}
\usepackage{titlesec}
% ___Theorem box. Box with shaded left margin. By Spiritualis.
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\definecolor{mygrey}{RGB}{127,127,127}
\newtcolorbox[auto counter, number within=section]{mytheorem}[1][]
{
enhanced jigsaw,colback=white,colframe=mygrey,coltitle=mygrey,coltext=darkgray,
fonttitle=\bfseries,
sharp corners,
detach title,
leftrule=16mm,
underlay unbroken and first={\node[below,text=white,font=\bfseries,align=center]
at ([xshift=-8mm,yshift=-1mm]interior.north west) {\rotatebox{90}{Theorem \thetcbcounter}};},
breakable,pad at break=1mm,
#1,
code={\ifdefempty{\tcbtitletext}{}{\tcbset{before upper={\tcbtitle\par\medskip}}}},
}
%__________________________________________________
% ---------------------------------=oo0oo=---------------------------------
\begin{document}
% Section style definition
\titleformat{\section}
{\normalsize \bfseries}
{\color{black} \S \hspace{.6pt} \thesection}
{1ex}{\color{black}}[\quad]
% Subsection style definition
\titleformat{\subsection}
{\normalsize \bfseries}
{\color{black} $ \bullet $ \thesubsection}
{1ex}{\color{black}}[\quad]
\renewcommand\thepart{\Roman{part}.}
\renewcommand\thesection{\thechapter.\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
\section{Test for the format outside mytheorem box.}
\subsection{My format for subsections.\\
}
But inside mytheorem box...
\\
\section{Test for the format inside mytheorem box.
}
\begin{mytheorem}[title=Fundamental theorem for polygonal orthotransforms.]
\lipsum[2]
\end{mytheorem}
\vspace{2ex}
Why is the title format inside the box like this: Theorem 0.2..1?\\
Why is the title of the section \S \ 0.2 outside the left margin?
\end{document}
答案1
更新
试试这个代码。定义number freestyle
格式化定理数。
\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage[margin=28mm
]{geometry}
\usepackage{amsmath,amssymb,amsthm,mathpazo}
\usepackage{titlesec}
% ___Theorem box. Box with shaded left margin. By Spiritualis.
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\definecolor{mygrey}{RGB}{127,127,127}
\newtcolorbox[auto counter, number within=section,
number freestyle={\noexpand\thesection\noexpand\arabic{\tcbcounter}}]{mytheorem}[1][]% added <<<<<<<<<<<<<<<<<<<<<<<<<<
{
enhanced jigsaw,colback=white,colframe=mygrey,coltitle=mygrey,coltext=darkgray,
fonttitle=\bfseries,
sharp corners,
detach title,
leftrule=16mm,
underlay unbroken and first={\node[below,text=white,font=\bfseries,align=center]
at ([xshift=-8mm,yshift=-1mm]interior.north west) {\rotatebox{90}{Theorem \thetcbcounter}};},
breakable,pad at break=1mm,
#1,
code={\ifdefempty{\tcbtitletext}{}{\tcbset{before upper={\tcbtitle\par\medskip}}}},
}
%__________________________________________________
% ---------------------------------=oo0oo=---------------------------------
\begin{document}
% Section style definition
\titleformat{\section}
{\normalsize \bfseries}
{\color{black} \S \hspace{.6pt} \thesection}
{1ex}{\color{black}}[\quad]
% Subsection style definition
\titleformat{\subsection}
{\normalsize \bfseries}
{\color{black} $ \bullet $ \thesubsection}
{1ex}{\color{black}}[\quad]
\renewcommand\thepart{\Roman{part}.}
\renewcommand\thesection{\thechapter.\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
\section{Test for the format outside mytheorem box.}
\subsection{My format for subsections.\\
}
But inside mytheorem box...
\\
\section{Test for the format inside mytheorem box.
}
\begin{mytheorem}[title=Fundamental theorem for polygonal orthotransforms.]
\lipsum[2]
\end{mytheorem}
\vspace{2ex}
Why is the title format inside the box like this: Theorem 0.2..1?\\
Why is the title of the section \S \ 0.2 outside the left margin?
\end{document}
试试这个代码。自由定义数字来格式化定理数字。
答案2
\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage[margin=28mm
]{geometry}
\usepackage{amsmath,amssymb,amsthm,mathpazo}
\usepackage{titlesec}
% ___Theorem box. Box with shaded left margin. By Jesús Álvarez Lobo.
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\definecolor{graytitle}{RGB}{127,127,127}
\definecolor{graytext}{RGB}{121,121,121}
\newtcolorbox[auto counter, number within=section,
number freestyle={ \noexpand\thesection\noexpand\arabic{\tcbcounter}.}]{mytheorem}[1][] % added by Simon Dispa <<<
{
enhanced jigsaw,colback=white,colframe=graytitle,coltitle=graytitle,coltext=graytext,
fonttitle=\bfseries,
sharp corners,
detach title,
leftrule=16mm,
underlay unbroken and first={\node[below,text=white,font=\bfseries,align=center]
at ([xshift=-8mm,yshift=-1mm]interior.north west) {\rotatebox{90}{$ \bullet $ Theorem \thetcbcounter}};},
breakable,pad at break=1mm,
#1,
code={\ifdefempty{\tcbtitletext}{}{\tcbset{before upper={\tcbtitle\par\medskip}}}},
}
%__________________________________________________
% ---------------------------------=oo0oo=---------------------------------
\begin{document}
% Section style definition
\titleformat{\section}
{\normalsize \bfseries}
{\color{black} \S \hspace{.6pt} \thesection}
{1ex}{\color{black}}[\quad]
% Subsection style definition
\titleformat{\subsection}
{\normalsize \bfseries}
{\color{black} $ \bullet $ \thesubsection}
{1ex}{\color{black}}[\quad]
\renewcommand\thepart{\Roman{part}.}
\renewcommand\thesection{\thechapter.\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
\section{Test for the format outside mytheorem box.}
\subsection{My format for subsections.\\
}
But inside mytheorem box...
\\
\section{Test for the format inside mytheorem box.
}
\begin{mytheorem}[title=Fundamental theorem for polygonal orthotransforms.]
\lipsum[2]
\end{mytheorem}
\end{document}