fancyhdr 中水平线的替代品

fancyhdr 中水平线的替代品

我正在寻找一种更别致的替代方案,以取代包装下方默认的(读作无聊的)水平线fancyhdr。我们可以有多有创意?

答案1

这里有五种可能性:两条规则(一条在下面,一条在上面);下面是一条双色规则;用pgfornament; 一个彩色圆角框和一个彩色框架(最后两个使用 TikZ 制作)。为了制作标题,我使用了titleps包,但是fancyhdr也可以这样使用:

\documentclass[draft]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage[object=vectorian]{pgfornament}
\usepackage{tikzpagenodes}
\usepackage{titleps}
\usepackage{lipsum}

\newpagestyle{mystyle}{
  \sethead{}{\thesection~\sectiontitle}{\thepage}\headrule
}
\pagestyle{mystyle}

\newcommand\myrule{%
  \leavevmode\cleaders\hbox{\raisebox{-2.5pt}{\pgfornament[width=0.2\textwidth]{88}}}\hfill\kern0pt}

\begin{document}

\renewcommand\makeheadrule{\color{red!70!black}%
  \makebox[0pt][l]{%
    \rule[.8\baselineskip]{\linewidth}{0.8pt}}%
    \rule[-.3\baselineskip]{\linewidth}{0.8pt}%
}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\renewcommand\makeheadrule{\color{red!70!black}%
  \makebox[0pt][l]{%
    \rule[-.3\baselineskip]{\linewidth}{0.4pt}}%
    \rule[-.4\baselineskip]{\linewidth}{0.4pt}%
}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\renewcommand\makeheadrule{\myrule}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\renewcommand\makeheadrule{%
\begin{tikzpicture}[remember picture,overlay]
  \draw[cyan,thick,rounded corners=5pt] 
  ([xshift=-3pt]current page header area.north west) 
    rectangle
  ([xshift=2pt,yshift=-3pt]current page header area.south east);
\end{tikzpicture}}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\renewcommand\makeheadrule{%
\begin{tikzpicture}[remember picture,overlay]
  \fill[orange] 
  (current page.north west) 
    rectangle
  ([xshift=2pt,yshift=-3pt]current page.east|-current page header area.south east);
\end{tikzpicture}}
\section{Test Section}
\lipsum[4]\lipsum[4]

\end{document}

在此处输入图片描述

还有一些其他的例子,主要是为了展示可能性:

\documentclass[draft]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{tikzpagenodes}
\usepackage{titleps}
\usepackage{lipsum}
\usetikzlibrary{shapes.symbols}

\newpagestyle{mystyleii}{
  \sethead{}{{\begin{tikzpicture}
    \node[draw=olive,rectangle,fill=olive!30,text width=.5\textwidth,inner xsep=0pt,align=center] at (current page header area.center) (header) {\thesection~\sectiontitle};
  \end{tikzpicture}}}{}
  \setfoot{}{{\begin{tikzpicture}
  \node[draw=olive,rectangle,fill=olive!30,text width=3em,inner xsep=0pt,align=center] at (current page footer area.center) {\thepage};
  \end{tikzpicture}}}{}
}
\pagestyle{mystyleii}


\begin{document}

\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\newpagestyle{mystyleiii}{
  \sethead{}{{\begin{tikzpicture}
    \node[draw=none,rectangle,left color=olive!40,right color=orange!40,text width=.5\textwidth,inner xsep=0pt,align=center] at (current page header area.center) (header) {\thesection~\sectiontitle};
  \end{tikzpicture}}}{}
  \setfoot{}{{\begin{tikzpicture}
  \node[draw=none,rectangle,left color=olive!40,right color=orange!40,text width=3em,inner xsep=0pt,align=center] at (current page footer area.center) {\thepage};
  \end{tikzpicture}}}{}
}
\pagestyle{mystyleiii}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\addtolength\headheight{29pt}
\newpagestyle{mystyleiv}{
  \sethead{}{{\begin{tikzpicture}
    \node[draw=none,starburst,line width=2pt,draw=red,fill=yellow!40,text width=.5\textwidth,inner xsep=0pt,align=center] at (current page header area.center) (header) {\thesection~\sectiontitle};
  \end{tikzpicture}}}{}
  \setfoot{}{{\begin{tikzpicture}
  \node[draw=none,starburst,line width=2pt,draw=red,fill=yellow!40,text width=3em,inner xsep=0pt,align=center] at (current page footer area.center) {\thepage};
  \end{tikzpicture}}}{}
}
\pagestyle{mystyleiv}
\section{Test Section}
\lipsum[4]\lipsum[4]

