我正在使用 mdframed 环境创建标题框。
如何在目录后添加框列表(作为表格列表和图表列表)?
这是我的 MWE。
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage{makeidx}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}
\makeindex
\author{Draft: Do not Cite}
\date{}
\title{alskdj alskdj alksjd}
\hypersetup{
pdfauthor={Draft: Do not Cite},
pdftitle={alskdj alskdj alksjd},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 24.5.1 (Org mode 8.3)},
pdflang={English}}
\begin{document}
\maketitle
\tableofcontents
\section{Heading}
\lipsum[5]
\begin{infobox}[Title of the box]
\label{orgspecialblock1}
\lipsum[8]
\end{infobox}
\end{document}
在我的实际用例中,我使用的是回忆录类。回忆录类集成了 tocloft。因此,在使用回忆录类时,文章类的解决方案似乎无法发挥作用。我正在为回忆录类添加另一个 MWE。如果您也能帮助解决这些问题,我将不胜感激。
下面的 MWE 将 Alan 的代码与我的用例结合起来。但是当在其上运行 pdflatex 时,我收到错误“命令 \infobox 已定义。”。我做错了什么?
\documentclass[a4paper,11pt,twoside,openany,showtrims,strict,extrafontsizes]{memoir}
\newcommand{\listinfoboxname}{List of Boxes}
\newlistof{infobox}{ibx}{\listinfoboxname}
\newcounter{infobox}[chapter]
\renewcommand{\theinfobox}{\thechapter.\arabic{infobox}}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\addcontentsline{ibx}{infobox}{\protect\numberline{\theinfobox}#1}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}
\begin{document}
\tableofcontents
\listoffigures
\listofboxes
\chapter{Chapter one starts here}
\section{Heading}
\lipsum[4]
\begin{infobox}[Title of the first test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}
\begin{figure}
\caption{\label{orgspecialblock3}ksfkhjsdkjhfs}
\includegraphics[width=0.9\linewidth]{pou.png}
\end{figure}
\chapter{Chapter two starts here}
\section{Heading}
\lipsum[4]
\begin{infobox}[Title of the third test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the fourth test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}
\end{document}
\documentclass[a4paper,11pt,twoside,openany,showtrims,strict,extrafontsizes]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage{makeidx}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}
\makeindex
\author{Draft: Do not Cite}
\date{}
\title{alskdj alskdj alksjd}
\hypersetup{
pdfauthor={Draft: Do not Cite},
pdftitle={alskdj alskdj alksjd},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 24.5.1 (Org mode 8.3)},
pdflang={English}}
\begin{document}
\maketitle
\tableofcontents
\chapter{Chapter one starts}
\section{Heading}
\lipsum[5]
\begin{infobox}[Title of the box]
\label{orgspecialblock1}
\lipsum[8]
\end{infobox}
\end{document}
以下是结合 Gonzalo 解决方案的 MWE
\documentclass[a4paper,11pt,twoside,openany,showtrims,strict,extrafontsizes]{memoir}
\newcounter{infobox}[chapter]
\renewcommand{\theinfobox}{\thechapter.\arabic{infobox}}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\newcounter{infobox}[chapter]
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}%
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
\addcontentsline{lob}{section}{\numberline{\theinfobox}#1}%
}{%
\end{mdframed}
}
\makeatletter
\newcommand\listboxname{Boxes}
\newcommand\listofboxes{
\section*{\listboxname}
\@starttoc{lob}
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listofboxes
\chapter{Chapter one starts here}
\section{Heading}
\lipsum[4]
\begin{infobox}[Title of the first test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}
\begin{figure}
\caption{\label{orgspecialblock3}ksfkhjsdkjhfs}
\includegraphics[width=0.9\linewidth]{pou.png}
\end{figure}
\chapter{Chapter two starts here}
\section{Heading}
\lipsum[4]
\begin{infobox}[Title of the third test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the fourth test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}
\end{document}
答案1
答案与 Gonzalo 的答案大致相同,但使用了tocloft
包,隐藏了一些机制。但如果您需要它来更普遍地格式化目录,那么您也可以使用它来做以下事情:
\documentclass[11pt]{article}
\usepackage[titles]{tocloft}
\newcommand{\listinfoboxname}{List of Boxes}
\newlistof{infobox}{ibx}{\listinfoboxname}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\addcontentsline{ibx}{infobox}{\protect\numberline{\theinfobox}#1}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}
\begin{document}
\tableofcontents
\listofinfobox
\section{Heading}
\lipsum[5]
\begin{infobox}[Title of the box]
\label{orgspecialblock1}
\lipsum[8]
\end{infobox}
\end{document}
使用回忆录的解决方案
该memoir
软件包包含了 的代码,tocloft
因此tocloft
不能与 一起使用memoir
。但是所有功能都在那里,尽管实现这一点的方式有些不同memoir
。
首先,该\newlistof
命令将列表名称而不是列表的基本名称作为其参数,因此,列表的计数器需要由用户创建。此外,我们需要告知列表条目应该处于什么级别。0 表示缩进级别与\chapter
(我认为这就是您想要的)相同。
\newlistof{listofinfobox}{ibx}{\listinfoboxname}
\newcounter{infobox}
\newlistentry{listofinfobox}{ibx}{0}
在infobox
环境中,addcontentsline
还需要更改:
\addcontentsline{ibx}{listofinfobox}{\protect\numberline{\theinfobox}#1}
完整的memoir
代码如下:
% !TEX TS-program = pdflatex
\documentclass[11pt]{memoir}
%\usepackage[titles]{tocloft}
\newcommand{\listinfoboxname}{List of Boxes}
\newlistof{listofinfobox}{ibx}{\listinfoboxname}
\newcounter{infobox}
\newlistentry{listofinfobox}{ibx}{0}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\addcontentsline{ibx}{listofinfobox}{\protect\numberline{\theinfobox}#1}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}
\begin{document}
\tableofcontents
\listofinfobox
\chapter{}
\section{Heading}
\lipsum[5]
\begin{infobox}[Title of the box]
\label{orgspecialblock1}
\lipsum[8]
\end{infobox}
\end{document}
答案2
更新
由于memoir
正在使用,那么事情就变得更容易了,因为回忆录已经提供了所有需要的工具来使用\newlistof
和关联生成所需的列表;特别是现在\listofboxes
带有一个带星号的变体,它不会向 ToC 添加新列表的条目:
\documentclass[a4paper,11pt,twoside,openany,showtrims,strict,extrafontsizes]{memoir}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}%
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
\addcontentsline{lob}{infobox}{\numberline{\theinfobox}#1}%
}{%
\end{mdframed}
}
\makeatletter
\newcommand\listboxname{Boxes}
\newlistof{listofboxes}{lob}{\listboxname}
\newlistentry[chapter]{infobox}{lob}{0}
\cftsetindents{infobox}{0em}{2.3em}
\renewcommand{\theinfobox}{\thechapter.\arabic{infobox}}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listofboxes
\chapter{Test chapter}
\section{Test section}
\lipsum[4]
\begin{infobox}[Title of the first test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}
\begin{figure}
\caption{\label{orgspecialblock3}A test figure}
\end{figure}
\end{document}
显示 ToC、LoF 和新列表的结果图像:
mdframed
版本
有一种可能性是:
\documentclass[11pt]{article}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\newcounter{infobox}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}%
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
\addcontentsline{lob}{section}{\numberline{\theinfobox}#1}%
}{%
\end{mdframed}
}
\makeatletter
\newcommand\listboxname{List of Boxes}
\newcommand\listofboxes{
\section*{\listboxname}
\@starttoc{lob}
}
\makeatother
\begin{document}
\tableofcontents
\listofboxes
\section{Heading}
\lipsum[4]
\begin{infobox}[Title of the first test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}
\end{document}
显示目录和新框列表的结果图像:
tcolorbox
版本
这里我提供了一个使用tcolorbox
它已经提供了轻松生成框列表的工具:
\documentclass[11pt]{article}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\usepackage{xparse}
\newtcolorbox[auto counter,list inside=infobox]{infobox}[2][]{
breakable,
enhanced jigsaw,
before=\vskip25pt,
after=\vskip25pt,
colback=white,
colbacktitle=white,
coltitle=black,
fonttitle=\bfseries,
arc=0pt,
outer arc=0pt,
boxsep=0pt,
toptitle=5pt,
bottomtitle=5pt,
left=10pt,
right=10pt,
enlarge left by=10pt,
enlarge right by=10pt,
width=\textwidth-20pt,
boxrule=0.4pt,
title={\strut Box~\thetcbcounter\ #1\strut},
label={#2}
}
\newcommand\listboxname{List of Boxes}
\begin{document}
\tableofcontents
\tcblistof[\section*]{infobox}{\listboxname}
\section{Heading}
\lipsum[4]
\begin{infobox}[Title of the first test box]{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]{orgspecialblock2}
\lipsum[4]
\end{infobox}
\end{document}
显示目录和新框列表的结果图像: