The issue: making a background gradient with tikz I had the following problem. The resolution of gradient is very low and hatched lines appear. (see an MWE + picture below)

The question: Is it possible to increase the resolution so that the gradient be smooth?

\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns,calc}

\definecolor{mydb} {RGB}{68,48,0}

\begin{document}

\begin{tikzpicture}[remember picture,overlay]
\node [shading = axis,rectangle, left color=mydb, right color=mydb!30!white,shading angle=135, anchor=north, minimum width=45.5cm, minimum height=25.5cm, samples=2000] (box) at (10,25){};
\end{tikzpicture}
\begin{tikzpicture}
\node[minimum height=210mm,minimum width=148.5mm,outer sep=0pt] (a)
{};

\end{tikzpicture}

\end{document}


• Are you using latexdvipsps2pdf by any chance? If so, I think you are out of luck because of how the shadings are constructed in Level 2 PostScript. If you are using pdflatex, then I think this is a viewer issue. It looks bad for me in some viewers (notably acroread 9), but good in zathura (poppler based viewer). – David Purton Aug 29 '19 at 13:28
• @David Purton Using either latex → dvips → ps2pdf, either pdflatex I'm getting, more or less, the same result. I think that the interesting issue is the possibility of changing the resolution from tikz itself. I'm not sure whether this is possible or not. – Grigorios Kostakos Aug 29 '19 at 13:58
• You could change it for the dvips driver by rewriting the PostScript. But believe me, you don't want to do this unless you are crazy :). The pdftex driver uses a built in PDF function for the gradient. tikz does not have control over how it renders. Rather viewers decide how they will render the shading, so you get different output from different viewers. Banding effects are also increased when your two colours are very similar as there aren't as many colours to go in between. – David Purton Aug 29 '19 at 14:07
• Your other option is to render the gradient yourself to a bitmap using ghostscript and include the bitmap. This also gives a smooth gradient for me. – David Purton Aug 29 '19 at 14:10
• BTW, the samples=2000 has no effect on your shading. – David Purton Aug 29 '19 at 14:33

I use Asymptote adapted with gkov's code, and find that axialshade seems to be better than TikZ's shade.

size(210mm,148.5mm);
pen pena=RGB(68,48,0), penb=.3pena+.7white;
pair a=plain.SW, b=plain.NE;

//x.asy
// compiling F5 on texstudio on Windows 10
// Build "C:\Program Files (x86)\Asymptote/asy.exe" -f pdf -noView %.asy
// ImageMagick: magick -density 960 x.pdf x.png

• This doesn't give better banding than tikz when I view it in acroread, which confirms my suspicion that this problem is basically a viewer issue. – David Purton Aug 30 '19 at 6:40
• Nevertheless, It would be very functional to have something analog to the option samples that we have for tikz-lines! – Grigorios Kostakos Aug 30 '19 at 15:12
• @GrigoriosKostakos, actually it wouldn't help much. With 8bit colour channels there isn't 2000 shades between your two colours anyway. – David Purton Sep 1 '19 at 6:42