Take the 2-minute tour ×
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.

I want to put a TikZ figure with a fading effect (which I reproduced in the body of the document as illustration) in the page header, which I set with the package titlesec. The following MWE seems to indicate that it doesn't work. Any workaround?

\documentclass[12pt]{article}
\usepackage{tikz}

\usetikzlibrary{fadings}
\usepackage[pagestyles]{titlesec}


\newpagestyle{teststyle}{
 \renewcommand{\makeheadrule}{%
  \color{blue}%
  \rule[-.3\baselineskip]{\linewidth}{1pt}}
   %% HEADER - depends on option
  \sethead{}%
   {}%
   {%
   \FadingSection
   }%
}

\newcommand{\FadingSection}{%
    \begin{tikzpicture}[baseline=(mabox.base)]
        \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);
    \end{tikzpicture}   
}

\begin{document}
\pagestyle{teststyle}
\section{ ABCD EFGH IJKLM NOPQR 1111 2222 3333 4444}
\FadingSection

\end{document}
share|improve this question
1  
Please no formatting in the question title. It's not supported and isn't very readable in verbatim form. Also "doesn't work" doesn't help. State the issue in more detail (e.g. how the output is off exactly; any error messages, etc.). And adding an image if applicable always helps as well. –  Martin Scharrer Apr 13 '12 at 17:17
add comment

2 Answers

up vote 6 down vote accepted

This seems to be a bug in PGF/TikZ related to PDF specials like fading, patterns and transparency applied outside the main body of the page. I encountered the same issue with transparencies with some of my code as well, when I tried to add them inside the output routine. Apparently some PDF dictionary is not updated or connected properly. I think talked about this with Joseph Wright, which knows more about output drivers etc. than me.

This particular issue happens only with single page documents. It works with when the document has more than one page. I guess at \end{document} some PDF stuff is flushed to early. You can fix this by adding a \newpage directly before it, so that the current page is flushed before the end of the document is reached. There will be no trailing empty page because of this as long there is no material after the \newpage. BTW, adding \AtEndDocument{\newpage} is not the same, because it comes to late.

In the following code the fading in the section title works correctly:

\documentclass[12pt]{article}
\usepackage{tikz}

\usetikzlibrary{fadings}
\usepackage[pagestyles]{titlesec}


\newpagestyle{teststyle}{
 \renewcommand{\makeheadrule}{%
  \color{blue}%
  \rule[-.3\baselineskip]{\linewidth}{1pt}}%
   %% HEADER - depends on option
  \sethead{}%
   {}%
   {%
   \FadingSection
   }%
}

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

\pagestyle{teststyle}
\begin{document}
\section{ABCD EFGH IJKLM NOPQR 1111 2222 3333 4444}
\FadingSection
\newpage% Required to make it work
\end{document}
share|improve this answer
    
Yes, I've also encountered this same problem with PGF/TikZ and one page documents in my background package. –  Gonzalo Medina Apr 13 '12 at 18:51
    
@GonzaloMedina: I have to check if there is a TikZ bug report about this. –  Martin Scharrer Apr 13 '12 at 18:54
    
Great! Please let me know if you find something. –  Gonzalo Medina Apr 13 '12 at 18:55
    
@Martin : more precisely, this bug appears always at the "last page of the document", and not only "if the document has a single page". Thanks anyway for the hint! –  nicolas roy Apr 14 '12 at 15:18
    
@nicolasroy: Ah, yes, that's also possible, but depends on how the last page is flushed I think. I tested it with some two-page document without \newpage and it worked fine; in that specific case I mean. –  Martin Scharrer Apr 14 '12 at 15:31
add comment

I think I've found the bug. On line 300 of pgfsys-pdftex.def there is a reference to a pgfsmaks. All around it are references to pgfsmasks. When I made the obvious change, I no longer got complaints about the last page's fading being missing.

Here's the diff.

--- pgfsys-pdftex.def   2010-10-25 23:00:21.000000000 +0200
+++ pgfsys-pdftex.def   2012-04-22 22:06:25.000000000 +0200
@@ -297,7 +297,7 @@
     \PackageError{pgf}{Undefined fading '#1'}{}%
   \else%
     {%
-      \expandafter\ifx\csname pgfsmaks@#1\endcsname\relax%
+      \expandafter\ifx\csname pgfsmask@#1\endcsname\relax%
         \pgf@sys@pdf@install@mask{#1}%
       \fi%
       \pgftransformreset%

I just checked a later version of PGF (just noticed the date on the file above) and it had the same spelling mistake.

share|improve this answer
add comment

Your Answer

 
discard

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.