第二次尝试

第二次尝试

我对文档中页眉和页脚的显示方式存在问题。我制作了一个仍然存在问题的小示例:

问题 1:标题标尺从前部到主内容上下移动
问题 2:页脚图像从首页到正文上下移动
问题 3:我希望“章节”始终显示在标题中,也显示在章节开头。目前,章节下方有一个空行,后面是标题标尺。

在此处输入图片描述

在此处输入图片描述

这是我的“代码”:

\documentclass[
   final,
   12pt,
   a4paper,
   oneside
]{book}

\usepackage{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{lipsum}
\usepackage{textcomp}
\usepackage{listings}

\usepackage{fancyhdr}
    \pagestyle{fancy}
    \pagestyle{fancyplain}
    \fancyhead{}
    \fancyfoot{}
    \fancyfoot[L]{\rule{2cm}{1cm}}
    \fancyfoot[RO, LE] {\thepage}
    \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
}}

\lfoot[LE,LO]{\rule{2cm}{1cm}}

\usepackage[
   bottom,      % Footnotes appear always on bottom. This is necessary
                % especially when floats are used
   stable,      % Make footnotes stable in section titles
   %perpage,     % Reset on each page
   %para,       % Place footnotes side by side of in one paragraph.
   %side,       % Place footnotes in the margin
   ragged,      % Use RaggedRight
   %norule,     % suppress rule above footnotes
   multiple,    % rearrange multiple footnotes intelligent in the text.
   %symbol,     % use symbols instead of numbers
]{footmisc}



\begin{document}
\renewcommand{\cftchapaftersnum}{.}

\frontmatter
\pagenumbering{Roman}
\fancyfoot[RO, LE] {\small\thepage}
\thispagestyle{empty}
\fancyfoot[R] {\thepage}
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
\rhead{\small{List of Listings}}
\addcontentsline{toc}{chapter}{List of Listings}
\lstlistoflistings

\mainmatter
\pagenumbering{arabic}
\onehalfspacing
\fancyhead{}
\pagestyle{plain}
\lhead{}
\rhead{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
\fancyfoot[R] {\thepage}
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\chapter{Some Chapter}
\lipsum

\section{Some section}
\lipsum

\end{document}

第二次尝试

现在页眉和页脚不再移动了,我开始感到高兴。

我还指出了其他问题。

  1. 现在,列表列表在标题中出现两次(一次作为章节,一次作为节)

  2. 第一部分仍然没有打印在页眉中(只打印了章节和空行)

它看起来是这样的:

当前代码如下:

\documentclass[
   final,
   12pt,
   a4paper,
   oneside
]{book}

\usepackage{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{textcomp}
\usepackage{listings}

%%# IN NEW BEGIN
\usepackage{lipsum}
\usepackage[headheight=30pt,
            a4paper,
            left=42mm,
            right=29mm,
            top=32mm,
            bottom=38mm
]{geometry}  % or %\setlength{\headheight}{30pt}
%% IN NEW END

\usepackage{fancyhdr}
    %\pagestyle{fancy}
    %\pagestyle{fancyplain}
    %\fancyhead{}
    %\fancyfoot{}
    \fancyhead[L]{}
    \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
    \fancyfoot[L]{\rule{2cm}{1cm}}
    \fancyfoot[R]{\thepage}
    \fancyfoot[C]{}
    \fancypagestyle{plain}{%
        \fancyhf{} % clear all header and footer fields
        \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
        \fancyfoot[L]{\rule{2cm}{1cm}}
        \fancyfoot[R]{\thepage}
        \fancyfoot[C]{}
        \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}}
    \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}


\begin{document}
\renewcommand{\cftchapaftersnum}{.}

%%# IN NEW BEGIN
\pagestyle{fancy}
%%# IN NEW END

\frontmatter
\pagenumbering{Roman}

%% OUT NEW BEGIN
%\fancyfoot[RO, LE] {\small\thepage}
%\thispagestyle{empty}
%\fancyfoot[R] {\thepage}
%% OUT NEW END

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
\rhead{\small{List of Listings}}
\addcontentsline{toc}{chapter}{List of Listings}
\lstlistoflistings

\mainmatter

