\documentclass{book} \usepackage[explicit]{titlesec} \usepackage{tikz} \usepackage{lipsum} \usepackage{fancyhdr} \colorlet{sectcolor}{gray!65} \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}
选自:http://tex.stackexchange.com/questions/100677/use-of-shaded-box-for-section-numbering-only
发表评论 取消回复