非编号章节*标题问题

非编号章节*标题问题

我对非编号章节第二页的页眉有问题。以下是我的最小工作示例。

一切正常,但在我的简介章节中(如果我像示例中那样不带数字放置它),在第二页(以及之后的每个其他页面)的标题中,我使用的是“定义列表”而不是“简介”。我该如何修复此问题?

(我也不喜欢我的词汇表的外观,但我仍需努力改进)。

谢谢!

\documentclass[a4paper,11pt,fleqn]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french,german,english]{babel}
\usepackage{fourier} % Utopia font-typesetting including mathematical formula compatible with newer TeX-Distributions (>2010)
\setlength{\textwidth}{146.8mm} % = 210mm - 37mm - 26.2mm
\setlength{\oddsidemargin}{11.6mm} % 37mm - 1in (from hoffset)
\setlength{\evensidemargin}{0.8mm} % = 26.2mm - 1in (from hoffset)
\setlength{\topmargin}{-2.2mm} % = 0mm -1in + 23.2mm 
\setlength{\textheight}{221.9mm} % = 297mm -29.5mm -31.6mm - 14mm (12 to accomodate footline with pagenumber)
\setlength{\headheight}{14pt}
\setlength{\parindent}{0pt}


\usepackage{lipsum}
\usepackage{microtype}

\usepackage{fancyhdr}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\pagestyle{fancy}
    \fancyhf{}
    \renewcommand{\headrulewidth}{0.4pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhead[OR]{\bfseries \nouppercase{\rightmark}}
    \fancyhead[EL]{\bfseries \nouppercase{\leftmark}}
    \fancyfoot[EL,OR]{\thepage}
\fancypagestyle{plain}{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyfoot[EL,OR]{\thepage}}
\fancypagestyle{addpagenumbersforpdfimports}{
    \fancyhead{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyfoot{}
    \fancyfoot[RO,LE]{\thepage}
}

\usepackage{listings}
\lstset{language=[LaTeX]Tex,tabsize=4, basicstyle=\scriptsize\ttfamily, showstringspaces=false, numbers=left, numberstyle=\tiny, numbersep=10pt, breaklines=true, breakautoindent=true, breakindent=10pt}

\usepackage{hyperref}
\hypersetup{pdfborder={0 0 0},
    colorlinks=true,
    linkcolor=black,
    citecolor=black,
    urlcolor=black}
\urlstyle{same}

\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}
    \thispagestyle{empty}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother \clearpage{\pagestyle{plain}\cleardoublepage}


%%%%% CHAPTER HEADER %%%%
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
\titleformat{\chapter}[display]  % type (section,chapter,etc...) to vary,  shape (eg display-type)
    {\normalfont\bfseries\Huge} % format of the chapter
    {\gdef\chapterlabel{\thechapter\ }}     % the label 
    {0pt} % separation between label and chapter-title
      {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-8cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=black] (0,0) rectangle(35.5mm,15mm);
        \node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum height=30mm,inner sep=0mm] at (current page.north west)
        {\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$\color{white}\chapterlabel}};  %the black l is just to get better base-line alingement
        \node[anchor=north west,yshift=-7.2cm,xshift=37mm,text width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north west)
              {\parbox[top][30mm][t]{\textwidth}{\color{black}#1}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
   \gdef\chapterlabel{}
  } % code before the title body

\titlespacing*{\chapter}{0pt}{50pt}{30pt}
\titlespacing*{\section}{0pt}{13.2pt}{*0}  % 13.2pt is line spacing for a text with 11pt font size
\titlespacing*{\subsection}{0pt}{13.2pt}{*0}
\titlespacing*{\subsubsection}{0pt}{13.2pt}{*0}

\newcounter{myparts}
\newcommand*\partlabel{}
\titleformat{\part}[display]  % type (section,chapter,etc...) to vary,  shape (eg display-type)
    {\normalfont\bfseries\Huge} % format of the part
    {\gdef\partlabel{\thepart\ }}     % the label 
    {0pt} % separation between label and part-title
      {\setlength{\unitlength}{20mm}
      \addtocounter{myparts}{1}
      \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north west,xshift=-65mm,yshift=-6.9cm-\value{myparts}*20mm] at (current page.north east) % for unknown reasons: 3mm missing -> 65 instead of 62
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=black] (0,0) rectangle(62mm,20mm);   % -\value{myparts}\unitlength
        \node[anchor=north west,yshift=-6.1cm-\value{myparts}*20mm,xshift=-60.5mm,minimum height=30mm,inner sep=0mm] at (current page.north east)
        {\parbox[top][30mm][t]{55mm}{\raggedright \color{white}Part \partlabel $\phantom{\textrm{l}}$}};  %the phantom l is just to get better base-line alingement
        \node[anchor=north east,yshift=-6.1cm-\value{myparts}*20mm,xshift=-63.5mm,text width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north east)
              {\parbox[top][30mm][t]{\textwidth}{\raggedleft \color{black}#1}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
   \gdef\partlabel{}
  } % code before the title body


\usepackage{bookmark}% http://ctan.org/pkg/bookmark
\usepackage{booktabs} %ema
\usepackage[acronym,nonumberlist]{glossaries} %ema 
\usepackage{glossary-mcols} %ema 
\usepackage{glossary-longragged}

\usepackage{gensymb}
\usepackage{import}
\usepackage{tikz}
\usepackage{bm}

\usetikzlibrary{plotmarks}
\usepackage{verbatim}

\usepackage{titlesec}  % to set spacings after titles
%\titlespacing{\chapter}{0pt}{1em}{1em}
\titlespacing{\subsection}{0pt}{1em}{1em}
\titlespacing{\subsubsection}{0pt}{1em}{1em}

% float placement %% from Martin
\renewcommand{\topfraction}{0.85}   % maximum share of float on top of page
\renewcommand{\textfraction}{0.1}   % minimum share of text on a page (if both floats and text is present)
\renewcommand{\floatpagefraction}{0.75} % min share of float on a page that justifies a float-only page. must be smaller than topfraction (and 1-textfraction, i guess)

\pdfoptionpdfminorversion=7
%\graphicspath{{/images}}
\makeatletter
\renewcommand{\thesection}{%
  \ifnum\c@chapter<1 \@arabic\c@section
  \else \thechapter.\@arabic\c@section
  \fi
}
\makeatother

 %to go to a new line after paragraph
\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\}

