我写了一个小环境来写练习:
\documentclass{book}
\usepackage{lipsum}
\usepackage{tocloft}
\usepackage{xparse}
\newcommand{\listofexercises}{List of exercises}
\newlistof{exercise}{exp}{\listofexercises}
% Restart counter at each new chapter
\makeatletter
\@addtoreset{exercise}{chapter}
\makeatother
% Exercise environment
\newenvironment{exercise}[1][]{%
\refstepcounter{exercise}
\par\noindent\textbf{Exercice \thechapter.\theexercise} {#1}
\newline
\addcontentsline{exp}{exercise}{%
Exercice \thechapter.\theexercise
\ifx&\else\ -- #1\fi
}\par
}{
\newline%
}
\begin{document}
\mainmatter
\chapter{Foo}
\lipsum[1][1-3]
\begin{exercise}
What is the difference between a duck?
\end{exercise}
\lipsum[2][1-3]
\begin{exercise}
What is the answer to life the universe and everything?
\end{exercise}
\begin{exercise}[Don't answer yes]
Are you human?
\end{exercise}
\chapter{Bar}
\begin{exercise}[Impossible?]
If you enjoy wasting time, is that time really wasted?
\end{exercise}
\backmatter
\listofexercise
\end{document}
遗憾的是,间距无法帮助清楚地识别练习。家长很困惑,间距也不好。
一些解决方法是不对整个文档设置 parindent 并\newline
在环境后添加 double,但我不认为这是一个好的解决方案。
此外,如果我在练习后添加新行,我会得到一个错误。使用这个:
\begin{exercise}
What is the answer to life the universe and everything?
\end{exercise}
我明白了:
! LaTeX Error: There's no line here to end.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.44 \end{exercise}
答案1
我确信这可以做得更漂亮。我的第一个想法是这样的。
除了par
-command 之外,您还可以使用\par\addvspace{\baselineskip}
:
\documentclass{book}
\usepackage{lipsum}
\usepackage{tocloft}
\usepackage{xparse}
\usepackage{parskip}
\newcommand{\listofexercises}{List of exercises}
\newlistof{exercise}{exp}{\listofexercises}
% Restart counter at each new chapter
\makeatletter
\@addtoreset{exercise}{chapter}
\makeatother
% Exercise environment
\newenvironment{exercise}[1][]{%
\refstepcounter{exercise}
\par\addvspace{\baselineskip}\noindent\textbf{Exercice \thechapter.\theexercise} {#1}
\par
\addcontentsline{exp}{exercise}{%
Exercice \thechapter.\theexercise
\ifx&\else\ -- #1\fi
}\par
}{
% \newline%
}
\begin{document}
\mainmatter
\chapter{Foo}
\lipsum[1][1-3]
\begin{exercise}
What is the difference between a duck?
\end{exercise}
\lipsum[2][1-3]
\begin{exercise}
What is the answer to life the universe and everything?
\end{exercise}
\begin{exercise}[Don't answer yes]
Are you human?
\end{exercise}
\chapter{Bar}
\begin{exercise}[Impossible?]
If you enjoy wasting time, is that time really wasted?
\end{exercise}
\backmatter
\listofexercise
\end{document}