TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the following MWE i define a fading monfading with the command \tikzfading which is then used in the command \fill.

  \tikzfading[name=monfading,left color=transparent!100,right color=transparent!0]
    \node[anchor=south west] at (0,0) {HALLO} ;   
    \fill[draw=black,path fading=monfading,fill=white] (0,0) rectangle (1.5,1);

Now, i encounter some difficulties, because my tikz picture is actually in the header of the page (i use \RequirePackage[pagestyles]{titlesec}), and there, it seems not to remember the definition of \tikzfading. Therefore, i would like to put the definition of monfading directly in the \fill command. Therefore something like :

%Pseudocode : 
    \node[anchor=south west] at (0,0) {HALLO} ;   
    \fill[draw=black,path fading={left color=transparent!100,right
    color=transparent!0},fill=white] (0,0) rectangle (1.5,1);

How i can make this pseudo code a real code?

share|improve this question
Couldn't you just put the \tikzfading command into your preamble? – Jake Apr 13 '12 at 16:29
it doesn't work either. The definition of monfading seems to be forgotten in the header. I could make a MWE for this, but before i was looking for a quick solution, like my pseudo-code – nicolas roy Apr 13 '12 at 16:30
For this concrete example, you can just use \fill[draw=black, path fading=west, fill=white] (0,0) rectangle (1.5,1);. Is your real fading more complicated? – Jake Apr 13 '12 at 16:42
Oh, i see, actually i redefined a completely standard fading, which already exists under the name ẁest. This is enough for me, i just needs this fading (for the moment). Thanks. But I am still interested in the general answer to the question. – nicolas roy Apr 13 '12 at 16:56
\tikzset{ define fading/.code={ \tikzfading[#1] } } allows you to define a new fading within your drawing command. Doesn't solve the header problem though, so I'm not sure if there's any utility for this. – Jake Apr 13 '12 at 17:10

The problem here is that when TikZ/PGF uses a fading it has to put the code necessary for that fading into the PDF near the start. So it stores all of this in a token register that is processed at the end of the document using \AtEndDocument. But this hook is executed before the last \clearpage. This is a problem if the fadings are in headers or footers because these are only processed at the \clearpage. So the necessary code for doing the fadings is processed too late to make it into the PDF. The solution is to ensure that the fading stuff is done after the last page has been fully processed (ie shipped). There are a number of ways to achieve this:

  1. File a bug report and get TikZ/PGF changed.
  2. Edit pgfutil-latex.def and change \AtEndDocument{\the\pgfutil@everybye} to \AtEndDocument{\clearpage\the\pgfutil@everybye}.
  3. Issue a \clearpage before the end of the document, either manually or automatically. If automatically, ie via \AtEndDocument, then put this before loading tikz.
  4. Use the package atveryend and put:


    at the start of the document. Note that in the main TikZ/PGF code then this is the only use of \AtEndDocument. A couple of the libraries also use it, notably the external library, and I haven't experimented with whether or not they are okay being after the \clearpage or not. Experiment.

  5. Use the atveryend package and edit pgfutil-latex.def and change \AtEndDocument to \AfterLastShipout (probably best to add \RequirePackage{atveryend} to this file as well).
  6. Use one of the other solutions at Can I hook into the end of the document but *after* the `\clearpage`?

Here's some working code without modifying any of the TikZ code:


   %% HEADER - depends on option

        \node[rectangle,baseline=current bounding
box.base,anchor=south east,inner ysep =0cm,inner xsep =0cm](mabox) at
(0,0) {\sectiontitle};
        \fill[path fading=west,fill=white] (-5,0) rectangle (0,1em);

\section{ ABCD EFGH IJKLM NOPQR 1111 2222 3333 4444}



share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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