1

In the code below, I want to produce a similar effect to the example on page 359 of the PGF manual.

\RequirePackage{fix-cm}
%\documentclass[tikz,preview]{standalone}
\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[
    margin = 0mm,
    paperwidth = 8cm,
    paperheight = 2cm
]{geometry}
\usepackage{tgbonum,tikz}

\usetikzlibrary{fadings}


\begin{document}
%
\tikzset{font = {\fontsize{20}{22}\selectfont} }
\begin{tikzfadingfrompicture}[name = latexnica]
    \node[text=transparent!20] at (0,0) {Establishmentless};% This text is too wide!
\end{tikzfadingfrompicture}

\begin{tikzpicture}
%   \node[
%%      inner sep = 1pt,
%       path fading = latexnica,
%       text = transparent,
%       top color = blue!85,
%       bottom color = orange!90
%   ] at (0,0) {Establishmentless};
    \node[text = white] (e) at (0,0) {Establishmentless};
    \shade[
        path fading = latexnica,
        fit fading = true,
        top color = blue!85,
        bottom color = orange!90
        ] (e.south west) rectangle (e.north east);
\end{tikzpicture}   

\end{document}

I obtain the attached image; as I commented in the code, the text of the fading (shading?) path is too wide; what I want is to have a rectangle with top blue part, bottom orange part and a faded text that reveals these colours. As you can see, I tried it using both a node and a rectangle of the same side (additionally, the key text = transparent shows the text in black. I'd like to understand why; in, so in the final picture I intend to use text = white).

How can I fit the text of the fading picture to the one I have below it? Thanks!

enter image description here

2
  • 2
    fit fading is the key. So PGF will do some rescaling to make sure that things don't go out of bounds. You need to read the manual carefully to understand how the rescaling works.
    – Symbol 1
    Commented May 29, 2020 at 3:03
  • 2
    You only need to set fit fading=false. (I find the manual a bit confusing here.)
    – user194703
    Commented May 29, 2020 at 3:21

1 Answer 1

3

This post is written under the assumption that you do not want to simply use fit fading=false. I am largely repeating this answer. If you set fit fading to true, then TikZ will use \pgfsetfadingforcurrentpath (or \pgfsetfadingforcurrentpathstroked if the path has a stroked curve). The pgfmanual v3.1.5 says about this option on p. 1202

enter image description here

However, this is not the case. Rather, as discovered in this answer, the box is really 50pt times 50pt large. Indeed, if we rescale the node underlying the latexnica fading to have these dimensions, the correct result is obtained.

\RequirePackage{fix-cm}
%\documentclass[tikz,preview]{standalone}
\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[
    margin = 0mm,
    paperwidth = 8cm,
    paperheight = 2cm
]{geometry}
\usepackage{tgbonum,tikz}

\usetikzlibrary{fadings}

\newsavebox\fadbox

\begin{document}
%
\tikzset{font ={\fontsize{20}{22}\selectfont}}
\savebox\fadbox{\begin{tikzpicture}
\node at (0,0) {Establishmentless};
\end{tikzpicture}}%
\begin{tikzfadingfrompicture}[name = latexnica]
    \node[text=transparent!20,xscale=50pt/\wd\fadbox,yscale=50pt/\ht\fadbox] 
    at (0,0) {Establishmentless};% 
\end{tikzfadingfrompicture}

\begin{tikzpicture}
%   \node[
%%      inner sep = 1pt,
%       path fading = latexnica,
%       text = transparent,
%       top color = blue!85,
%       bottom color = orange!90
%   ] at (0,0) {Establishmentless};
    \node[text = white] (e) at (0,0) {Establishmentless};
    \shade[
        path fading = latexnica,
        fit fading = true,
        top color = blue!85,
        bottom color = orange!90
        ] (e.south west) rectangle (e.north east);
\end{tikzpicture}   

\end{document}

enter image description here

So I think that there could be an issue, which got reported here, where you can also find some technical details that IMHO support the conjecture of a slight error in the manual.

2
  • I do not recommend using fadings. There are a lot of buggy viewers. Commented May 29, 2020 at 9:52
  • 1
    As always, Mr. Cat, quite useful! Thanks! Commented May 29, 2020 at 17:56

You must log in to answer this question.

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