3

I'd like to fade some text, on its left and its right. I want the fading to be visually both :

  • progressive
  • complete (ie: when the fading ends, the text becomes invisible)

I didn't find any example of that.

I will illustrate what I tried with 5 examples. My fading is from the right to the left, and ends around the left-third of the text.

On texts A and B, I use a white fading. On texts C, D, E, I use a blue fading.

I tested 2 strategies :

  1. Using tikzfading (example A). But my text doesn't become completely invisible. The fading is not "complete".
  2. Drawing multiple tiny vertical stripes. I don't like the method, but the result is more what I expect. But when I print the document, or when I zoom in, I can see the stripes :-(

How I can achieve a complete fading like in B (or C), but without the stripes ?

\documentclass[tikz]{standalone}
\usetikzlibrary{fadings}
\tikzfading[name=fade example,left color=transparent!0,right color=transparent!100]
\begin{document}
{
    \begin{tikzpicture}           
    \draw((2,4) node[fill=white!80, text=black] {AAAAAAAAAAAAAAAAAAAA} ;
    \filldraw [draw=none, white, path fading=fade example] (1,3.5) rectangle (3,4.5);
    \end{tikzpicture}   
    
    \begin{tikzpicture}
    \draw((1,0.5) node[fill=white!80, text=black] {BBBBBBBBBBBBBBBBBBBBB} ;
    \foreach \x in {0,0.01,...,2.0}
    \filldraw [draw=none, white, opacity=\x/2.0] (2.0 - \x, 0) rectangle (1.96-\x, 1);
    \end{tikzpicture}
    
    \begin{tikzpicture}
    \draw((1,0.5) node[fill=white!80, text=black] {CCCCCCCCCCCCCCCCCCCCCC} ;
    \foreach \x in {0,0.01,...,2.0}
    \filldraw [draw=none, blue, opacity=\x/2.0] (2.0 - \x, 0) rectangle (1.96-\x, 1);
    \end{tikzpicture}   
    
    \begin{tikzpicture}
    \draw((1,0.5) node[fill=white!80, text=black] {DDDDDDDDDDDDDDDDDDDDDDD} ;
    \foreach \x in {0,0.001,...,2.0}
    \filldraw [draw=none, blue, opacity=\x/2.0] (1.999 - \x, 0) rectangle (2.0-\x, 1);
    \end{tikzpicture}
    
    \begin{tikzpicture}
    \draw((1,0.5) node[fill=white!80, text=black] {EEEEEEEEEEEEEEEEEEEEEEEE} ;
    \foreach \x in {0,0.001,...,2.0}
    \filldraw [draw=none, blue, opacity=\x/2.0] (1.999 - \x, 0) rectangle (2.001-\x, 1);
    \end{tikzpicture}

}
\end{document}

5 examples

zoom B

2 Answers 2

5

The fading does become invisible, but only at the very end. The issue is that the fading is not severe enough near the faded end. You can set middle color=transparent!50, which will produce your original image:

enter image description here

Setting middle color=transparent!10 fades from 0% to 10% in the first half, 10% to 100% in the second half, which produces

enter image description here

If you set middle color=transparent!2 you get

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\tikzfading[name=fade example,left color=transparent!0,right color=transparent!100,middle color=transparent!2]

\begin{document}
    \begin{tikzpicture}           
    \draw((2,4) node[fill=white, text=black] {AAAAAAAAAAAAAAAAAAAA} ;
    \filldraw [draw=none, white, path fading=fade example] (1,3.5) rectangle (3,4.5);
    \end{tikzpicture}  
\end{document}
1
  • Ah, middle color!... Of course. I probably saw this option but forgot about it... I just played with it, I think that's exactly what I was looking for. Thanks!
    – Michaël
    May 10, 2022 at 16:06
2

Here is a solution:

\documentclass[tikz]{standalone}
\usetikzlibrary{fadings}
\tikzfading[name=fade example,left color=transparent!0,right color=transparent!0,middle color=transparent!100]
\begin{document}

\begin{tikzpicture}           
  \node[draw,fill=white!80,text=black] (my text) {AAAAAAAAA} ;
  \filldraw [draw=none, white, path fading=fade example] (my text.south west) rectangle (my text.north east);
\end{tikzpicture}   

\end{document}

Note: the fading is complete (look at borders) but the text remains visible because it does not go all the way to the borders.

enter image description here

2
  • I think that's more or less what I did with my A-example, where my 7th "A" is faded but still visible. But that's not what I'm looking for. I want something like my B-example, where the 7th "B" becomes invisible (not just faded).
    – Michaël
    May 10, 2022 at 15:12
  • Sorry, I just noticed that you mentioned the "middle color" option in your answer. As I said, the result is not invisible enough for me at the edges of the text, but I can produce it with this option and a few lines. Thanks!
    – Michaël
    May 10, 2022 at 16:15

You must log in to answer this question.

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