向目录中添加不同的实体,第 2 部分

向目录中添加不同的实体,第 2 部分

这是该问题的后续:向目录添加不同类型的实体

当我构建一个大型文档时,事情并不像上一个问题的 MWE 中那样运作。我删除了整个文档,只留下命令和几个示例页面来演示我想要什么以及问题是什么。

  1. 目录崩溃了。错误消息指出有一个多余的右括号 },但我没有看到它。

  2. 实验室应该像附录一样是独立的单元。但每页都以标题“第 1 章。标题...”开头,因为书籍样式认为所有内容都必须在章节内。我如何隐藏该标题?


\documentclass[12pt]{book}              % Book class in 12 points
\parindent0pt  \parskip10pt             % make block paragraphs
\raggedright                            % do not right justify
\usepackage{mathptmx}  % times roman, including math (where possible)
\usepackage{mathpazo}  % palatino, including math (where possible)
\usepackage{helvet}    % helvetica
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[usenames,dvipsnames]{color}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{comment}
\usepackage{listings}
\usepackage{grffile}
\usepackage{listing}
\usepackage{changepage}
\usepackage{multirow}
\usepackage{outlines}
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage{subfigure}
\usepackage{hyperref}
\usepackage{textcomp}
\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
%usepackage{fullpage} would fix the margins problem
\cfoot{\sffamily\textcopyright 2005-2014 copyright notice }
\rfoot{\thepage}
\graphicspath{ {C:/LaTeX/img/} }
\pagestyle{fancy}
\title{\bf Grandiose Title Here \\ %\includegraphics[scale=.5]{ Logo.jpg}\\
Organization Name Here}    % Supply information
\author{Primary Author}            %   for the title page.
\date{\today}                           %   Use current date. 
\definecolor{lgray}{rgb}{0.9,0.9,0.9}
%\definecolor{graycolor}{rgb}{0.9,0.9,0.9}
\definecolor{white}{rgb}{1,1,1}
\definecolor{dkgreen}{rgb}{0,.5,0.1}
\definecolor{wrongcolor}{rgb}{.9,.5,.4}
\definecolor{purple}{rgb}{0.6,0,0.6}
%\input state.tex


\newcommand{\underscore}{ %UNDERLINE COMMAND
  \underline{ \hspace{3 cm}}
}

\makeatletter
\newcounter{lab}% also defines \thelab

