采用titlesec进行代码尝试设计,效果图如下:
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{xcolor,lipsum}
\usepackage{fancyhdr}
\colorlet{sectcolor}{gray!35}
\newcommand\graysquare{\textcolor{sectcolor}{\rule{1ex}{1ex}}}
\newcommand{\helv}{\fontfamily{phv}\fontseries{}\fontsize{10}{12}\selectfont}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\fancyhf{}
\fancyhead[RO]{\helv\rightmark\hspace{0.5em}\graysquare\hspace{0.5em}\thepage}
\fancyhead[LE]{\helv\thepage\hspace{0.5em}\graysquare\hspace{0.5em}\leftmark}
\renewcommand{\headrulewidth}{0pt}
\titleformat{\section}
{\normalfont\Large\bfseries}
{\llap{\colorbox{sectcolor}{\makebox[3em][r] {\thesection}}\hspace{1em}}}
{0em}{#1}
\begin{document}
\setcounter{chapter}{1}% just for the example
\section{Introduction}
A cross-reference to the last section:~\ref{sec:conclusion}.
\lipsum[4]
\section{Discussion}
\lipsum[4]
\section{Conclusion}
\label{sec:conclusion}
\lipsum[4]
\end{document}
发表评论 取消回复