26

Is there the possiblity to make a color gradient in the rectangular box in the following example from the bottom left to the top right corner (both in linear or radial shape)?

\documentclass{article}
\usepackage{tikz}

\usepackage{xcolor}

\definecolor{left} {HTML}{001528}

\begin{document}

  \begin{tikzpicture}[remember picture,overlay]
    \node [rectangle, left color=left, right color=left!30!white, anchor=north, minimum width=\paperwidth, minimum height=5.5cm] (box) at (current page.north){};
  \end{tikzpicture}



\end{document}

Thanks for your help!

3
  • I understand the question for linear, I think, but I have no idea what you are looking for in the radial case. How would that look different from just a bog-standard radial shading? Also, please make your code compilable. As it stands, I am certain that it will not do so!
    – cfr
    Commented Dec 7, 2014 at 22:21
  • For the radial case I meant somethin like this: encrypted-tbn3.gstatic.com/… but just with the center of the lightest point in the top right corner Commented Dec 7, 2014 at 22:23
  • fixed my code, now its compilable Commented Dec 7, 2014 at 22:42

2 Answers 2

28

You can use shading = axis and shading angle=135

\documentclass{article}
\usepackage{tikz}

\definecolor{left} {HTML}{001528}

\begin{document}

  \begin{tikzpicture}[remember picture,overlay]
    \node [shading = axis,rectangle, left color=left, right color=left!30!white,shading angle=135, anchor=north, minimum width=\paperwidth, minimum height=5.5cm] (box) at (current page.north){};
  \end{tikzpicture}
\end{document}

enter image description here

0
17

I hope this is what you mean:

variant shadings and fadings

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fadings,through}

\definecolor{left} {HTML}{001528}

\begin{document}

  \begin{tikzpicture}[remember picture,overlay]
    \node [rectangle, left color=left, right color=left!30!white, anchor=north, minimum width=\paperwidth, minimum height=5.5cm] (box) at (current page.north){};
    % manual 181
    \node [rectangle, fill=left!30!white, postaction={path fading=north, fading angle=-45, fill=left}, anchor=north, below=10mm of box, minimum width=\paperwidth, minimum height=5.5cm] (box1) {};
    \begin{scope}
      \clip (box1.south west) +(0,-10mm) coordinate (c1) rectangle +(\paperwidth,-150mm) coordinate (c2);
      \node [inner color=left!30!white, outer color=left, circle through={(c1 |- c2)}] at (c1 -| c2) {};
    \end{scope}
  \end{tikzpicture}

\end{document}
4
  • I like your 2nd option the most. But there is to the very right side a kind of mistake in the fading. A few pixels from the top to the bottom are not fading. Why is that? Commented Dec 8, 2014 at 9:00
  • @AdrianPfeifle I'm not sure why that happens. I thought it might be an artefact of my PDF viewer since I've seen similar before, when others haven't. Does it reproduce for you?
    – cfr
    Commented Dec 8, 2014 at 13:38
  • yes I get the same result Commented Dec 8, 2014 at 13:48
  • but I'm not sure if the other answer produces the same result as your 2nd option should or if there is a difference? Because there I don't get the mistake on the right side Commented Dec 8, 2014 at 13:49

You must log in to answer this question.

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