1

Quick and hopefully easy question. Is there a way to apply fading both to the filling and to the border of a tikz path?

mwe

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
  \node at (1, 0.5) {\Large\bfseries fading};
  \draw[ultra thick, fill=purple, path fading=east] (0,0) rectangle (2,1);
\end{tikzpicture}
\end{document}

result

enter image description here

I'd like the black border to fade to alpha in the same way of the filling.

EDIT: Reading the comments it seems something specific to my setup, probably poppler/Evince, with chrome-integrated reader it works fine.

Here's the pdf: https://www.dropbox.com/s/vn402eaw7kil3cj/fade.pdf?dl=0

and the log file: https://www.dropbox.com/s/lhz9fclot9n0qpx/fade.log?dl=0

So, is there a way to make it work with all PDF readers? Not sure it matters, but I can draw something similar with inkscape (just setting border fill to gradient) and it works fine.

  • 1
    Mine is fading with the exact same code O_o i.stack.imgur.com/HdcjJ.png – Phelype Oleinik Jan 26 '18 at 12:20
  • @PhelypeOleinik weird, texlive 2017? – filippo Jan 26 '18 at 12:25
  • 1
    Works for me with pdflatex from texlive 2017 i.stack.imgur.com/XXBNT.png. Also works with xelatex. – user36296 Jan 26 '18 at 13:55
  • 1
    Any PDF reader is an impossible task. Adobe has the reference implementation. Sumatra on Windows is also pretty good. I see the faded border in your link by the way. So should you I guess – percusse Jan 26 '18 at 15:05
  • 1
    @filippo As a workaround you could stack the red rectangle without boarder on top of a black rectangle (a bit larger) with fading. – user36296 Jan 26 '18 at 15:11
1

Workaround:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
  \fill[black, path fading=east] (-0.07,-0.07) rectangle (2.07,1.07);
    \node at (1, 0.5) {\Large\bfseries fading};
  \fill[purple, path fading=east] (0,0) rectangle (2,1);
\end{tikzpicture}
\end{document}

enter image description here

  • Great, now I just need to find a way to make it work with more complex paths. Do you know if is there a way to scale a path with respect to its center? That way I could use just duplicate the path, scale it up, and fill it with black – filippo Jan 26 '18 at 15:27
  • @filippo Maybe something like tex.stackexchange.com/a/399382/36296 could help – user36296 Jan 26 '18 at 15:54
  • thank you that's perfect (at least for paths with proper symmetry) – filippo Jan 26 '18 at 16:18

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.