我试图创造一个这样的环境定理。以下是我迄今为止尝试过的:
\documentclass{article}
\usepackage{xifthen}
\newcounter{numdef}[subsection]
\setcounter{numdef}{0}
\renewcommand\thenumdef{\arabic{numdef}}
\newenvironment{ntdef}[1][]{
\vspace*{.2em}
\newcommand\makedef{\stepcounter{numdef}
\textit{Definition}\ \thesubsection.\thenumdef:
}
\noindent\makedef
}{\par\vspace{.2em}}
\begin{document}
\section{A}
\subsection{B}
\noindent\textit{Definition}\ 1.1.0\ \textit{(Definition 1)}: This is a template\par
\begin{ntdef}[Definition 1]
This is the first difinition
\end{ntdef}
\begin{ntdef}
This is the second difinition
\end{ntdef}
\end{document}
我使用纯文本向模板展示我所认为的前两行所显示的内容。
在我的项目中,环境应该有一个可选参数(为了显示更清晰,我已将显示给定参数的函数移至此测试项目中)。当没有给出选项时,环境工作正常。但是一旦我在选项中给出了名称,水平方向就会出现一个意外的空白,如第二行所示。
是什么原因导致了这个奇怪的问题?
答案1
我不确定为什么不使用\newtheorem
。无论如何,您需要删除空格和您想要的\addvspace
而不是\vspace
,以免累积垂直间距。
\documentclass{article}
\usepackage{xifthen}
\newcounter{numdef}[subsection]
\setcounter{numdef}{0}
\renewcommand\thenumdef{\arabic{numdef}}
\newenvironment{ntdef}[1][]{%
\par\addvspace{.2em}
\newcommand\makedef{%
\stepcounter{numdef}%
\textit{Definition}\ \thesubsection.\thenumdef: \ignorespaces
}%
\noindent\makedef
}{\par\addvspace{.2em}}
\begin{document}
\section{A}
\subsection{B}
\noindent\textit{Definition}\ 1.1.0\ \textit{(Definition 1)}: This is a template
\begin{ntdef}[Definition 1]
This is the first definition
\end{ntdef}
\begin{ntdef}
This is the second definition
\end{ntdef}
\end{document}
和\newtheorem
:
\documentclass{article}
\usepackage{amsthm}
\newtheoremstyle{enkidudefinition}
{0.2em} % ABOVESPACE
{0.2em} % BELOWSPACE
{\normalfont} % BODYFONT
{0pt} % INDENT (empty value is the same as 0pt)
{\itshape} % HEADFONT
{\normalfont:}% HEADPUNCT
{5pt plus 1pt minus 1pt} % HEADSPACE
{} % CUSTOM-HEAD-SPEC
\theoremstyle{enkidudefinition}
\newtheorem{ntdef}{Definition}[subsection]
\begin{document}
\section{A}
\subsection{B}
\noindent\textit{Definition}\ 1.1.0\ \textit{(Definition 1)}: This is a template
\begin{ntdef}[Definition 1]
This is the first definition
\end{ntdef}
\begin{ntdef}
This is the second definition
\end{ntdef}
\end{document}
如果您想要斜体注释:
\documentclass{article}
\usepackage{amsthm}
\newtheoremstyle{enkidudefinition}
{0.2em} % ABOVESPACE
{0.2em} % BELOWSPACE
{\normalfont} % BODYFONT
{0pt} % INDENT (empty value is the same as 0pt)
{\itshape} % HEADFONT
{\normalfont:}% HEADPUNCT
{5pt plus 1pt minus 1pt} % HEADSPACE
{\thmname{#1} \thmnumber{\textup{#2}}\thmnote{ (#3)}} % CUSTOM-HEAD-SPEC
\theoremstyle{enkidudefinition}
\newtheorem{ntdef}{Definition}[subsection]
\begin{document}
\section{A}
\subsection{B}
\noindent\textit{Definition}\ 1.1.0\ \textit{(Definition 1)}: This is a template
\begin{ntdef}[Definition 1]
This is the first definition
\end{ntdef}
\begin{ntdef}
This is the second definition
\end{ntdef}
\end{document}