我想创建类似的东西:
这张照片的代码
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{stix}
\usepackage{tcolorbox}
% (Re)newcommands
\renewcommand\qedsymbol{$\blacksquare$}
% New counters
\newcounter{boxtheorem}[subsection]
\newenvironment{boxtheorem}[1][]{\refstepcounter{boxtheorem}\par\medskip \textbf{Theorem --- \colorbox{orange} {\theboxtheorem.} #1} \rmfamily}{\medskip}
\newtheorem{theorem}{Theorem}[subsection]
% New Theorems
\newcommand{\tcbnamedtheoremname}{
\begin{tcolorbox}[colback=gray!40,colframe=red]{
\newtheorem{tcbnamedtheoreminner}[boxtheorem]{\protect\tcbnamedtheoremname}
\newenvironment{tcbnamedtheorem}[1]
{%
\renewcommand{\tcbnamedtheoremname}{#1}%
\begin{tcbnamedtheoreminner}%
}
{\end{tcbnamedtheoreminner}}}
\end{tcolorbox}}
% My Book
\title{Theorem Proof, Stack}
\author{Name, Surname}
\begin{document}
\maketitle
\Large
\chapter{First Chapter}
\section{Theorems}
\subsection{Colorboxed Theorems}
The \LaTeX--funcion in rows 19--26 makes this:
\begin{tcbnamedtheorem}{Cauchy--Lipschitz}
Statement.
\begin{proof}
Its Proof.
\end{proof}
\end{tcbnamedtheorem}
\flushleft{}But I'd like to have this:
\begin{tcolorbox}[colback=gray!40,colframe=red]
{\textbf{Theorem --- \colorbox{orange}{1.1.1.1.}}
Statement.}
\end{tcolorbox}
\begin{proof}
Its Proof.
\end{proof}
\end{document}
我的目标是使用 创建一种新风格的定理tcolorbox
。
我不明白我创建 tex 函数哪里错了。
今天的第一篇编辑:“Overleaf”告诉我此代码有三个错误:
(1) \tcbnamedtheoremname 定义中的参数数量非法。Main Tex, 31
(2)LaTeX 错误:环境 tcbnamedtheorem 未定义。主 Tex,50
(3)LaTeX 错误:\begin{document} 以 \end{tcbnamedtheorem} 结束。Main Tex, 55
我希望通过这次编辑,我的问题会更加清楚。
答案1
当有一个定理标题时,你不太清楚该做什么以及你想在哪里得到证明。
这是我的例子:
\documentclass{book}
%\usepackage[utf8]{inputenc} <-- no more needed
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{stix}
\usepackage[most]{tcolorbox}
% (Re)newcommands
\renewcommand\qedsymbol{$\blacksquare$}
% New Theorems
\newtcolorbox[auto counter, number within=subsection
]{tcbnamedtheorem}[2][]{%
enhanced,
toptitle=2mm,
colback=gray!40,colframe=red,
coltitle=black,
colbacktitle=gray!40,
detach title,before upper={\tcbtitle\ },
title={\textbf{Theorem --- \colorbox{orange}{\thetcbcounter.}}\ifstrempty{#2}{\ignorespaces}{~#2.}},
#1
}
% My Book
\title{Theorem Proof, Stack}
\author{Name, Surname}
\begin{document}
\maketitle
\chapter{First Chapter}
\section{Theorems}
\subsection{Colorboxed Theorems}
Theorem with title and proof in the box
\begin{tcbnamedtheorem}{Cauchy--Lipschitz}
Statement.
\begin{proof}
Its Proof.
\end{proof}
\end{tcbnamedtheorem}
\noindent Theorem with title and proof out of the box
\begin{tcbnamedtheorem}{Cauchy--Lipschitz}
Statement.
\end{tcbnamedtheorem}
\begin{proof}
Its Proof.
\end{proof}
\noindent Theorem without title and proof in the box
\begin{tcbnamedtheorem}{}
Statement.
\begin{proof}
Its Proof.
\end{proof}
\end{tcbnamedtheorem}
\noindent Theorem without title and proof out of the box
\begin{tcbnamedtheorem}{}
Statement.
\end{tcbnamedtheorem}
\begin{proof}
Its Proof.
\end{proof}
\end{document}