TransWikia.com

Fading in two directions with unshaded middle - Faded rectangles create "lines at boundaries"

TeX - LaTeX Asked by twister on February 24, 2021

I’d like to do some fading of my background page from the middle to top and bottom – so far as good. My Problem is that I don’t want to start the fading immediatly (e.g. the upper third is faded, the middle third is background color, the lower third is faded).

So my suggestions are two ways:
a) Manipulate somehow the fading speed (I read the corresponding thread but was not able to do the necessary adjustments) and work with "color top", "color bottom", and "color middle".
b) Draw two rectangles at the top and the bottom which are faded in one direction.

My problem: While a) looks "good" but has no extended middle background color part, b) creates some mysterious lines in my output file at the boundaries (the lines are not printed in texmaker but in all of my pdf viewers):

boundaries at fading rectangles

Below a minimal working example for version b:

documentclass{report}
usepackage{tikz}
usetikzlibrary{calc,fadings}
definecolor{colorBackground}{RGB}{65,110,131}

begin{document}

begin{tikzpicture}[remember picture,overlay]
  fill[color=colorBackground] (current page.north west) rectangle (current page.south east);
  fill[top color=colorBackground!0, bottom color=colorBackground] (current page.north west) rectangle ($(current page.north west)+(paperwidth,-10cm)$);
  fill[top color=colorBackground, bottom color=colorBackground!0] (current page.south west) rectangle ($(current page.south west)+(paperwidth,+10cm)$);
end{tikzpicture}

end{document}

Kind regards!

One Answer

I cannot reproduce the lines you describe and they are likely a viewer artefact. If your document will be printed, that's not a big deal. Otherwise, you might see if this works any better. You will need to adjust the specific points at which the shading changes. I don't know what paper you are using, so I'm not sure what is needed for 10cm. However, I think that you want to change colour at (25bp-(10cm/paperheight)*50bp) and (75bp-(10cm/paperheight)*50bp). The shading should total 100bp by 100bp. Only the middle ninth of it will be used i.e. the middle third vertically and the middle third horizontally. So imagine a square divided into thirds horizontally and vertically. Your square needs to be 100bp in length and the middle square will be the bit actually used.

That is, that bit will be used in this case. If you were rotating it or something, it gets more complicated. But you're not rotating it, so it is (relatively!) straightforward.

documentclass{report}
usepackage{tikz}
definecolor{colorBackground}{RGB}{65,110,131}

begin{document}

pgfdeclareverticalshading[colorBackground]{pageshade}{100bp}{%
  color(0bp)=(white);
  color(25bp)=(white);
  color(40bp)=(colorBackground);
  color(60bp)=(colorBackground);
  color(75bp)=(white);
  color(100bp)=(white)
}

begin{tikzpicture}[remember picture, overlay]
  shade [shading=pageshade] (current page.north east) rectangle (current page.south west);
end{tikzpicture}


end{document}

custom shading

Correct answer by cfr on February 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP