# fancyhdr - Koch Snowflake as part of \headrule

I have redefined the \headrule to include part of the the Koch Snowflake from the \usetikzlibrary{decorations.fractals} package. Here is my code and a screenshot:

\documentclass[10pt]{article}
\usepackage{fancyhdr}
\usepackage{tikz}
\usetikzlibrary{decorations.fractals}

\vspace{-0.75in}
\hrulefill
{\tikz[decoration=Koch snowflake]{\draw decorate{ decorate{ decorate{ (0,-2) -- (3,-2) }}};}}
}

\fancypagestyle{firstpage}{
}

\begin{document}
\thispagestyle{firstpage}

First Page

\end{document}


My goal is to have the nth iteration of the snowflake corresponding with the nth page of my document (My document will only be around 5-6 pages). My idea is to use some type of for loop to do this. I'm imagining something similar to this, where I am redefining the headrule for each page.

\foreach \x in {1,...,final page}{%

%%something with koch snowflake here%%

}

}



I think I need the number of decoration commands to be equal to \thepage. I'm sure there is a way to do this, but I can't figure it out. Any help is appreciated!

• Welcome! Could you please add a complete example that works except for the Koch snowflake? – user194703 Feb 21 '20 at 19:57
• Sure! I have edited my post. – Logan Weinert Feb 21 '20 at 20:13
• Thanks! Cool question! – user194703 Feb 21 '20 at 20:57

You can recursively define a macro that picks up a new decorate on each page. This is done with

\xdef\MyDeco{decorate{\MyDeco}}


in

\documentclass[10pt]{article}
\usepackage{fancyhdr}
\usepackage{tikz}
\usetikzlibrary{decorations.fractals}
\vspace{-0.75in}
\hrulefill
{\tikz[decoration=Koch snowflake]{\draw \MyDeco;}}%
\xdef\MyDeco{decorate{\MyDeco}}%
}
\xdef\MyDeco{decorate{ (0,-2) -- (3,-2) }}
\fancypagestyle{firstpage}{
}

\pagestyle{firstpage}

\begin{document}

First Page
\clearpage
Second Page
\clearpage
Third Page
\clearpage
Fourth Page

\end{document}


• Neat. Thank you! I haven't seen \xdef before, so I'll have to read up on it. – Logan Weinert Feb 21 '20 at 22:50