4

I am trying to draw some of the headers for a document with TikZ inside a fancy custom header, using the following code:

\documentclass[letter,11pt]{article}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{lastpage}

\fancypagestyle{aero450}
{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}

    \fancyhead[C]{

        \begin{tikzpicture}[remember picture]

            \draw (current bounding box.center) node (__head_c)
                [font=\scriptsize]
            {HEADER HEADER HEADER};

        \end{tikzpicture}

    }
}

\pagestyle{aero450}

\begin{document}
    TEST TEST TEST
\end{document}

However, either with xelatex, pdflatex or writelatex.com, I get the following error:

Runaway argument? 
{ \begin {tikzpicture}[remember picture] 
Paragraph ended before \f@ncyhf was complete. <to be read again> 
\par l.23 \pagestyle{aero450}

What am I doing wrong? writelatex.com says that I might have forgotten a }, but I am pretty sure that I haven't...

  • @Werner, have you taken a look at the writelatex example? What did you use for compiling it? – Ricardo Jan 13 '14 at 6:28
  • 1
    Your writelatex example doesn't match the code above. Especially it has blank lines inside the tikzpicture environment, which is causing the problem. – Werner Jan 13 '14 at 6:32
  • You are right @Werner, I deleted one blank line after \begin{tikzpicture}, the one that was causing the problem. Thanks. – Ricardo Jan 13 '14 at 6:34
  • @Werner, so I can remake my question: I cannot add blank lines to the contents of a \chead{}-like command from the fancyhdr package? – Ricardo Jan 13 '14 at 17:56
3

The problem here is the blank lines inside your definition of \fancyhead. However, this translates to \fancyfoot. The reason here is that \fancyhead (\fancyfoot) - defined using \newcommand - calls an internal, universal macro \f@ncyhf - defined using \def - that stores the header/footer. The former \newcommand-created macros accept paragraph breaks (I'll call it \long-content), but the latter \def-created macro only accepts non-\long content. That is, you can't have paragraphs inside them, and since an empty line denotes a paragraph break, it flags an error.

Solution: Remove the blank lines, or use % as a line separator if you wish to air out your code.

As reference, see

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.