% roughly equivalent to \chapter
\newcommand{\lab}[1]{% #1 is lab heading
  \refstepcounter{lab}%
  \if@openright\cleardoublepage\else\clearpage\fi%
  \addtocontents{toc}{\string\contentsline {chapter}%
    {\hbox to .65in{Lab}\protect\numberline{\thelab}#1}{\thepage}}%
  \global\@topnum\z@% page number to bottom?
  \noindent%
  \@lab{#1}% fixed first character separation
}

% roughly equivalent to \@chapter
\def\@lab#1{% #1 is lab heading
  \if@twocolumn%
    \@topnewpage[{\huge\bfseries Lab \thelab: #1\par}]%
  \else{\huge\bfseries Lab \thelab: #1\par}%
  \@afterheading% no idea
  \fi}

% copied from mwe
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
   \thispagestyle{plain}%
   \global\@topnum\z@
   \@afterindentfalse
   \secdef\@chapter\@schapter}

% copied from book.cls and modified
\def\@chapter[#1]#2{%
  \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
      \refstepcounter{chapter}%
      \typeout{\@chapapp\space\thechapter.}%
      \addtocontents{toc}{\string\contentsline {chapter}%
        {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
    \else
      \addtocontents{toc}{\string\contentsline {chapter}%
        {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
    \fi
  \else
    \addtocontents{toc}{\string\contentsline {chapter}%
      {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
  \fi
  \chaptermark{#1}%
  \addtocontents{lof}{\protect\addvspace{10\p@}}%
  \addtocontents{lot}{\protect\addvspace{10\p@}}%
  \if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]%
  \else
    \@makechapterhead{#2}%
    \@afterheading
  \fi}
\makeatother


% Note that book class by default is formatted to be printed back-to-back.
\begin{document}                        % End of preamble, start of text.
\setenumerate[1]{label=\arabic*.}
\setenumerate[2]{label=\Alph*.}
\setenumerate[3]{label=\roman*.}
\setenumerate[4]{label=\alph*.}
\frontmatter                            % only in book class (roman page #s)
\maketitle                                  % Print title page.
\pagebreak
{\Large Acknowledgements }

Acknowledgements ... Thanks Stack Overflow experts!

{\Large Authors}

Main author \\
author2 \\
author3

{\Large Editors} \\
editor-in-chief

{\Large Layout and LaTeX Programming} \\
interns who laid out the document

{\Large Contributors} \\
contributor 1 \\
contributor 2


{\Large Example Programs in Java} \\

Code contributors

{\Large Example Programs in C++}

{\Large Online Quiz Development and Testing}

{\Large Lab Photos and  Testing}

\pagebreak
\tableofcontents                        % Print table of contents
\mainmatter                                 % only in book class (arabic page #s)

\chapter{How to Use this Document}                % Print a "chapter" heading
This is where we describe how it all works

Now, here come the individual short self-paced lessons,
called labs for now for want of a better term.

\lab{ Let There be Light}

To embed a live link ...
%\url{http://www.AdAstraEducation.org}

\lab{C++ Code and BadCode Styles}

Write some code, yadayada

\end{document}                          

答案1

\addtocontents在我看来,命令是错误的根源,所以我将其更改为版本\addcontentsline。但是,lab在这种情况下,命令似乎定义不明确。

此外,为了与 一起使用,之前hyperref应该有一个命令。\phantomsection\addcontentsline

\documentclass[12pt]{book}              % Book class in 12 points
\parindent0pt  \parskip10pt             % make block paragraphs
\raggedright                            % do not right justify
\usepackage{mathptmx}  % times roman, including math (where possible)
\usepackage{mathpazo}  % palatino, including math (where possible)
\usepackage{helvet}    % helvetica
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[usenames,dvipsnames]{color}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{comment}
\usepackage{listings}
\usepackage{grffile}
\usepackage{listing}
\usepackage{changepage}
\usepackage{multirow}
\usepackage{outlines}
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage{subfigure}
\usepackage[bookmarksnumbered=true]{hyperref}
\usepackage{textcomp}
\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
%usepackage{fullpage} would fix the margins problem
\cfoot{\sffamily\textcopyright 2005-2014 copyright notice }
\rfoot{\thepage}
\graphicspath{ {C:/LaTeX/img/} }
\pagestyle{fancy}
\title{\bf Grandiose Title Here \\ %\includegraphics[scale=.5]{ Logo.jpg}\\
Organization Name Here}    % Supply information
\author{Primary Author}            %   for the title page.
\date{\today}                           %   Use current date. 
\definecolor{lgray}{rgb}{0.9,0.9,0.9}
%\definecolor{graycolor}{rgb}{0.9,0.9,0.9}
\definecolor{white}{rgb}{1,1,1}
\definecolor{dkgreen}{rgb}{0,.5,0.1}
\definecolor{wrongcolor}{rgb}{.9,.5,.4}
\definecolor{purple}{rgb}{0.6,0,0.6}
%\input state.tex


\newcommand{\underscore}{ %UNDERLINE COMMAND
  \underline{ \hspace{3 cm}}
}

\makeatletter
\newcounter{lab}% also defines \thelab

\newcommand{\labname}{Lab}

% roughly equivalent to \chapter
\newcommand{\lab}[1]{% #1 is lab heading
  \refstepcounter{lab}%
  \if@openright\cleardoublepage\else\clearpage\fi%
  \phantomsection%%%%
  \addcontentsline{toc}{chapter}{\labname~\protect\numberline{\thelab}#1}%
%
%  \addtocontents{toc}{\string\contentsline {chapter}%
%    {\hbox to .65in{Lab}\protect\numberline{\thelab}#1}{\thepage}}%
  \global\@topnum\z@% page number to bottom?
  \noindent%
  \@lab{#1}% fixed first character separation
}

% roughly equivalent to \@chapter
\def\@lab#1{% #1 is lab heading
  \if@twocolumn%
    \@topnewpage[{\huge\bfseries Lab \thelab: #1\par}]%
  \else{\huge\bfseries Lab \thelab: #1\par}%
  \@afterheading% no idea
  \fi}

% copied from mwe
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
   \thispagestyle{plain}%
   \global\@topnum\z@
   \@afterindentfalse
   \secdef\@chapter\@schapter}

% copied from book.cls and modified
\def\@chapter[#1]#2{%
  \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
      \refstepcounter{chapter}%
      \typeout{\@chapapp\space\thechapter.}%
      \addcontentsline{toc}{chapter}{Chapter~\protect\numberline{\thechapter}#1}%
%      \addtocontents{toc}{\string\contentsline {chapter}%
%        {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
    \else
      \addcontentsline{toc}{chapter}{Chapter~\protect\numberline{\thechapter}#1}%
%      \addtocontents{toc}{\string\contentsline {chapter}%
%        {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
    \fi
  \else
      \addcontentsline{toc}{chapter}{Chapter~\protect\numberline{\thechapter}#1}%
  %  \addtocontents{toc}{\string\contentsline {chapter}%
  %    {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
  \fi
  \chaptermark{#1}%
  \addtocontents{lof}{\protect\addvspace{10\p@}}%
  \addtocontents{lot}{\protect\addvspace{10\p@}}%
  \if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]%
  \else
    \@makechapterhead{#2}%
    \@afterheading
  \fi}
\makeatother


% Note that book class by default is formatted to be printed back-to-back.
\begin{document}                        % End of preamble, start of text.
\setenumerate[1]{label=\arabic*.}
\setenumerate[2]{label=\Alph*.}
\setenumerate[3]{label=\roman*.}
\setenumerate[4]{label=\alph*.}
\frontmatter                            % only in book class (roman page #s)
\maketitle                                  % Print title page.
\pagebreak
{\Large Acknowledgements }

Acknowledgements ... Thanks Stack Overflow experts!

{\Large Authors}

Main author \\
author2 \\
author3

{\Large Editors} \\
editor-in-chief

{\Large Layout and LaTeX Programming} \\
interns who laid out the document

{\Large Contributors} \\
contributor 1 \\
contributor 2


{\Large Example Programs in Java} \\

Code contributors

{\Large Example Programs in C++}

{\Large Online Quiz Development and Testing}

{\Large Lab Photos and  Testing}

\pagebreak
\tableofcontents                        % Print table of contents
\mainmatter                                 % only in book class (arabic page #s)

\chapter{How to Use this Document}                % Print a "chapter" heading
This is where we describe how it all works

Now, here come the individual short self-paced lessons,
called labs for now for want of a better term.

\lab{Let There be Light}

To embed a live link ...
%\url{http://www.AdAstraEducation.org}

\lab{C++ Code and BadCode Styles}

Write some code, yadayada

\end{document}   

**OP 要求实验室部分使用空页眉,因此请lab对这些“部分”使用不同的页面样式。

\documentclass[12pt]{book}              % Book class in 12 points
\parindent0pt  \parskip10pt             % make block paragraphs
\raggedright                            % do not right justify
\usepackage{mathptmx}  % times roman, including math (where possible)
\usepackage{mathpazo}  % palatino, including math (where possible)
\usepackage{helvet}    % helvetica
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[usenames,dvipsnames]{color}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{comment}
\usepackage{listings}
\usepackage{grffile}
\usepackage{listing}
\usepackage{changepage}
\usepackage{multirow}
\usepackage{outlines}
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage{subfigure}
\usepackage[bookmarksnumbered=true]{hyperref}
\usepackage{textcomp}
\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
%usepackage{fullpage} would fix the margins problem
\cfoot{\sffamily\textcopyright 2005-2014 copyright notice }
\rfoot{\thepage}
\graphicspath{ {C:/LaTeX/img/} }
\pagestyle{fancy}
\title{\bf Grandiose Title Here \\ %\includegraphics[scale=.5]{ Logo.jpg}\\
Organization Name Here}    % Supply information
\author{Primary Author}            %   for the title page.
\date{\today}                           %   Use current date. 
\definecolor{lgray}{rgb}{0.9,0.9,0.9}
%\definecolor{graycolor}{rgb}{0.9,0.9,0.9}
\definecolor{white}{rgb}{1,1,1}
\definecolor{dkgreen}{rgb}{0,.5,0.1}
\definecolor{wrongcolor}{rgb}{.9,.5,.4}
\definecolor{purple}{rgb}{0.6,0,0.6}
%\input state.tex


\newcommand{\underscore}{ %UNDERLINE COMMAND
  \underline{ \hspace{3 cm}}
}

\makeatletter
\newcounter{lab}% also defines \thelab

\newcommand{\labname}{Lab}

% roughly equivalent to \chapter
\newcommand{\lab}[1]{% #1 is lab heading
  \refstepcounter{lab}%
  \if@openright\cleardoublepage\else\clearpage\fi%
  \phantomsection%%%%
  \addcontentsline{toc}{chapter}{\labname~\protect\numberline{\thelab}#1}%
%
%  \addtocontents{toc}{\string\contentsline {chapter}%
%    {\hbox to .65in{Lab}\protect\numberline{\thelab}#1}{\thepage}}%
  \global\@topnum\z@% page number to bottom?
  \noindent%
  \@lab{#1}% fixed first character separation
  \cleardoublepage
}

% roughly equivalent to \@chapter


\fancypagestyle{lab}{%
%\fancyhf{}%
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0pt}%
  \lfoot{}%
  \lhead{}%
  \rhead{}%
  \rfoot{}%
}%



\def\@lab#1{% #1 is lab heading
  \if@twocolumn%
    \@topnewpage[{\huge\bfseries Lab \thelab: #1\par}]%
  \else{\huge\bfseries Lab \thelab: #1\par}%
  \@afterheading% no idea
  \fi}

% copied from mwe
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
   \thispagestyle{plain}%
   \global\@topnum\z@
   \@afterindentfalse
   \secdef\@chapter\@schapter}

% copied from book.cls and modified
\def\@chapter[#1]#2{%
  \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
      \refstepcounter{chapter}%
      \typeout{\@chapapp\space\thechapter.}%
      \addcontentsline{toc}{chapter}{Chapter~\protect\numberline{\thechapter}#1}%
%      \addtocontents{toc}{\string\contentsline {chapter}%
%        {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
    \else
      \addcontentsline{toc}{chapter}{Chapter~\protect\numberline{\thechapter}#1}%
%      \addtocontents{toc}{\string\contentsline {chapter}%
%        {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
    \fi
  \else
      \addcontentsline{toc}{chapter}{Chapter~\protect\numberline{\thechapter}#1}%
  %  \addtocontents{toc}{\string\contentsline {chapter}%
  %    {\hbox to .65in{Chapter}\protect\numberline{\thechapter}#1}{\thepage}}%
  \fi
  \chaptermark{#1}%
  \addtocontents{lof}{\protect\addvspace{10\p@}}%
  \addtocontents{lot}{\protect\addvspace{10\p@}}%
  \if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]%
  \else
    \@makechapterhead{#2}%
    \@afterheading
  \fi}
\makeatother


% Note that book class by default is formatted to be printed back-to-back.
\begin{document}                        % End of preamble, start of text.
\setenumerate[1]{label=\arabic*.}
\setenumerate[2]{label=\Alph*.}
\setenumerate[3]{label=\roman*.}
\setenumerate[4]{label=\alph*.}
\frontmatter                            % only in book class (roman page #s)
\maketitle                                  % Print title page.
\pagebreak
{\Large Acknowledgements }

Acknowledgements ... Thanks Stack Overflow experts!

{\Large Authors}

Main author \\
author2 \\
author3

{\Large Editors} \\
editor-in-chief

{\Large Layout and LaTeX Programming} \\
interns who laid out the document

{\Large Contributors} \\
contributor 1 \\
contributor 2


{\Large Example Programs in Java} \\

Code contributors

{\Large Example Programs in C++}

{\Large Online Quiz Development and Testing}

{\Large Lab Photos and  Testing}

\pagebreak
\tableofcontents                        % Print table of contents
\mainmatter                                 % only in book class (arabic page #s)

\chapter{How to Use this Document}                % Print a "chapter" heading
This is where we describe how it all works

Now, here come the individual short self-paced lessons,
called labs for now for want of a better term.

\pagestyle{lab}

\lab{Let There be Light}

To embed a live link ...
%\url{http://www.AdAstraEducation.org}

\lab{C++ Code and BadCode Styles}

Write some code, yadayada

\end{document}

笔记大多数奇怪的代码都是使用另一个我未回答的问题中的代码堆积起来的。使用newtheoremtcolorbox具有干净界面的环境会比滥用某种命令更容易\chapter

相关内容