让 \part 格式中的“第 1 部分”消失

让 \part 格式中的“第 1 部分”消失

我正在为课程制作练习库。为此,我使用考试类,该类使用与文章类相同的分段。

为此,我有一个单独的 .tex 文件,其中包含使用考试类格式的问题、内部章节和小节。

主 .tex 文件仅包含 \Part{Questions} \input{questions.tex} 和 \Part{Answers} \input{questions.tex}。打印 \part 时,会显示以下内容:

第一部分

问题

我想删除第 1 部分的标题。

@Werner 对此有一个解决方案问题,其中使用了报告类。使用此解决方案似乎有效,但 LaTeX 为我拥有的每个 \part 提供了未定义的控制序列。

这是没有 Werner 解决方案的 MWE

\documentclass[12pt]{exam}
\usepackage{lmodern}
\usepackage[T1]{fontenc}    
\usepackage[utf8]{inputenc}     
\usepackage{amsfonts,amsmath,amssymb,amsthm,mathrsfs} 
\usepackage{sectsty}
\pagestyle{headandfoot}
\firstpageheadrule
\firstpageheader{Probabilités}{}{MAT-1720}                             
\firstpagefooter{}{}{\thepage}
\firstpagefootrule
\runningheadrule
\runningheader{Probabilités}{}{MAT-1720}  
\runningfooter{Nom du professeur}{}{\thepage}
\runningfootrule
\title{Banque d'exercices pour MAT-1720}
\author{Nom du professeur - Institut}
\date{Automne 2014}
\begin{document}
\maketitle
\thispagestyle{headandfoot}
\tableofcontents
\newpage
\part{Questions}
\noprintanswers
\begin{questions}
\newcounter{NombredeQ}
\setcounter{NombredeQ}{1}
\newcounter{NombredeR}
\setcounter{NombredeR}{1}
\section{ Dénombrement  }
\subsection{Principes de dénombrement}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}  Ceci est une question test. Quel est le sigle du cours probabilités à l'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question.  }}
\begin{solution}
Le sigle est MAT-1720.
\end{solution}
\subsection{Permutations et Combinaisons}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}
 Ceci est une autre question test. Quel est le nom du cours qui a pour sigle MAT-1720 à L'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question. }}
\begin{solution}
Le cours est probabilité.
\end{solution}
\newpage
\part{Solutions}
\qformat{\shadowbox{\textbf{Solution à l'exercice} \theNombredeQ}  \hfill}
\printanswers
\section{ Dénombrement  }
\subsection{Principes de dénombrement}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}  Ceci est une question test. Quel est le sigle du cours probabilités à l'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question.  }}
\begin{solution}
Le sigle est MAT-1720.
\end{solution}
\subsection{Permutations et Combinaisons}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}
 Ceci est une autre question test. Quel est le nom du cours qui a pour sigle MAT-1720 à L'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question. }}
\begin{solution}
Le cours est probabilité.
\end{solution}
\end{questions}
\end{document}

现在,同样的代码和 Werner 的代码

\documentclass[12pt]{exam}
\usepackage{lmodern}
\usepackage[T1]{fontenc}    
\usepackage[utf8]{inputenc}     
%\usepackage[francais]{babel}
\usepackage{amsfonts,amsmath,amssymb,amsthm,mathrsfs} 
\usepackage{sectsty}
\usepackage{hyperref} 
\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \Huge \bfseries  #2\par}%
    \@endpart}
\makeatother
\pagestyle{headandfoot}
\firstpageheadrule
\firstpageheader{Probabilités}{}{MAT-1720}                             
\firstpagefooter{}{}{\thepage}
\firstpagefootrule
\runningheadrule
\runningheader{Probabilités}{}{MAT-1720}  
\runningfooter{Nom du professeur}{}{\thepage}
\runningfootrule
\title{Banque d'exercices pour MAT-1720}
\author{Nom du professeur - Institut}
\date{Automne 2014}
\begin{document}
\maketitle
\thispagestyle{headandfoot}
\tableofcontents
\newpage
\part{Questions}
\noprintanswers
\begin{questions}
\newcounter{NombredeQ}
\setcounter{NombredeQ}{1}
\newcounter{NombredeR}
\setcounter{NombredeR}{1}
\section{ Dénombrement  }
\subsection{Principes de dénombrement}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}  Ceci est une question test. Quel est le sigle du cours probabilités à l'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question.  }}
\begin{solution}
Le sigle est MAT-1720.
\end{solution}
\subsection{Permutations et Combinaisons}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}
 Ceci est une autre question test. Quel est le nom du cours qui a pour sigle MAT-1720 à L'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question. }}
