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...

4
  • @Werner, have you taken a look at the writelatex example? What did you use for compiling it?
    – nsx
    Jan 13, 2014 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, 2014 at 6:32
  • You are right @Werner, I deleted one blank line after \begin{tikzpicture}, the one that was causing the problem. Thanks.
    – nsx
    Jan 13, 2014 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?
    – nsx
    Jan 13, 2014 at 17:56

1 Answer 1

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

2
  • Thanks for the explanation @Werner. It is quite a tough-to-resolve problem.
    – nsx
    Jan 13, 2014 at 18:13
  • there's an [unouter](mirror.ctan.org/macros/plain/contrib/misc/unouter.tex which removes \outer flags from commands. a similar (possibly even less hair-raising) technique might well work for adding \long Jan 14, 2014 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .