I am trying to get a gradient to work with 3 distinct positions by using \pgfdeclarehorizontalshading. I have read the docs here and it seems rather straightforward that the different colors should be positioned at the exact widths indicated. Unfortunately, in practice I do not get those results. I have also adapted my code from another answer here, but for some reason I cannot extrapolate from this answer for my needs. Here is a MWE and the relevant code pasted below:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{calc}
\newlength{\mymargin}
\setlength{\mymargin}{0.125in}
\usepackage
[
paperwidth=11in,paperheight=17in,layoutwidth=10.75in,layoutheight=16.75in,
left=\mymargin,right=\mymargin,top=\mymargin,bottom=\mymargin,
bindingoffset=0in,landscape=true,marginparwidth=0in,marginparsep=0in
]{geometry}
\pgfdeclarehorizontalshading{grad}{.5in}{
color(0cm)=(white);
color(2.5cm)=(white);
color(5cm)=(pink);
color(8cm)=(black);
color(10cm)=(black)
}
\begin{document}
\begin{tikzpicture}[remember picture,overlay,every node/.style={inner sep=0,outer sep=0}]
\fill[shading=grad,shading angle=0] (current page.north west) ++ (1in,-3in) rectangle ++ (15in,-3in);
\end{tikzpicture}
\end{document}
The reasons why I am not satisfied with this are:
- First, it does not go from pure white to pure pink to pure black, at least not in the portion that is visible, and changing the size of this rectangle does not seem to do the trick.
- My understanding is that the positions of the different colors act as percentages, since from what I read the 0 is the left and whatever the last value is (as they are sorted ascendingly) is the right-most value. However, this does not seem to be the case as when I change units from cm to in the actual gradient changes, which I do not understand.
- Third, I am not certain as to why, in the answer referenced above, the same color is repeated: is that to get a pure color for a given space? because if so (which seems to make sense) then I cannot seem to reproduce this feature in my example, as is plain to see...
- Finally, I see that by adjusting the height (second parameter of the \pgfdeclarehorizontalshading command), I can get the gradient to fill the whole rectangle, but I am still surprised as to why the rendering is the way it is, with a black band at the bottom?
My final goal is thus to understand exactly how I can define N=3 or more colors such that a ruler, say in cm, spaced into those N segments has the peak color at those given limits exactly. Thanks!
[EDIT 1] It has been suggested by @Ulrike that the units should be in bp and sum to 100bp, which might be the case. However, this does not, on its own, seem to solve the problem. Here is an example:
\pgfdeclarehorizontalshading{grad}{100bp}{
color(0bp)=(white);
color(25bp)=(white);
color(49bp)=(pink);
color(50bp)=(red);
color(51bp)=(pink);
color(80bp)=(black);
color(100bp)=(black)
}
\begin{tikzpicture}[remember picture,overlay,every node/.style={inner sep=0,outer sep=0}]
\fill[shading=grad,shading angle=0] (current page.north west) ++ (2cm,-4cm) rectangle ++ (10cm,-1cm);
\end{tikzpicture}
This produces the following screenshot, in which the red zone is not centered:
color(0cm)=white; color(0.2cm)=white; color(0.4cm)=pink; color(0.4cm)=pink etc...
until 2cm.