\begin{solution}
Le cours est probabilité.
\end{solution}
\newpage
\part{Solutions}
\printanswers
\section{ Dénombrement  }
\subsection{Principes de dénombrement}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}  Ceci est une question test. Quel est le sigle du cours probabilités à l'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question.  }}
\begin{solution}
Le sigle est MAT-1720.
\end{solution}
\subsection{Permutations et Combinaisons}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}
 Ceci est une autre question test. Quel est le nom du cours qui a pour sigle MAT-1720 à L'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question. }}
\begin{solution}
Le cours est probabilité.
\end{solution}
\end{questions}
\end{document}

它给出了预期的结果,但留下了错误。

答案1

\part在设置方式上存在很大差异article(由exam) 和report类。最值得注意的是后者为该部分设置了整个页面。

从示例代码来看,导致错误的唯一未知数是\@endpart,它仅存在于report类中。相反,使用article结束。因此您可以添加\part\@afterheading

\makeatletter
\let\@endpart\@afterheading
\makeatother

如果您对最终的排版结果也满意的话,请在序言中删除错误。

在此处输入图片描述

答案2

您可以使用课程\uplevel提供的宏exam

\uplevel{\centering\Huge\bfseries Questions}
\addcontentsline{toc}{part}{Questions}

如果你愿意,你可以将其变成宏:

\newcommand{\mypart}[1]{%
\phantomsection   %% to make links work
\uplevel{\centering\Huge\bfseries #1}
\addcontentsline{toc}{part}{#1}
}

并像使用它一样

\mypart{Questions}

完整代码:

\documentclass[12pt]{exam}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage[francais]{babel}
\usepackage{amsfonts,amsmath,amssymb,amsthm,mathrsfs}
\usepackage{sectsty}
\usepackage{hyperref}

\pagestyle{headandfoot}
\firstpageheadrule
\firstpageheader{Probabilités}{}{MAT-1720}
\firstpagefooter{}{}{\thepage}
\firstpagefootrule
\runningheadrule
\runningheader{Probabilités}{}{MAT-1720}
\runningfooter{Nom du professeur}{}{\thepage}
\runningfootrule
\title{Banque d'exercices pour MAT-1720}
\author{Nom du professeur - Institut}
\date{Automne 2014}

\newcommand{\mypart}[1]{%
\phantomsection
\uplevel{\centering\Huge\bfseries #1}
\addcontentsline{toc}{part}{#1}
}
\begin{document}
\maketitle
\thispagestyle{headandfoot}
\tableofcontents
\newpage
\mypart{Questions}
\noprintanswers
\begin{questions}
\newcounter{NombredeQ}
\setcounter{NombredeQ}{1}
\newcounter{NombredeR}
\setcounter{NombredeR}{1}
\section{ Dénombrement  }
\subsection{Principes de dénombrement}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}  Ceci est une question test. Quel est le sigle du cours probabilités à l'UdeM?
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question.  }}
\begin{solution}
Le sigle est MAT-1720.
\end{solution}
\subsection{Permutations et Combinaisons}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}
 Ceci est une autre question test. Quel est le nom du cours qui a pour sigle MAT-1720 à L'UdeM?
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question. }}
\begin{solution}
Le cours est probabilité.
\end{solution}
\newpage
\mypart{Solutions}
\printanswers
\section{ Dénombrement  }
\subsection{Principes de dénombrement}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}  Ceci est une question test. Quel est le sigle du cours probabilités à l'UdeM?
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question.  }}
\begin{solution}
Le sigle est MAT-1720.
\end{solution}
\subsection{Permutations et Combinaisons}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}
 Ceci est une autre question test. Quel est le nom du cours qui a pour sigle MAT-1720 à L'UdeM?
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question. }}
\begin{solution}
Le cours est probabilité.
\end{solution}
\end{questions}
\end{document}

