我正在制作一个仅包含定义的文档,为此我使用了这个代码
\documentclass[12pt, a4paper, fleqn]{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Definition
\newcounter{defns}[section] \setcounter{defns}{0}
\renewcommand{\thedefns}{\arabic{section}.\arabic{defns}}
\newenvironment{defns}[2][]{%
\refstepcounter{defns}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definition~\thedefns};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definition~\thedefns:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=green!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\qed\end{mdframed}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\tableofcontents
\newpage
\section{Definitions}
\begin{defns}[Ring]{defns:ring01}
Let $R$ be an Abelian group under addition in witch multiplication is...
\end{defns}
This is a reference to definition \ref{defns:ring01}
\end{document}
一切都很好,但我需要的是所有定义的可点击列表,而不是内容。
请帮我怎么做?
答案1
\listof...
tocloft
命令可以用包和\newlistof
命令结合来定义\addcontentsline
(这是通常的怀疑 ;-))
解释:由于计数器已命名,因此defns
该\newlistof
命令用于定义该计数器(重置计数器section
)、文件扩展名、.dfn
以及的标题名称\list of definitions
。
这定义了一个命令\listofdefns
(即\listof....
后缀与计数器名称相同)。
使用 在定义环境中添加条目\addcontentsline{dfn}{section}{\protect\numberline{\thedefns}~#1}
。
\newcommand{\listofdefinitionsname}{List of definitions}
\newlistof[section]{defns}{dfn}{\listofdefinitionsname}
请注意,计数器不能在之前定义——这是 的设计缺陷tocloft
。不幸的是,它不允许类似use counter from
等的操作。
以下是代码:
\documentclass[12pt, a4paper, fleqn]{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tocloft}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition
\newcommand{\listofdefinitionsname}{List of definitions}
\newlistof[section]{defns}{dfn}{\listofdefinitionsname}
\setcounter{defns}{0}
\renewcommand{\thedefns}{\arabic{section}.\arabic{defns}}
\newenvironment{defns}[2][]{%
\refstepcounter{defns}%
\addcontentsline{dfn}{section}{\protect\numberline{\thedefns}~#1} % Add it to the dfn file
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definition~\thedefns};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definition~\thedefns:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=green!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\qed\end{mdframed}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\tableofcontents
\clearpage
\listofdefns
\newpage
\section{Definitions}
\begin{defns}[Ring]{defns:ring01}
Let $R$ be an Abelian group under addition in witch multiplication is...
\end{defns}
This is a reference to definition \ref{defns:ring01}
\end{document}
请注意,该tcolorbox
软件包提供了类似的功能,例如mdframed
自动listof...