\end{document}

在此处输入图片描述

还有一些其他的可能性,现在使用由杰利迪亚兹his answer撕页效果

\documentclass[draft]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{tikzpagenodes}
\usepackage{titleps}
\usepackage{lipsum}
\usetikzlibrary{decorations.pathmorphing,calc,shadows.blur,shadings}
\pgfmathsetseed{1}

\pgfdeclaredecoration{irregular fractal line}{init}
{
  \state{init}[width=\pgfdecoratedinputsegmentremainingdistance]
  {
    \pgfpathlineto{\pgfpoint{random*\pgfdecoratedinputsegmentremainingdistance}{(random*\pgfdecorationsegmentamplitude-0.02)*\pgfdecoratedinputsegmentremainingdistance}}
    \pgfpathlineto{\pgfpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}}
  }
}

\tikzset{
   paper/.style={draw=black!10, blur shadow, shade=bilinear interpolation,
                 lower left=black!20, upper left=black!15, upper right=white, lower right=black!10},
   irregular border/.style={decoration={irregular fractal line, amplitude=0.2},
           decorate,
     },
   ragged border/.style={ decoration={random steps, segment length=7mm, amplitude=2mm},
           decorate,
   }
}

\newpagestyle{mystylev}{
  \sethead{}{\thesection~\sectiontitle}{\thepage}\headrule
  \setfoot{}{}{}
}
\pagestyle{mystylev}
\renewcommand\makeheadrule{%
\begin{tikzpicture}[remember picture,overlay]
  \fill[red!30!cyan!60]
        decorate[irregular border]{decorate{decorate{decorate{decorate[ragged border]{
        ($(current page header area.south east-|current page.east) - (0, random*30mm)$) -- ($(current page header area.south west-|current page.west) - (0, random*12mm)$)
        }}}}}
        -- (current page.north west) -- (current page.north east) -- cycle;
\end{tikzpicture}
}

\begin{document}

\section{Test Section}
\lipsum[4]\lipsum[4]

\end{document}

在此处输入图片描述

答案2

一个带有简单框的示例。您还可以使用 tikz 或 pgf 命令来制作更复杂的标题:

\documentclass[fleqn,11pt,pdflatex]{book}
\usepackage{microtype}
\usepackage{times}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{xcolor}

\usepackage{fancyhdr}%
\pagestyle{fancy}%
\setlength\fboxsep{1pt}
\setlength\fboxrule{1pt}
\fancyhf{}%
\fancyfoot[LO]{\colorbox{red}{\makebox[1cm]{\thepage}}\mbox{\hskip2pt}\colorbox{black!5}{\makebox[\linewidth-2cm-4pt-4\fboxrule-4\fboxsep]{\leftmark}}\mbox{\hskip2pt}\colorbox{blue}{\makebox[1cm]{\thesection}}}%
\fancyfoot[RE]{\colorbox{red}{\makebox[1cm]{\thepage}}\colorbox{black!5}{\makebox[\linewidth-2cm-4pt-4\fboxrule-4\fboxsep]{\rightmark}}\colorbox{blue}{\makebox[1cm]{\thesection}}}%
\begin{document}
\chapter{chapter}
\section{section a}
\lipsum[1-10]
\section{section b}
\lipsum[1-10]
\section{section c}
\lipsum[1-10]

得出的结果是:

在此处输入图片描述

相关内容