以下代码给出了某种风格书籍的示例页面。
\documentclass[a4paper]{book}
\setlength\headheight{0cm}
\usepackage{xcolor}
\colorlet{headbgcolor}{green!50!blue!70}
\setlength{\topmargin}{-1.5cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand\chaptermark[1]{\markboth{\chaptername\ \thechapter:\enskip#1}{}}
\fancyhf{}
\fancyhead[LE]{%
\makebox[0pt][r]{
\colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries\textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
{\itshape\leftmark}\hspace*{1em}\headrulefill%
}
\fancyhead[RO]{%
\mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
\makebox[0pt][l]{%
\hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip \bfseries\textcolor{white}{\thepage}}}}%
}
\renewcommand\headrulewidth{0pt}
\def\headrulefill{\leaders\hrule width 0pt height 3pt depth -2.8pt \hfill}
\usepackage{blindtext}% dummy text
\fancypagestyle{plain}{
\fancyhf{}
\fancyhead[LE]{%
\makebox[0pt][r]{
\colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries \textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
{\itshape\leftmark}\hspace*{1em}\headrulefill%
}
\fancyhead[RO]{%
\mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
\makebox[0pt][l]{%
\hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip\bfseries\textcolor{white}{\thepage}}}}%
}
}
\usepackage{mathptmx}
\begin{document}
\blinddocument
\end{document}
我想知道是否有任何方法可以按照下图中箭头指示的方向增加此文档类中文本块的宽度:我尝试使用 geometry 包和 \setlength{\rightmargin}{...} 中的命令,但无济于事。任何帮助都感激不尽。我感觉我错过了一些很明显的东西……
答案1
而不是使用
\setlength\headheight{0cm}
\setlength{\topmargin}{-1.5cm}
您最好使用包。从您的屏幕截图来看,我猜 topmargin 、 rightmargin和 textwidthgeometry
的值是您需要的值。如果不是,请根据需要更改它们。tmargin=2cm
rmargin=3cm
width=14cm
因此添加命令
\usepackage[rmargin=3cm,tmargin=2cm,width=14cm]{geometry} % <===========
在你的序言中应该做你想做的事。
拥有完整的 MWE
\documentclass[a4paper]{book}
%\setlength\headheight{0cm}
%\setlength{\topmargin}{-1.5cm}
\usepackage[rmargin=3cm,tmargin=2cm,width=14cm]{geometry} % <===========
\usepackage{xcolor}
\colorlet{headbgcolor}{green!50!blue!70}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand\chaptermark[1]{\markboth{\chaptername\ \thechapter:\enskip#1}{}}
\fancyhf{}
\fancyhead[LE]{%
\makebox[0pt][r]{
\colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries\textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
{\itshape\leftmark}\hspace*{1em}\headrulefill%
}
\fancyhead[RO]{%
\mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
\makebox[0pt][l]{%
\hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip \bfseries\textcolor{white}{\thepage}}}}%
}
\renewcommand\headrulewidth{0pt}
\def\headrulefill{\leaders\hrule width 0pt height 3pt depth -2.8pt \hfill}
\usepackage{blindtext}% dummy text
\fancypagestyle{plain}{
\fancyhf{}
\fancyhead[LE]{%
\makebox[0pt][r]{
\colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries \textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
{\itshape\leftmark}\hspace*{1em}\headrulefill%
}
\fancyhead[RO]{%
\mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
\makebox[0pt][l]{%
\hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip\bfseries\textcolor{white}{\thepage}}}}%
}
}
\usepackage{mathptmx}
\begin{document}
\blinddocument
\end{document}
我得到的结果: