代码摘选: % ---------------------------------------------------------------- % Book Class (This is a LaTeX2e document) *********************** % ---------------------------------------------------------------- \documentclass[10pt,x11names,svgnames,twoside]{book} \usepackage{tikz} \usetikzlibrary{shapes.misc,calc} \usepackage{lipsum,fancyhdr} \usepackage[a4paper,left=1.2in,right=1in,top=1in,bottom=1in,headheight=\baselineskip, headsep=9mm,footskip=13mm,showframe,]{geometry} % ---------------------------------------------------------------- \newcommand\MyColor{% % This line is from Gonzalo's answer \ifcase\thechapter blue!30\or red!30\or olive!30\or magenta!30\else yellow!30\fi} % This line is from Gonzalo's answer %------------------------------------------ \fancypagestyle{plain}{% %% Clear all headers and footers \fancyhf{} %% Right headers on odd pages \fancyhead[RO]{% \rotatebox{90}{ \begin{tikzpicture}[overlay,remember picture] \node[fill=\MyColor,text=white, font=\footnotesize, inner ysep=12pt, inner xsep=20pt, rounded rectangle,anchor=east, at ($ (current page.north east) + (2.9cm,-0cm) + (-4*\thechapter cm,0cm) $) {\sffamily\itshape\small\nouppercase{\leftmark}}; \end{tikzpicture} } } %% Left headers on even pages \fancyhead[LE]{% \rotatebox{90}{ \begin{tikzpicture}[overlay,remember picture] \node[fill=\MyColor,text=white, font=\footnotesize, inner ysep=12pt, inner xsep=20pt, rounded rectangle,anchor=east, at ($ (current page.north west) + (4cm,0cm) + (-4*\thechapter cm,0cm) $) {\sffamily\itshape\small\nouppercase{\leftmark}}; \end{tikzpicture} } } \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} \fancyfoot[R]{\thepage} } % ---------------------------------------------------------------- \pagestyle{plain} \renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}} \begin{document} % \chapter{First chapter} \lipsum[1-16] \cleardoublepage \chapter{Second chapter} \lipsum[1-16] \chapter{Third chapter} \lipsum[1-16] \chapter{Fourth chapter} \lipsum[1-16] % \end{document} \documentclass{book} \usepackage{background} \usetikzlibrary{calc} \usepackage{ifthen} \usepackage{lipsum} \pagestyle{plain} % background common settings \SetBgScale{1} \SetBgAngle{0} \SetBgOpacity{1} \SetBgContents{} % auxiliary counter \newcounter{chapshift} \addtocounter{chapshift}{-1} % the list of colors to be used (add more if needed) \newcommand\BoxColor{% \ifcase\thechapshift blue!30\or red!30\or olive!30\or magenta!30\else yellow!30\fi} % the main command; the mandatory argument sets the color of the vertical box \makeatletter \newcommand\ChapFrame{% \AddEverypageHook{% \ifthenelse{\isodd{\thepage}} {\SetBgContents{% \begin{tikzpicture}[overlay,remember picture] \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=2cm, at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $) {\rotatebox{90}{\hspace*{.3cm}\parbox[c][1.5cm][t]{3.4cm}{% \raggedright\textcolor{black}{\scshape\leftmark}}}}; \end{tikzpicture}}% } {\SetBgContents{% \begin{tikzpicture}[overlay,remember picture] \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=2cm, at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $) {\rotatebox{90}{\hspace*{.3cm}\parbox[c][1.5cm][t]{3.4cm}{% \raggedright\textcolor{black}{\scshape\leftmark}}}}; \end{tikzpicture}} } \bg@material}% \stepcounter{chapshift} } \makeatother % redefinition of \chaptermark to contain only the title \renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}} \begin{document} \chapter[intro]{Introduction} \ChapFrame \lipsum[1-7] \chapter{Results} \ChapFrame \lipsum[1-7] \chapter{Discussion} \ChapFrame \lipsum[1-7] \end{document}
扫描下方二维码,关注数学中国微信获取更多实用信息!
|