在此处输入图片描述

在此处输入图片描述

如果您想引用这些部分,您可以使用一个新的计数器:

\newcounter{mypart}
\setcounter{mypart}{0}
\newcommand{\mypart}[1]{%
\phantomsection
\refstepcounter{mypart}
\label{mypart:#1}
\uplevel{\centering\Huge\bfseries #1}
\addcontentsline{toc}{part}{#1}
}

这样{mypart:Questions}当你使用时标签就会自动创建\mypart{Questions},你可以像这样使用它们

refer~\ref{mypart:Questions} here

答案3

您必须\@part按照article类中的定义修补命令;它与中的不同report

最简单的方法是使用\patchcmd,但这必须在加载之前完成,这会根据之前的内容hyperref改变的定义。\@part

\documentclass[12pt]{exam}
\usepackage{lmodern}
\usepackage[T1]{fontenc}    
\usepackage[utf8]{inputenc}     
\usepackage{amsfonts,amsmath,amssymb,amsthm,mathrsfs,fancybox} 
\usepackage{sectsty}
\usepackage{etoolbox}

\makeatletter
\pretocmd{\@part}{\phantomsection}{}{} % for links (requires hyperref)
\patchcmd{\@part}{\m@ne}{\maxdimen}{}{}
\patchcmd{\@part}{\m@ne}{\maxdimen}{}{}
\makeatother
\usepackage{hyperref}

\pagestyle{headandfoot}
\firstpageheadrule
\firstpageheader{Probabilités}{}{MAT-1720}                             
\firstpagefooter{}{}{\thepage}
\firstpagefootrule
\runningheadrule
\runningheader{Probabilités}{}{MAT-1720}  
\runningfooter{Nom du professeur}{}{\thepage}
\runningfootrule
\title{Banque d'exercices pour MAT-1720}
\author{Nom du professeur - Institut}
\date{Automne 2014}
\begin{document}
\maketitle
\thispagestyle{headandfoot}
\tableofcontents
\newpage
\part{Questions}
\noprintanswers
\begin{questions}
\newcounter{NombredeQ}
\setcounter{NombredeQ}{1}
\newcounter{NombredeR}
\setcounter{NombredeR}{1}
\section{ Dénombrement  }
\subsection{Principes de dénombrement}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}  Ceci est une question test. Quel est le sigle du cours probabilités à l'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question.  }}
\begin{solution}
Le sigle est MAT-1720.
\end{solution}
\subsection{Permutations et Combinaisons}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}
 Ceci est une autre question test. Quel est le nom du cours qui a pour sigle MAT-1720 à L'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question. }}
\begin{solution}
Le cours est probabilité.
\end{solution}
\newpage
\part{Solutions}
\qformat{\shadowbox{\textbf{Solution à l'exercice} \theNombredeQ}  \hfill}
\printanswers
\section{ Dénombrement  }
\subsection{Principes de dénombrement}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}  Ceci est une question test. Quel est le sigle du cours probabilités à l'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question.  }}
\begin{solution}
Le sigle est MAT-1720.
\end{solution}
\subsection{Permutations et Combinaisons}
\question \ifthenelse{\boolean{printanswers}}{\label{R:\theNombredeR}}{\label{Q:\thequestion}}
 Ceci est une autre question test. Quel est le nom du cours qui a pour sigle MAT-1720 à L'UdeM? 
\\\ifthenelse{\boolean{printanswers}}{\textbf{Retour à la question \ref{Q:\theNombredeQ}.}\stepcounter{NombredeQ} \stepcounter{NombredeR}}{\textbf{Voir la \hyperref[R:\thequestion]{solution} à la question. }}
\begin{solution}
Le cours est probabilité.
\end{solution}
\end{questions}
\end{document}

这个想法是将两个条件改为\ifnum\c@secnumdepth>\m@ne\ifnum\c@secnumdepth}>\maxdimen代表\m@ne-1,而\maxdimen是可表达的最大数字。

在此处输入图片描述

相关内容