% avoid single lines at beginning and end of pages (widows and orphans). increase value up to 1000 if required
\widowpenalty=600
\clubpenalty=600

%avoid splitting footnotes
\interfootnotelinepenalty=10000
\raggedbottom % avoid relative warning


% set distance between text and floats
\setlength{\textfloatsep}{10pt plus 1.0pt minus 2.0pt}



% to number subsub section and make them appear in the toc
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}

\newcommand*{\Agroupname}{}
\newcommand*{\Ggroupname}{Greek letters}
\newcommand*{\Sgroupname}{Subscripts}

\newglossarystyle{onecol}{%
%
\renewenvironment{theglossary}%
{\begin{description}}{\end{description}}%
%
\renewcommand*{\glossaryheader}{}%
%
% indicate what to do at the start of each logical group
\renewcommand*{\glsgroupheading}[1]{%
\item[{\glsgetgrouptitle{##1}}]}
%
\renewcommand*{\glsgroupskip}{\indexspace}%
%
\renewcommand*{\glossaryentryfield}[5]{%
\item[\glstarget{##1}{##2}] ##3%
}%
}



\newglossary[dlg]{definitions}{dld}{ddn}{List of Definitions}

\newglossaryentry{definition}{name={definition},description={this is a definition},type={definitions}, plural={definitions}}


\immediate\write18{makeglossaries \jobname}
\makeglossaries

\glstoctrue % place your custom packages, etc... in this file!

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% HEAD: Book-Begin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\frontmatter
\cleardoublepage
\pdfbookmark{\contentsname}{toc}
\tableofcontents
\printglossary[type={definitions}]
\setlength{\parskip}{0em}
\setlength{\parindent}{4ex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% MAIN: The chapters of the thesis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\mainmatter
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\gls{definition}

\lipsum[3-30]
\glsresetall
\chapter{State of the Art}
 \gls{definition}

\lipsum[7]

\end{document}

答案1

带星号的章节(和部分)没有编号,也没有目录条目和标题。问题是,标题不会自动清除。您必须使用 手动执行此操作\markboth{}{}。但从您的示例中,我可以看到您想要一个目录条目,我想还需要一个标题。您可以实现这一点。

KOMA 类以更高级的方式提供相同的命令。请阅读如何在 KOMA-script 中使用未编号章节?了解更多信息。现在,您可以使用 KOMA 脚本文档中描述的命令。切换到 KOMA 不会对刚刚定义的命令造成任何困难。

总结一下,\addchap创建一个带编号的章节,使用其参数作为目录条目和页眉。如果给出了可选参数,则将其用于目录和页眉。如果使用星号形式,则不会设置目录条目,并且页眉中将清除任何以前的内容。


由于这似乎经常需要,我将前面的代码放入一个名为的小包中unnumberedtotoc(<- 下载链接) 与 KOMA 兼容,便于以后切换。这是一个 alpha 版本,可能永远不会有任何错误修复。如果您想要万无一失的功能,请使用 KOMA 类。

该软件包仅提供一个选项;indentunnumbered。这是基于软件包tocbasic(来自 KOMA 包)。

\documentclass{book}
\usepackage{blindtext}
\usepackage[
%   indentunnumbered
]{unnumberedtotoc} %get it from https://github.com/johannesbottcher/unnumberedtotoc

\begin{document}
\tableofcontents

\addchap{unnumbered chapter with toc and head}
\blindtext[10]

\addchap[title for toc and head]{chapter title}
\blindtext[10]
\addsec*{starred addsec}
\blindtext[10]
\addsec{regular addsec}
\blindtext[10]
\addsec*{starred addsec}
\blindtext[10]
\chapter{usual chapter}
\blindtext[10]
\chapter*{look at the header}
\blindtext[10]
\addchap*{really nothing, header cleared}
\blindtext[10]
\end{document}

前一个例子

\documentclass[a4paper,11pt,fleqn]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french,german,english]{babel}

\usepackage{lipsum}
\usepackage{microtype}

\usepackage{fancyhdr}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[OR]{\bfseries \nouppercase{\rightmark}}
\fancyhead[EL]{\bfseries \nouppercase{\leftmark}}
\fancyfoot[EL,OR]{\thepage}
\fancypagestyle{plain}{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyfoot[EL,OR]{\thepage}
}
\fancypagestyle{addpagenumbersforpdfimports}{
    \fancyhead{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyfoot{}
    \fancyfoot[RO,LE]{\thepage}
}


%Implementing *some* KOMA functionality now
\usepackage{xparse}

\ProvideDocumentCommand{\addchap}{ s o m }{%
    \typeout{providing a minimal version of addchapp.
        You might want to use a KOMA class for full
        features
    }%
    \chapter*{#3}%
    \IfBooleanTF{#1}{
        \markboth{}{}
    }{
        \IfNoValueTF{#2}{
            \addcontentsline{toc}{chapter}{#3}
            \markboth{#3}{#3}%
        }{%
            \addcontentsline{toc}{chapter}{#2}
            \markboth{#2}{#2}%
        }
    }
}

\ProvideDocumentCommand{\addsec}{ s o m }{%
    \typeout{providing a minimal version of addsec.
        You might want to use a KOMA class for full
        features
    }%
    \section*{#2}%
    \IfBooleanTF{#1}{}{
        \IfNoValueTF{#2}{
            \addcontentsline{toc}{section}{#3}
            \markright{#3}%
        }{%
            \addcontentsline{toc}{section}{#2}
            \markright{#2}%
        }
    }
}





%A KOMA class also provides this feature
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}
    \thispagestyle{empty}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi}
    \makeatother \clearpage{\pagestyle{plain}\cleardoublepage}




\begin{document}
\frontmatter
\cleardoublepage
\tableofcontents
%\setlength{\parskip}{0em}
%\setlength{\parindent}{4ex}

\mainmatter
\addchap{Introduction}
\lipsum[3-30]

\addchap[toc and head]{Donald is a great duck}
\lipsum[3-30]
\addsec{Daisy}
\lipsum[3-30]
\addsec{Dagobert}
\lipsum[3-30]
\chapter{State of the Art}

\lipsum[7-20]
\addchap*{really nothing, header cleared}

\end{document}

相关内容