制作用于定义样式的样式文件

制作用于定义样式的样式文件

如何在样式文件的定义中包含以下样式?我正在使用包xcolor(带有选项x11namesamsmath、、amsthmamssymb


    \newtheoremstyle{typex-definition} % name of style
    {8pt}       % measure of space above definition, e.g. {3pt}
    {8pt}       % measure of space below definition, e.g. {3pt}
    {\itshape}  % name of font for body of example
    {}          % measure of space to indent, e.g. {3pt}
    {\bfseries\itshape}           % name of font for heading
    {\textcolor{DarkOrange3}{.}}  % punctuation between heading and body
    { }         % space after theorem heading
    {\thmname{\textbf{\textit{#1}}}
     \textcolor{DarkOrange3}{\textbf{\thmnumber{#2}}}
     \thmnote{\textit{({#3})}} }
    
    \theoremstyle{typex-definition}
    \newtheorem{definition}{\textcolor{Blue3}{Definition}}[section]

答案1

\newtheoremstyle将声明放在文件中与否都没有区别.sty,因此我将使用文档序言中的声明作为示例。

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[x11names]{xcolor}

% this can go in a .sty file, but it's not necessary

\newtheoremstyle{typex-definition} % name of style
  {8pt}       % measure of space above definition, e.g. {3pt}
  {8pt}       % measure of space below definition, e.g. {3pt}
  {\itshape}  % name of font for body of example
  {}          % measure of space to indent, e.g. {3pt}
  {\bfseries\itshape}           % name of font for heading
  {\textcolor{DarkOrange3}{.}}  % punctuation between heading and body
  { }         % space after theorem heading
  {%
   \thmname{#1}% heading
   \thmnumber{ \textcolor{DarkOrange3}{#2}}% number
   \thmnote{ {\normalfont\itshape(#3)}}%
 }

\theoremstyle{typex-definition}
\newtheorem{definition}{\textcolor{Blue3}{Definition}}[section]
\newtheorem*{altdefinition}{\textcolor{Blue3}{Definition}}

\begin{document}

\begin{definition}
This is the text of the definition.
\end{definition}

\begin{definition}[Some name]
This is the text of the definition.
\end{definition}

\begin{altdefinition}
This is the text of the definition.
\end{altdefinition}

\begin{altdefinition}[Some name]
This is the text of the definition.
\end{altdefinition}

\end{document}

我修复了一些细节:将数字与标题分开的空格以及注释前面的空格应该放在和的参数中\thmnumber\thmnote否则如果没有数字或没有注释,这些空格将被无条件添加,请参阅未编号altdefinition以查看它。

您不需要\textbf\textit,因为它们已经被设置了\bfseries\itshape

在此处输入图片描述

答案2

可能与此类似,大卫·卡莱尔在上面命令的注释中\ProvidesPackage,“将包含包名称和版本的有用消息放入日志文件中,这对于调试很有用”,尽管这不是必需的:

\ProvidesPackage{CustTheorem}[2022/04/25 Custom Theorem Style]

\usepackage[x11names]{xcolor}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}

\newtheoremstyle{typex-definition} % name of style
{8pt}       % measure of space above definition, e.g. {3pt}
{8pt}       % measure of space below definition, e.g. {3pt}
{\itshape}  % name of font for body of example
{}          % measure of space to indent, e.g. {3pt}
{\bfseries\itshape}           % name of font for heading
{\textcolor{DarkOrange3}{.}}  % punctuation between heading and body
{ }         % space after theorem heading
{\thmname{\textbf{\textit{#1}}}
\textcolor{DarkOrange3}{\textbf{\thmnumber{#2}}}
\thmnote{\textit{({#3})}} }
  
\theoremstyle{typex-definition}
\newtheorem{definition}{\textcolor{Blue3}{Definition}}[section]

其他人可能会有更好的答案,所以请稍等片刻,看看是否有人建议更好的答案。使用加载包\usepackage{CustTheorem)并将文件另存为CustTheorem.sty或您想要更改的名称(确保将名称更改\ProvidesPackage{}为相同的名称)。这里有关于将自定义.sty文件放在哪里以便 Latex 可以找到它们而不必将文件放在与文档相同的文件夹中的答案,如果您找不到它们,请发表评论,我会为您找到最近的一个来帮助您。

相关内容