頁首和頁尾

頁首和頁尾

可能的重複:
頁首、頁尾和字體自訂

我正在寫一個更大的項目(一本書),現在標題有很多可能性。但我是一個新手,我不知道哪個可能是最好的,所以我想問你我應該如何以最好的方式實現標題?我希望標題顯示頁碼和章節標題,並且下面應該有一行。我不知道如何實現這一點,現在文字下方的頁碼應該會消失,標題中的文字應該有顏色,但頁碼應該是黑色。該線應該比 4 磅稍厚一些。非常感謝你的幫忙!這是我的程式碼:

\documentclass{book}
\usepackage{geometry}
\geometry{left=4cm,right=3cm, top=2cm, bottom=2cm} 
\usepackage{titlesec}
\titlespacing*{\chapter}{0pt}{-30pt}{20pt}
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\usepackage[ngerman]{babel}
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{wallpaper}
\usepackage{color}
\usepackage[final]{pdfpages} 
%,bookmarksopenlevel={1}
%\usepackage[hidelinks,bookmarks=true,bookmarksopen=true,bookmarksnumbered=true,colorlinks=true,linkcolor=black,]{hyperref}
\usepackage[colorlinks,linkcolor=black,bookmarksopen=false,
hypertexnames=TRUE,pdfpagelabels=true]{hyperref}[2011/02/05]
\hypersetup{ 
  pdftitle={},
%  pdfauthor={},
  pdfsubject={Statistics Book}, 
  pdfkeywords={}, 
  }
\usepackage{xcolor,bookmark}
\usepackage{scrextend}
\usepackage{titlepic}
\usepackage{shorttoc}
\usepackage{courier}
\usepackage{type1cm}         
\usepackage{zref-abspage}
\usepackage{makeidx}        
\usepackage{graphicx}        
\usepackage{multicol}        
\usepackage[bottom]{footmisc}
\usepackage{tocstyle}
\usetocstyle{allwithdot} 
\usepackage{shadethm}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{marginnote}
\usepackage{wrapfig}
\usepackage{paralist}
\usepackage{amssymb}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{ulem}

\definecolor{shadethmcolor}{rgb}{.9,.9,.95}%

\newtheoremstyle{mystyle}
  {\topsep}{\topsep}{}{}%
  {\bfseries}{:}{.5em}{}%

\theoremstyle{mystyle}

\newmdtheoremenv[hidealllines=true,backgroundcolor=shadethmcolor,skipabove=\topsep,
skipbelow=\topsep]{example}{example}

\begin{document}
\frontmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\setlength{\marginparwidth}{2.1cm}
\marginparsep = -4pt
\pagestyle{plain}
\pagenumbering{Roman}
\include{dedic}
\newpage\section*{} 
\include{foreword}
\newpage\section*{} 
\include{preface}
\newpage\section*{} 
\include{acknow}
\newpage\section*{} 
\include{acronym}
%
    \shorttableofcontents{Inhalts\"ubersicht}{1}
\bookmark[page=15,rellevel=1,keeplevel,view={XYZ},color=red]{Inhalts\"ubersicht}
\bookmark[page=17,rellevel=1,keeplevel,view={XYZ},color=red]{Inhaltsverzeichnis}
\tableofcontents
\clearpage
\pagenumbering{arabic}  
%



\mainmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\include{part1} 
\include{chapter1}
\include{chapter2}
\include{chapter3}
\include{part2}
\include{chapter4}
\include{chapter5}
\include{chapter6}
\backmatter

\appendix 

\include{appendix}

\listoffigures
\newpage
\listoftables
\backmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\include{glossary}
%\include{solutions}
\cleardoublepage
\phantomsection
\addcontentsline{toc}{part}{Index}
\printindex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cleardoublepage
\phantomsection
\addcontentsline{toc}{part}{\"Uber den Autor}
\includepdf{ueberautor}
\includepdf{back}
\end{document}

答案1

首先需要更換線路

\usepackage{titlesec}

\usepackage[pagestyles]{titlesec}

使命令\newpagestyle可用。然後,您可以使用此命令使用語法建立自己的頁首和頁尾樣式:\newpagestyle{stylename}[global style options]{commands}。 「commands」參數可能包含其他指令,例如\headrule在標題下方包含一條水平線(如您所願)或\sethead自訂標題的內容。語法是\sethead[even-left][even-center][even-right]{odd-left}{odd-center}{odd-right}.

例如,您可以透過新增以下行來建立樣式「mystyle」:

\newpagestyle{mystyle}{
\headrule \sethead[\thepage][][\color{red} \chaptertitlename\ \thechapter. \chaptertitle]
{\color{red} \thesection\ \sectiontitle}{}{\thepage}}
\pagestyle{mystyle}

如果您只對章節標題而不是章節感興趣(儘管您正在使用 book 類別),您可以嘗試

\newpagestyle{mystyle2}{
\headrule \sethead[\thepage][][\color{red} \thesection\ \sectiontitle]
{\color{red} \thesection\ \sectiontitle}{}{\thepage}}
\pagestyle{mystyle2}

這應該像您所期待的那樣。

相關內容