如何在页眉中添加如下所示的图形,其中页眉底部的线从左侧开始,长 1 厘米,图形之间有 3 厘米的间隙,并且线继续延伸剩余长度:
- 数字 - - - - - - - - -
我的 .cls 中有一行使用此代码运行:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test-report}
\newif\if@print
\LoadClass[10pt]{book}
\RequirePackage{fancyhdr}
\RequirePackage[pdftex]{geometry}
\RequirePackage{xcolor}
\def\titlefont{\rmfamily}
\def\titlestyle{\titlefont\titleshape\bfseries}
\colorlet{title}{black}
%% Fancy style for the main matter.
\fancypagestyle{mainmatter}{%
\fancyhf{}
%% Page numbers on the top left and top right.
\fancyhead[LE,RO]{\titlefont\thepage}
}
%% The mainmatter style is default for normal pages.
\pagestyle{mainmatter}
%% Print the current chapter and section at the top of the page in cyan.
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\ \color{title}#1}{}}
\renewcommand*\sectionmark[1]{\markright{\thesection.\ \color{title}#1}}
%% The setheader command can be used to print the title of unnumbered chapters
%% in the page header.
\newcommand*\setheader[1]{\markboth{\color{title}#1}{\color{title}#1}}
%% Change the headrule command (from fancyhdr.sty) to draw the line below the
%% header in the title color.
\renewcommand*\headrule{%
\if@fancyplain%
\let\headrulewidth\plainheadrulewidth%
\fi%
{\color{title}\hrule\@height\headrulewidth\@width\headwidth}%
\vskip-\headrulewidth%
}
我的文本文件:
\documentclass{test-report}
\begin{document}
\mainmatter
some text
\end{document}
ps. 我使用的是 sharelatex
答案1
也许以下内容会有所帮助
\documentclass[10pt]{book}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{graphicx}
\def\titlefont{\rmfamily}
\colorlet{title}{black}
%% Fancy style for the main matter.
\fancypagestyle{mainmatter}{%
\fancyhf{}
%% Page numbers on the top left and top right.
\fancyhead[LE,RO]{\titlefont\thepage}
%% Chapter name on the left (even) page.
\fancyhead[RE]{\titlefont\nouppercase{\leftmark}}
%% Section name on the right (odd) page.
\fancyhead[LO]{\titlefont\nouppercase{\rightmark}}
}
%% The mainmatter style is default for normal pages.
\pagestyle{mainmatter}
%% Print the current chapter and section at the top of the page in cyan.
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\ \color{title}#1}{}}
\renewcommand*\sectionmark[1]{\markright{\thesection.\ \color{title}#1}}
%% The setheader command can be used to print the title of unnumbered chapters
%% in the page header.
\newcommand*\setheader[1]{\markboth{\color{title}#1}{\color{title}#1}}
%% Change the headrule command (from fancyhdr.sty) to draw the line below the
%% header in the title color.
\makeatletter
\renewcommand*\headrule{%
\if@fancyplain%
\let\headrulewidth\plainheadrulewidth%
\fi%
{\color{title}%
\rule{1cm}{\headrulewidth}%
\raisebox{-\baselineskip}[0pt][0pt]{%
\parbox[b]{3cm}{\centering%
\ifdim\headrulewidth>0pt\includegraphics[height=2\baselineskip]{example-image}\fi
}}%
\rule{\dimexpr\textwidth-4cm\relax}{\headrulewidth}%
}%
\vskip-\headrulewidth%
}
\makeatother
%% enlarge headsep and headheight
\geometry{headsep=2\baselineskip,headheight=20.5pt}
\begin{document}
\mainmatter
\noindent some text
\end{document}
结果:
或者
\documentclass[10pt]{book}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{graphicx}
\def\titlefont{\rmfamily}
\colorlet{title}{black}
%% Fancy style for the main matter.
\fancypagestyle{mainmatter}{%
\fancyhf{}
%% Page numbers on the top left and top right.
\fancyhead[LE,RO]{\titlefont\thepage}
%% Chapter name on the left (even) page.
\fancyhead[RE]{\titlefont\nouppercase{\leftmark}}
%% Section name on the right (odd) page.
\fancyhead[LO]{\titlefont\nouppercase{\rightmark}}
}
%% The mainmatter style is default for normal pages.
\pagestyle{mainmatter}
%% Print the current chapter and section at the top of the page in cyan.
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\ \color{title}#1}{}}
\renewcommand*\sectionmark[1]{\markright{\thesection.\ \color{title}#1}}
%% The setheader command can be used to print the title of unnumbered chapters
%% in the page header.
\newcommand*\setheader[1]{\markboth{\color{title}#1}{\color{title}#1}}
%% Change the headrule command (from fancyhdr.sty) to draw the line below the
%% header in the title color.
\makeatletter
\renewcommand*\headrule{%
\if@fancyplain%
\let\headrulewidth\plainheadrulewidth%
\fi%
{\color{title}%
\rule{1cm}{\headrulewidth}%
\smash{%
\parbox[b]{3cm}{\centering%
\ifdim\headrulewidth>0pt\includegraphics[height=2\baselineskip]{example-image}\fi
}%
\rule{\dimexpr\textwidth-4cm\relax}{\headrulewidth}%
}}%
\vskip-\headrulewidth%
}
\makeatother
%% enlarge headheight
\geometry{headheight=20pt}
\begin{document}
\mainmatter
\noindent some text
\end{document}