4

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}

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

\fancypagestyle{firstpage}{
    \fancyhead[L]{Name:}
    \fancyhead[C]{Period:}
}

\begin{document}
\thispagestyle{firstpage}

First Page

\end{document}

enter image description here 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}{%

\renewcommand\headrule{%

%%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!

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

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}
\setlength\headheight{16pt}
\renewcommand\headrule{%
    \vspace{-0.75in}
    \hrulefill
    {\tikz[decoration=Koch snowflake]{\draw \MyDeco;}}%
    \xdef\MyDeco{decorate{\MyDeco}}%
}
\xdef\MyDeco{decorate{ (0,-2) -- (3,-2) }}
\fancypagestyle{firstpage}{
    \fancyhead[L]{Name:}
    \fancyhead[C]{Period:}
}

\pagestyle{firstpage}

\begin{document}

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

\end{document}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.