%% IN NEW BEGIN
\renewcommand{\sectionmark}[1]{\markright{\thesection~#1}}
%% IN NEW END

\pagenumbering{arabic}
\onehalfspacing

%% OUT NEW BEGIN
%\fancyhead{}
%\pagestyle{plain}
%\lhead{}
%\rhead{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
%\fancyfoot[R] {\thepage}
%% OUT NEW END

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\chapter{Some Chapter}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{Some section}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.


\end{document}`

答案1

编译时会收到许多警告,其中之一是

软件包 Fancyhdr 警告:\headheight 太小(12.0pt):至少将其设置为 17.99998pt。我们现在将其设置为与文档其余部分一样大。但是,这可能会导致页面布局不一致。

因此添加

\usepackage[headheight=18pt]{geometry}  % or
%\setlength{\headheight}{18pt}

来解决这个问题。此外,该E选项在一侧文档中无用。

答案2

scrbook以下是使用和的建议scrlayer-scrpage

请注意,我定义\rightbotmark使用章节页上出现的最后一个右标记。通常使用第一个,但在章节页上,第一个由设置\chapter

\documentclass[
  12pt,
  oneside,
  parskip=full-,
  chapterprefix,
  footheight=33pt,
  headheight=28pt,
  listof=totoc
]{scrbook}
\usepackage{setspace}

\usepackage{scrhack}
\usepackage{listings}
\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}

\usepackage[
  a4paper,
  left=42mm,
  right=29mm,
  top=32mm,
  bottom=38mm,
  %showframe % to show the pagelayout
]{geometry}

\usepackage[autooneside=false]{scrlayer-scrpage}
\automark[chapter]{chapter}
\automark*[section]{}
\KOMAoptions{onpsinit=\setstretch{1}}% singlespacing in header
\clearpairofpagestyles
\makeatletter
\providecommand*{\rightbotmark}{\expandafter\@rightmark\botmark\@empty\@empty}
\makeatother
\addtokomafont{pageheadfoot}{\small}
\ohead%
  [\ifstr{\leftmark}{\rightbotmark}{}{\leftmark}\\\rightbotmark]% pagestyle plain
  {\ifstr{\leftmark}{\rightmark}{}{\leftmark}\\\rightmark}% pagesstyle scrheadings
\ifoot*{\rule{2cm}{1cm}}
\ofoot*{\pagemark}


\ModifyLayer[
contents={%
  \usekomafont{pageheadfoot}\usekomafont{pagehead}\usekomafont{headsepline}%
  \rlap{\rule[-2pt]{\layerwidth}{1.9pt}}%
  \rule[-3.6pt]{\layerwidth}{.6pt}%
  }]{scrheadings.head.below.line}
\ModifyLayer[clone=scrheadings.head.below.line]{plain.scrheadings.head.below.line}


\usepackage{xcolor}
\addtokomafont{headsepline}{\color{purple}}

\usepackage{blindtext}% dummy text

\begin{document}

\frontmatter
\pagenumbering{Roman}
\lstlistoflistings

\mainmatter
\onehalfspacing
\chapter{Some Chapter}
\blindtext
\section{Some section}
\Blindtext
\chapter{Next Chapter}
\Blindtext[3]
\section{Some section}
\Blindtext

\blinddocument
\end{document}

在此处输入图片描述

在此处输入图片描述

答案3

虽不完美,但这是一个开始:

\documentclass[
   final,
   12pt,
   a4paper,
   oneside
]{book}

\usepackage{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{lipsum}

\usepackage{fancyhdr}
    %\pagestyle{fancy}
    %\pagestyle{fancyplain}
    %\fancyhead{}
    %\fancyfoot{}
    \fancyhead[L]{}
    \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
    \fancyfoot[L]{\rule{2cm}{1cm}}
    \fancyfoot[R]{\thepage}
    \fancyfoot[C]{}
    \fancypagestyle{plain}{%
        \fancyhf{} % clear all header and footer fields
        \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
        \fancyfoot[L]{\rule{2cm}{1cm}}
        \fancyfoot[R]{\thepage}
        \fancyfoot[C]{}
        \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}}
    \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}



\begin{document}
\renewcommand{\cftchapaftersnum}{.}

\pagestyle{fancy}

\frontmatter
\pagenumbering{Roman}
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
\addcontentsline{toc}{chapter}{List of Listings}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\sectionmark{}
\lstlistoflistings

\mainmatter
\renewcommand{\sectionmark}[1]{\markright{\thesection~#1}}
\pagenumbering{arabic}
\onehalfspacing


\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\chapter{Some Chapter}
\lipsum[1]

\section{Some section}
\lipsum


\end{document}

这会在前页上保留第二行的空间,但不打印任何内容,因此标题行的高度保持不变。此外,只要有章节名称,它就会开始打印章节名称,如果没有章节名称,则会在标题中保留空白的第二行。当章节从同一页开始时,我只是没有成功在新章节开始的页面上打印章节名称,尽管我本以为重新定义 plain 应该可以解决问题。

相关内容