我正在尝试为我的博士论文创建一个模板。我喜欢 Yo' 在框中显示页码的方式 [格式化页码(fancyhdr?)]。我稍微修改了他的代码,并添加了章节号和页码。但是,我有以下问题二问题。
- 在我的前言中,我看到了带有章节号零和罗马数字二的框,这不是我想要的。我希望在第一章开始之前不显示任何数字(或框)。
- 如下图所示,在章节的第一页,页码显示在页面底部。我想在章节标题旁边显示带有章节号和页码的框。
以下是我的代码。非常感谢您的帮助。提前致谢。:)
\documentclass[11pt,openright,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage[paperheight=25cm,paperwidth=17.6cm,left=2cm,right=2cm,top=2cm,bottom=2cm, footskip=1cm]{geometry}%
\usepackage[a4, cam, center]{crop}
\usepackage{lipsum}
\usepackage{indentfirst}
\setlength{\parindent}{1cm}
\usepackage{CormorantGaramond}
\usepackage[T1]{fontenc}
\usepackage{caption}
\captionsetup[table]{skip=8pt}
\usepackage{tikz}
\renewcommand{\baselinestretch}{1.1}
\newcommand*\chem[1]{\ensuremath{\mathrm{#1}}}
\renewcommand{\theequation}{Eq. \arabic{equation}}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\centering\Huge\bfseries}{}{0cm}{}
%%
\usepackage{fancyhdr}
%\usepackage{lastpage}
\fancyhf{}
\fancyhead[LE,RO]{{\ooalign{%
\color{black!60!white}% background box color
\rule[0.05in]{0.7in}{1in}% background box raise, width, height
\cr
\hfil\strut\raisebox{0.25in}{% number raise
\sffamily\bfseries\color{white}% number color
\Huge% number fontsize
\thechapter
\kern0.1em% distance number-bar
\rule{1pt}{1.4ex}% bar size
\kern0.15em% distance bar-totalnumber
\large% totalnumber fontsize
\thepage}\hfil
}}}
\fancyheadoffset[LE,RO]{0.8in}% protrusion
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\makeatother
\pagenumbering{roman}
\begin{document}
\begin{titlepage}
\begin{center}
\vspace*{5cm}
\line(1,0){250}\\
\huge{Thesis Title}
\line(1,0){250}\\
\vspace*{5cm}
{\Large Name}
\end{center}
\end{titlepage}
\tableofcontents
\chapter{Chapter 1}
\pagenumbering{arabic}
\setcounter{page}{1}
\lipsum[1-10]
\chapter{Chapter 2}
\lipsum[1-10]
\chapter{Chapter 3}
\lipsum[1-10]
\chapter{Chapter 4}
\lipsum[1-10]
\end{document}
答案1
\documentclass[11pt,openright,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage[paperheight=25cm,paperwidth=17.6cm,left=2cm,right=2cm,top=2cm,bottom=2cm, footskip=1cm]{geometry}%
\usepackage[a4, cam, center]{crop}
\usepackage{lipsum}
\usepackage{indentfirst}
\setlength{\parindent}{1cm}
\usepackage{CormorantGaramond}
\usepackage[T1]{fontenc}
\usepackage{caption}
\captionsetup[table]{skip=8pt}
\usepackage{tikz}
%\usepackage{lineno}
%\linenumbers
\usepackage{xcolor}
\usepackage{framed}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{lmodern}
\renewcommand{\baselinestretch}{1.1}
\newcommand*\chem[1]{\ensuremath{\mathrm{#1}}}
\renewcommand{\theequation}{Eq. \arabic{equation}}
%%
\usepackage{fancyhdr}
% for remving all styles from front matter
\fancypagestyle{style1}{
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
}
% for adding boxes with chapter and page numbers
\fancypagestyle{style2}{
\fancyhf{}
\fancyhead[LE,RO]{{\ooalign{%
\color{black!60!white}% background box color
\rule[0.05in]{0.7in}{1in}% background box raise, width, height
\cr
\hfil\strut\raisebox{0.25in}{% number raise
\bfseries\color{white}% number color
\Huge% number fontsize
\thechapter
\kern0.1em% distance number-bar
\rule{1pt}{1.4ex}% bar size
\kern0.15em% distance bar-totalnumber
\large% totalnumber fontsize
\thepage}\hfil
}}}
\fancyheadoffset[LE,RO]{0.8in}% protrusion
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{style2}}{}{}
\pagestyle{style1}
\begin{document}
%\begin{titlepage}
%\begin{center}
% \vspace*{5cm}
% \line(1,0){250}\\
% \huge{Thesis Title}
% \line(1,0){250}\\
% \vspace*{5cm}
% {\Large Name}
%\end{center}
%\end{titlepage}
\tableofcontents
\thispagestyle{empty}
\chapter{Introduction}
\pagestyle{style2}
\pagenumbering{arabic}
\setcounter{page}{1}
\section{1}\lipsum[1-10]
\section{2}\lipsum[1-10]
\chapter{Experimental}
\pagestyle{style2}
\lipsum[1-10]
\chapter{Chapter 3}
\pagestyle{style2}
\lipsum[1-10]
\chapter{Appendix 3A}
\chapter{Chapter 4}
\pagestyle{style2}
\lipsum[1-10]
\end{document}