0

I am trying to make a gradient box with text with the right color completely blend with the background. Here is my document.

\documentclass{article}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
    \node[inner xsep=2mm,text width=5cm,left color=red,right color=white]
      {\parbox[t]{\textwidth}{\color{white}\sffamily\bfseries A}};
  \end{tikzpicture}
\end{document}

The result I got is this:

gradient1

I want the border at the right to be gone and the right color to completely blend with the background like this:

gradient2

I tried fade with transparency from this post but the result is the same.

Any help will be highly appreciated.

2
  • If available, opaque (transparent) would be the better choice. If available, you'd need to shift the fading point more to the left. See drawing programs, or even Excel.
    – MS-SPO
    Commented Jun 30, 2022 at 7:05
  • Can you give an example how to shift the fading point to the left?
    – Raja Ayaz
    Commented Jun 30, 2022 at 7:23

1 Answer 1

0

Use \usepgflibrary{shadings}, and put the middle color option last. Add text, e.g. by putting a node to anchor west.

P.S. See also e.g. Tikz gradient with 3 or more colors using pgfdeclarehorizontalshading

gradient

\documentclass[10pt, border=3mm]{standalone}

\usepackage{tikz}
\usepgflibrary{shadings}

% see pgf manual, ch. 69 Shadings Library

\begin{document}

    \tikz \draw[left color=red, right color=white, middle color=red!5]
    (0,0) rectangle (2,1);% middle must be last

\end{document}
2
  • Thank you. Could you post the example without the black border and with text?
    – Raja Ayaz
    Commented Jun 30, 2022 at 10:19
  • Kindly please check the manual(s) at ctan.org/pkg/pgf .
    – MS-SPO
    Commented Jun 30, 2022 at 11:16

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