我正在尝试生成乳胶代码,该代码可用于将来自多位作者的最低限度格式的章节整合成一份包含三个部分的单个报告。我使用的章节层次结构是/part /chapter /section /subsection /subsubsection
。目前,我在整个文档中只有一个标题,但我希望在第 2 部分和第 3 部分的标题中显示部分名称,但不是在每个页面(部分标题页除外)上都显示第 1 部分。我尝试/thepart
在标题中使用,但我认为因为我使用的是未编号的部分,所以它不起作用。我知道我应该能够从我在这里读到的例子中做到这一点,但没有运气
我的项目代码在这里,并附有构建的 PDF: https://github.com/trosendal/report_template
谢谢!
托马斯
以下仅是 .tex 代码:
%%%%%%%%% The format of the report goes here %%%%%%%%%%%%%%%%%%%%%
%%A two sided book that has space for binding on the left side:
\documentclass[a4paper, twoside]{report}
\usepackage[top=4cm, bottom=2.5cm, left=2.5cm, right=2.5cm, bindingoffset=1cm]{geometry}
%use correct character encoding
\usepackage[utf8]{inputenc}
%Choose a font family:
%\usepackage{bookman}
%\usepackage{avant}
%\usepackage{chancery}
\usepackage{courier}
%\usepackage{newcent
%\usepackage{palatino}
\title{\textbf{\huge{Title of Report}}}
\author{The list of authors}
\usepackage{color}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage[hidelinks]{hyperref}
\usepackage{multicol}
\usepackage{url}
%%Separated the columns by a 6 mm
\setlength{\columnsep}{0.6cm}
%%Sort out the spacing a style of the paragraph, section, subsection, subsubsection and chapter titles
\usepackage[compact]{titlesec}
\titleformat*{\section}{\normalfont\scshape\color{red}}
\titlespacing*{\section}{0pt}{12pt}{0pt}
\titleformat*{\subsection}{\small\bf}
\titlespacing*{\subsection}{0pt}{12pt}{0pt}
\titleformat*{\subsubsection}{\small\bf}
\titlespacing*{\subsubsection}{12pt}{12pt}{0pt}
%%Add a header on eack page
\usepackage{fancyhdr}
\renewcommand\headrule{}
\pagestyle{fancy}
\fancyhead{} % clear all header fields
\fancyhead[LE,RO]{\textcolor{red}{\uppercase{HEADER TEXT}}}
%Even add the header on the plain pages like the first page of each chapter
\fancypagestyle{plain}{%
\fancyhead[LE, RO]{\textcolor{red}{\uppercase{HEADER TEXT}}}}
%%define the boxes around stuff:
\usepackage{tcolorbox}
\newtcolorbox{mybox}{colback=blue!5!white}
\newtcolorbox{mytitlebox}{colback=blue!5!white, valign=top, height=3.5cm,%
enlarge left by = -5cm, width=24cm}
%%%%%%%%% The content in the report goes after this break %%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%The Title page
\maketitle
%%The table of contents
\begin{multicols}{2}
\tableofcontents
\end{multicols}
%%The Introduction (Part1)
\input{chapters/chapter1/input}
%The chapters in Part2
\newpage
\begin{mytitlebox}
\part*{PART2}
\addcontentsline{toc}{part}{\bf{PART2}}
\end{mytitlebox}
\input{chapters/chapter2/input}
\input{chapters/chapter3/input}
%The chapters in Part3
\newpage
\begin{mytitlebox}
\part*{PART3}
\addcontentsline{toc}{part}{\bf{PART3}}
\end{mytitlebox}
\input{chapters/chapter4/input}
\end{document}
答案1
我不太确定,但我认为这应该可以回答这个问题。
重新定义part-pages为空,让plain与pagestyle fance相同,定义一个命令使得输入新的运行页眉更加容易。
\documentclass[a4paper, twoside]{report}
\usepackage[top=4cm, bottom=2.5cm, left=2.5cm, right=2.5cm,
bindingoffset=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\title{Title of Report}
\author{The list of authors}
\usepackage{fancyhdr}
\renewcommand\headrule{}
\pagestyle{fancy}
\fancyhead{} % clear all header fields
\usepackage{etoolbox}
\tracingpatches
\patchcmd{\part}{plain}{empty}{}{}
\makeatletter
\let\ps@plain\ps@fancy
\makeatother
\newcommand{\setheadmark}[1]{
\fancyhead[LE,RO]{\textcolor{red}{\uppercase{#1}}}
}
\usepackage{tcolorbox}
\usepackage{blindtext}
\newtcolorbox{mybox}{colback=blue!5!white}
\newtcolorbox{mytitlebox}{colback=blue!5!white,
valign=top, height=3.5cm,%
enlarge left by = -5cm, width=24cm}
\begin{document}
\maketitle
\begin{multicols}{2}
\tableofcontents
\end{multicols}
\blinddocument
\clearpage
\begin{mytitlebox}
\setheadmark{part2}
\part*{PART2}
\addcontentsline{toc}{part}{\bf{PART2}}
\end{mytitlebox}
\blinddocument
\clearpage
\begin{mytitlebox}
\setheadmark{part3}
\part*{PART3}
\addcontentsline{toc}{part}{\bf{PART3}}
\end{mytitlebox}
\blinddocument
\end{document}