
我正在使用標準書籍課程編寫一份簡短的報告。在報告中我們描述了大約 10 個實驗。我想定義一個名為 的切片指令experiment
。此切片指令應該與標準切片的指令非常相似。如果可能的話,我希望唯一的區別是它會發布一個新頁面,並且在內容中,實驗必須在本章末尾顯示。
Chapter 1 Introduction 12
section 2 .....
section 3 .....
experiment 1.2 ....
experiment 1.3 ....
experiment 1.4 ....
答案1
這是使用experiment
環境的一種可能的解決方案:環境放置表單的標題實驗 #風格與標準部分類似,使用每個新章節都會重置的計數器;該環境也會在目錄中產生一個條目。但是,該條目將出現在使用環境的位置(否則,正如 Unapiedra 在評論中提到的那樣,目錄中的順序會很奇怪);如果您希望條目出現在章節條目的末尾,則必須使用那裡的環境。
\documentclass{book}
\usepackage{lipsum}% just to generate text for the example
\newcounter{exp}
\renewcommand\theexp{\thechapter.\arabic{exp}}
\newcommand\experimentname{Experiment}
\makeatletter
\@addtoreset{exp}{chapter}
\makeatother
\newenvironment{experiment}
{\clearpage
%\phantomsection % un-comment if hyperref is to be used
\stepcounter{exp}
\addcontentsline{toc}{section}{\experimentname~\theexp}
\noindent{\Large\bfseries\experimentname~\theexp}%
\par\vspace*{2.3ex plus .2ex}\noindent\ignorespaces}
{\clearpage}
\begin{document}
\tableofcontents
\chapter{Test Chapter}
\section{Test Section One One}
\lipsum[1]
\begin{experiment}
\lipsum*[1]
\end{experiment}
\section{Test Section One Two}
\lipsum[1]
\begin{experiment}
\lipsum*[1]
\end{experiment}
\end{document}
另一個選擇是創建一個新的實驗清單,類似於標準的“Lists of...”。具體方法如下:
\documentclass{book}
\usepackage{lipsum}
\newcounter{exp}
\renewcommand\theexp{\thechapter.\arabic{exp}}
\newcommand\experimentname{Experiment}
\newcommand\listexperimentname{List of Experiments}
\makeatletter
\@addtoreset{exp}{chapter}
\newcommand\listofexperiments{\chapter*{\listexperimentname}\@starttoc{exp}}
\makeatother
\newenvironment{experiment}
{\clearpage
%\phantomsection % un-comment if hyperref is to be used
\stepcounter{exp}
\addcontentsline{exp}{section}{\experimentname~\theexp}
\noindent{\Large\bfseries\experimentname~\theexp}%
\par\vspace*{2.3ex plus .2ex}\noindent\ignorespaces}
{\clearpage}
\begin{document}
\tableofcontents
\listofexperiments
\chapter{Test Chapter}
\section{Test Section One One}
\lipsum[1]
\begin{experiment}
\lipsum*[1]
\end{experiment}
\section{Test Section One Two}
\lipsum[1]
\begin{experiment}
\lipsum*[1]
\end{experiment}
\end{document}