\newtheorem과 유사한 환경을 생성할 수 있는 명령을 어떻게 정의합니까?

\newtheorem과 유사한 환경을 생성할 수 있는 명령을 어떻게 정의합니까?

LaTeX 내장 명령이 \newtheorem유사한 일련의 정리 환경을 생성할 수 있다는 것은 잘 알려져 있습니다. 레이아웃 스타일의 동일한 테마를 공유하지만 이름과 카운터 스타일 등이 다릅니다.

Ti를 사용하여 멋진 스타일의 수업 노트를 출력하는 데 사용되는 컬러 텍스트 상자를 정의했습니다.케이최근에는 Z. 특정 스타일은 나 자신을 만족시키기도 했지만, 약간의 불편함도 안겨주었다. 예를 들어 정의, 보조정리, 결론 등을 서로 다르지만 비슷한 스타일로 넣고 싶기 때문에 이러한 환경을 10줄이 넘는 코드를 사용하여 하나씩 정의해야 합니다.

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

당신이 원하는 것은 색상과 스타일을 제어하기 위해 이름과 일부 설정을 취할 다른 매크로 안에 코드를 래핑하는 것입니다. 여기서는 대략적으로 \newtheoremand 을 흉내내려고 합니다 \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대신 with 로 참조됩니다 #1.

관련 정보