\newtheorem と同様の環境を生成できるコマンドを定義するにはどうすればよいでしょうか?

\newtheorem と同様の環境を生成できるコマンドを定義するにはどうすればよいでしょうか?

LaTeX の組み込みコマンドが、\newtheoremレイアウト スタイルのテーマは同じですが、名前やカウンター スタイルなどが異なる、類似した一連の定理環境を生成できることはよく知られています。

Tiを使用して、派手なスタイルの授業ノートを出力するために使用される色付きのテキストボックスを定義しました。最近、Z を使い始めました。特定のスタイルは私自身は満足していましたが、ある種の不便さももたらしました。たとえば、定義、補題、結論を、異なるが類似したスタイルにしたいので、10 行を超えるコードを使用して、そのような環境を 1 つずつ定義する必要があります。

MWEはこちらです:

\documentclass{book}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{environ}
\usepackage{amsmath,mathrsfs,amsfonts}

\usetikzlibrary{shapes,decorations}
\definecolor{bule}{RGB}{18,29,57}
\definecolor{bablue}{RGB}{248,248,248}
\definecolor{main}{RGB}{127,191,51}
\definecolor{seco}{RGB}{0,145,215}
\definecolor{thid}{RGB}{180,27,131}

%define the style of tikz newthemsty
\tikzstyle{newthemsty} 
          =[draw=seco, fill=blue!10,very thick,rectangle,
           rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{newthemstytitle}
          =[fill=seco, text=blue!10]

%%define the "newthem" environment
\newcounter{Newthem}[chapter]
\renewcommand{\theNewthem}{\thechapter.\arabic{Newthem}}
\NewEnviron{newthem}[1][{}]{%
\noindent\centering
\begin{tikzpicture}
\node[newthemsty] (box){
     \begin{minipage}{0.93\columnwidth}
        \sffamily\BODY
     \end{minipage}};
\node[newthemstytitle,right=10pt] at (box.north west){
     \bfseries\textsf{Theorem \stepcounter{Newthem}\theNewthem\; #1}};
\node[newthemstytitle, rounded corners] at (box.east) {$\clubsuit$};
\end{tikzpicture}
}[\par\vspace{.5\baselineskip}]

\begin{document}

\begin{newthem}
    test
\end{newthem}

\end{document}

出力は次のようになります。

ここに画像の説明を入力してください

このような環境を定義できるコマンドが必要で、色 (背景と端)、フォントの形状 (斜体または直立)、シリーズ (太字またはそれ以外)、ラベル内の名前 (ここでは「定理」とします)、カウンター (別のカウンター内またはカウンターなし) を変更できる場合は、どうすればよいでしょうか。

手がかりやヒントがあれば、ぜひ教えてください。

答え1

やりたいことは、名前と色とスタイルを制御するためのいくつかの設定を受け取る別のマクロ内にコードをラップすることです。ここでは、\newtheoremと を大まかに模倣しようとしています\theoremstyle

\documentclass{book}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{environ}
\usepackage{amsmath,mathrsfs,amsfonts}
\usepackage{xparse}

\usetikzlibrary{shapes,decorations}
\definecolor{bule}{RGB}{18,29,57}
\definecolor{bablue}{RGB}{248,248,248}
\definecolor{main}{RGB}{127,191,51}
\definecolor{seco}{RGB}{0,145,215}
\definecolor{thid}{RGB}{180,27,131}


\newcommand{\newfancytheoremstyle}[5]{%
  \tikzset{#1/.style={draw=#3, fill=#2,very thick,rectangle,
      rounded corners, inner sep=10pt, inner ysep=20pt}}
  \tikzset{#1title/.style={fill=#3, text=#2}}
  \expandafter\def\csname #1headstyle\endcsname{#4}
  \expandafter\def\csname #1bodystyle\endcsname{#5}
}

\newfancytheoremstyle{fancythrm}{blue!10}{seco}{\bfseries\sffamily}{\sffamily}

\makeatletter
\DeclareDocumentCommand{\newfancytheorem}{ O{\@empty} m m m O{fancythrm} }{%
  % define the counter for the theorem
  \ifx#1\@empty
    \newcounter{#2}
  \else
    \newcounter{#2}[#1]
    \numberwithin{#2}{#1}
  \fi
  %% define the "newthem" environment
  \NewEnviron{#2}[1][{}]{%
    \noindent\centering
    \begin{tikzpicture}
      \node[#5] (box){
        \begin{minipage}{0.93\columnwidth}
          \csname #5bodystyle\endcsname \BODY~##1
        \end{minipage}};
      \node[#5title, right=10pt] at (box.north west){
        {\csname #5headstyle\endcsname #3 \stepcounter{#2}\csname the#2\endcsname\; ##1}};
      \node[#5title, rounded corners] at (box.east) {#4};
    \end{tikzpicture}
  }[\par\vspace{.5\baselineskip}]
}
\makeatother

% Define new styles
% \newfancytheoremstyle{<name>}{inner color}{outer color}{head style}{body style}
\newfancytheoremstyle{fancydef}{green!10}{green}{\itshape\sffamily}{\sffamily}

% Define some new environments
% \newfancytheorem[<number within>]{<name>}{<head>}{<symbol>}[<style>]
\newfancytheorem[chapter]{newthem}{Theorem}{$\clubsuit$}
\newfancytheorem[section]{newcor}{Corollary}{$\heartsuit$}

\newfancytheorem{newdef}{Definition}{$\spadesuit$}[fancydef]

\begin{document}

\begin{newthem}
    test
\end{newthem}

\begin{newcor}
  test
\end{newcor}

\begin{newdef}
  test
\end{newdef}

\end{document}

出力

マクロを使用して\newfancytheoremstyleスタイル (色とフォント) を定義し、 \newfancytheorem新しい環境を定義します。複数のオプション引数を処理するために を使用しています。「内部」環境の引数はではなくxparseで参照されることに注意してください。##1#1

関連情報