我有以下 MWE:
\documentclass[12pt]{article}
\makeatletter
\usepackage[dutch]{babel}
\usepackage{blindtext}
%Paragraphs get numbered continuously
\usepackage{chngcntr}
\counterwithout{paragraph}{subsubsection}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\usepackage{titlesec}
\usepackage{tocloft}
%How stuff is displayed EVERYWHERE
\renewcommand\cftsecaftersnum{.}
\renewcommand\cftparaaftersnum{.}
\renewcommand\cftparanumwidth{1em}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\theparagraph}{\arabic{paragraph}}
%How stuff is displayed in the text
\titleformat{\section}[block]
{\Large\bfseries}
{Hoofdstuk \thesection:}{0.5em}{}
\titleformat{\paragraph}[block]
{\normalfont\bfseries}
{Paragraaf \theparagraph:}{0.5em}{}
\newcounter{exercise}[section]
\newcounter{exercisestar}[section]
\renewcommand{\theexercise}{\thesection.\@Alph\c@exercise \hspace{6pt}}
\renewcommand{\theexercisestar}{\thesection.\@Alph\c@exercise*}
\newcommand{\exercisestarmark}[1]{}
\newcommand{\exercisemark}[1]{}
\newcommand{\exercise}{\@startsection{exercise}{2}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\large\bfseries}}
\newcommand{\exercisestar}{
\stepcounter{exercise}
\@startsection{exercisestar}{2}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\large\bfseries}
}
\begin{document}
\tableofcontents
\section{Volledige inductie}
\paragraph{Inleiding}
\paragraph{Getalrijen}
\exercise {}
Some exercise
\section{Optelling en vermenigvuldiging}
\paragraph{Optelling}
\paragraph{Vermenigvuldiging}
\end{document}
现在的问题是,添加练习时,LaTeX 无法正确编译。如果有人能指出原因或如何改进代码,我将非常高兴。
编辑:我现在意识到删除“\tableofcontents”可以解决问题...但我真的希望在我的笔记中有目录。
第二次编辑:删除 .toc 文件时,我第一次编译时一切正常。之后编译时,我再次收到错误。也许这有帮助。
答案1
\documentclass[12pt]{article}
\usepackage[dutch]{babel}
\usepackage{blindtext}
%Paragraphs get numbered continuously
\usepackage{chngcntr}
\counterwithout{paragraph}{subsubsection}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\usepackage{titlesec}
\usepackage{tocloft}
%How stuff is displayed EVERYWHERE
\renewcommand\cftsecaftersnum{.}
\renewcommand\cftparaaftersnum{.}
\renewcommand\cftparanumwidth{1em}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\theparagraph}{\arabic{paragraph}}
%How stuff is displayed in the text
\titleformat{\section}[block]
{\Large\bfseries}
{Hoofdstuk \thesection:}{0.5em}{}
\titleformat{\paragraph}[block]
{\normalfont\bfseries}
{Paragraaf \theparagraph:}{0.5em}{}
\makeatletter
\newcounter{exercise}[section]
\renewcommand{\theexercise}{\thesection.\@Alph\c@exercise\hspace{6pt}}
\newcommand{\exercisemark}[1]{}
\newcommand{\exercise}{\@startsection{exercise}{2}{\z@}{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}{\normalfont\large\bfseries}}
\newcommand{\fakercise}[1]% #1 = title
{\refstepcounter{exercise}%
\exercise*{\theexercise\hspace{1em}#1}}
\newcommand*{\l@exercise}{\@dottedtocline{2}{1.5em}{2.3em}}
\makeatother
\begin{document}
\tableofcontents
\section{Volledige inductie}
\paragraph{Inleiding}
\paragraph{Getalrijen}
\exercise{title}
some exercise
\fakercise{title}
some exercise
\section{Optelling en vermenigvuldiging}
\paragraph{Optelling}
\paragraph{Vermenigvuldiging}
\end{document}