页眉中章节/部分名称旁边的页码

页眉中章节/部分名称旁边的页码

我想将页码放在章节/部分名称旁边没有下划线的空白处(就像在包中一样classicthesis(我看过那个包,但似乎他们使用的包已被弃用))。不幸的是,我的尝试并没有真正起作用,因为它总是将页码放在右侧(即使在左页)。

\documentclass[
fontsize=12pt,                  
open=right,         
twoside = true,
paper=a4]
{scrreprt}

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

\usepackage{fancyhdr}
\pagestyle{fancy}   
\fancyhf{}                                              
\usepackage{lmodern}




\newcommand{\funnypagenumberright}{
    \setlength{\unitlength}{1in}%
    \begin{picture}(0,0)%
    \put(.1,0){{\thepage}}
    \end{picture}}

\newcommand{\funnypagenumberleft}{
    \setlength{\unitlength}{1in}%
    \begin{picture}(-0.1,0)%
    \put(0,0){{\thepage}}
    \end{picture}}

\begin{document}
    \rhead{}
    \lhead{} 
    \rfoot{}
    \lfoot{} 
    \fancyhead[LE]{\nouppercase{\leftmark~\funnypagenumberleft}}
    \fancyhead[RO]{\nouppercase{\rightmark~\funnypagenumberright}}
\blinddocument
\end{document}

在此处输入图片描述

答案1

scrlayer-scrpage这是使用KOMA-Script 软件包的一部分的建议。在那里,您可以放大页眉宽度.2in,然后使用它\makebox[2in][...]{\pagemark}来打印页码。

\documentclass[
fontsize=12pt,
open=right,
twoside = true,
paper=a4]
{scrreprt}

\usepackage[english,]{babel}
\usepackage[T1]{fontenc}        
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage{lmodern}

\usepackage[automark,markcase=noupper]{scrlayer-scrpage}
\KOMAoptions{
  headsepline=:text,
  headwidth=\dimexpr\textwidth+.2in\relax:0pt
}
\renewcommand\chaptermarkformat{\chapapp~\thechapter.\enskip}
\clearmainofpairofpagestyles
\lehead{\makebox[.2in][l]{\pagemark}~\headmark}
\rohead{\headmark~\makebox[.2in][r]{\pagemark}}
\addtokomafont{pageheadfoot}{\upshape}

\begin{document}
\blinddocument
\end{document}

在此处输入图片描述


或者头部宽度不变的情况下\makebox[0pt]...

\documentclass[
fontsize=12pt,
open=right,
twoside = true,
paper=a4]
{scrreprt}

\usepackage[english,]{babel}
\usepackage[T1]{fontenc}        
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage{lmodern}

\usepackage[automark,markcase=noupper,headsepline]{scrlayer-scrpage}
\renewcommand\chaptermarkformat{\chapapp~\thechapter.\enskip}
\clearmainofpairofpagestyles
\lehead{\makebox[0pt][r]{\pagemark\hspace{.1in}}~\headmark}
\rohead{\headmark~\makebox[0pt][l]{\hspace{.1in}\pagemark}}
\addtokomafont{pageheadfoot}{\upshape}

\begin{document}
\blinddocument
\end{document}

在此处输入图片描述

但如果你想使用fancyhdr

\documentclass[
fontsize=12pt,
open=right,
twoside = true,
paper=a4]
{scrreprt}

\usepackage[english,]{babel}
\usepackage[T1]{fontenc}        
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage{lmodern}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\nouppercase{\makebox[0pt][r]{\thepage\hspace{.1in}}~\leftmark}}
\fancyhead[RO]{\nouppercase{\rightmark~\makebox[0pt][l]{\hspace{.1in}\thepage}}}

\begin{document}
\blinddocument
\end{document}

答案2

您看到了有关 KOMA-Script 的消息并且最好不要使用fancyhdr

通过以下更改您可以获得想要的结果:

移至\funnypagenumberleft的左侧\leftmark

\fancyhead[LE]{\nouppercase{\funnypagenumberleft~\leftmark}}

并将宏更改\funnypagenumberleft为(查看更改后的数字!):

\newcommand{\funnypagenumberleft}{
    \setlength{\unitlength}{1in}%
    \begin{picture}(0,0)%
    \put(-0.2,0){{\thepage}}
    \end{picture}}

完整代码:

\documentclass[%
  fontsize=12pt,
  open=right,
  twoside=true,
  paper=a4
]{scrreprt}

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

\usepackage{blindtext}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\usepackage{lmodern}


\newcommand{\funnypagenumberright}{
    \setlength{\unitlength}{1in}%
    \begin{picture}(0,0)%
    \put(.1,0){{\thepage}}
    \end{picture}}

\newcommand{\funnypagenumberleft}{
    \setlength{\unitlength}{1in}%
    \begin{picture}(0,0)%
    \put(-0.2,0){{\thepage}}
    \end{picture}}

\begin{document}
\rhead{}
\lhead{} 
\rfoot{}
\lfoot{} 
\fancyhead[LE]{\nouppercase{\funnypagenumberleft~\leftmark}}
\fancyhead[RO]{\nouppercase{\rightmark~\funnypagenumberright}}
\blinddocument
\end{document}

结果:

在此处输入图片描述

相关内容