TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a full page graphic (background) I am trying to duplicate using Tikz. The original was created in MS 2010 power point (all details and parameters are included below as is an initial MWE).

I am wondering if Tikz can give me control over the following parameters that Power point did.

  • n number of middle colors (inner and outer are logical enough, but it would be nice to have some extra stops). I did try superimposing images of different sizes, but got stripes, not gradients, and now I can't remember how I previously did that.
  • Position - I think this would be best implemented by a percentage of the width and/or height page dimensions that control to what extent the colors are split. For example compiling my MWE demonstrates that the Black triangles in the corner are much larger than in the power point controls and this were adjusted with the position percentage.
  • Brightness and Transparency (I think these are self explanatory and will be consistent and dependent on the colors provided).

Here are the power point details for the three stops in the radial gradient fill that I was able to produce in power point

Stop 1

  • Color black
  • Position 3%
  • Brightness -15%
  • Transparency 0%

Stop 2

  • Color black
  • Position 96%
  • Brightness 0%
  • Transparency 0%

Stop 3

  • Color Aqua (Accent 5)
  • Position 50%
  • Brightness 0%
  • Transparency 0%

Screenshot for (3) Multistop Formatting Controls enter image description here

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

\usepackage{flowfram}
\usepackage{tcolorbox}

\usepackage[%
%showframe,
%letterpaper,
papersize={100cm,100cm},
%includehead,
%includefoot,
left=1.0cm,
right=1.0cm,
top=1.0cm,
headheight=0.0cm,
bottom=1.0cm,
footskip=1.0cm
%hmargin=3cm,vmargin=3.75cm %only used to get rid of a overfull \hbox warning.
]{geometry}

%Aqua accent 5 is close to
%75-172-198
%HEX Number:
%4bacc6
\definecolor{AquaA5}{HTML}{4bacc6}

%Black is pre-coded so it doesn't need to be redefined but for reference here are some values
%RGB CODE:
%0-0-0
%HEX Number:
%000000

\begin{document}

  \begin{tikzpicture}[remember picture,overlay]
      \node [rectangle, inner color=AquaA5, outer color=black, anchor=north, minimum width=\paperwidth, minimum height=\paperheight] (box) at (current page.north){};

  \end{tikzpicture}

\end{document}

Currently I just import a jpeg saved from power point and use tikz to save it as the full page background, but I would like to be able to do this dynamically for any size page geometry without having to save a new version from power point.

\documentclass[]{article}

\usepackage[%
%showframe,
%letterpaper,
papersize={100cm,100cm},
%includehead,
%includefoot,
left=1.0cm,
right=1.0cm,
top=1.0cm,
headheight=0.0cm,
bottom=1.0cm,
footskip=1.0cm
%hmargin=3cm,vmargin=3.75cm %only used to get rid of a overfull \hbox warning.
]{geometry}

\usepackage{tikz}
\pagestyle{empty}
\begin{document}

    \begin{tikzpicture}[remember picture,overlay]
    % draw image
    \node[inner sep=0] at (current page.center)
    {\includegraphics[width=\paperwidth,height=\paperheight]{RadialPictureExport.jpg}};
    \end{tikzpicture}

\end{document}

Finally: Yay, my first TikZ question.

share|improve this question
    
Yes it can. You can declare your own shadings as shown in the manual. – percusse Jan 10 at 19:03
    
I think brightness is not an aspect of the shading for TikZ, at least. It is part of the specification of the colour or colours. And transparency can be altered with fill opacity in the usual way, can't it? – cfr Jan 10 at 19:55
up vote 10 down vote accepted

Something like this?

fancy radial shading

\documentclass[border=5pt, multi, tikz]{standalone}
\pgfdeclareradialshading[fradialcolour]{fradial}{\pgfpoint{0}{0}}{% manual 1082-1083
  color(0)=(black);
  color(20bp)=(fradialcolour);
  color(40bp)=(black)
}
\colorlet{fradialcolour}{blue!50!cyan}
\begin{document}
\begin{tikzpicture}
  \fill [shading=fradial] (0,0) rectangle (2,2);
\end{tikzpicture}
\end{document}

You can set this up so that any or all of the three colours used in the shading can be specified when specifying the settings for the path in a picture. (And, of course, you could define a shading involving more than three colours.)

For example,

\pgfdeclareradialshading[fradialcolour1,fradialcolour2,fradialcolour3]{fradial}{\pgfpoint{0}{0}}{% manual 1082-1083; later - shading is assumed to be 100bp diameter ??
  color(0)=(fradialcolour1);
  color(20bp)=(fradialcolour2);
  color(40bp)=(fradialcolour3)
}

This makes the shading depend on a list of three colours, fradialcolour1, fradialcolour2 and fradialcolour3, which can then be set within a tikzpicture by setting up some appropriate PGF/TikZ keys.

\tikzset{%

First some code to set each of the colours.

  fradial inner colour/.code={
    \colorlet{fradialcolour1}{#1}
  },
  fradial mid colour/.code={
    \colorlet{fradialcolour2}{#1}
  },
  fradial outer colour/.code={
    \colorlet{fradialcolour3}{#1}
  },

Now set some defaults so these are always defined.

  fradial inner colour=black,
  fradial outer colour=black,
  fradial mid colour=white,

A key to shade without specifying colours.

  fancy radial/.style={
    shading=fradial,
  },

And now some keys to change one of the colours and use the shading.

  fancy radial inner/.style={
    fradial inner colour=#1,
    shading=fradial,
  },
  fancy radial outer/.style={
    fradial outer colour=#1,
    shading=fradial,
  },
  fancy radial mid/.style={
    fradial mid colour=#1,
    shading=fradial,
  },
}

We can then say something like this:

\begin{tikzpicture}
  \fill [fancy radial] (0,0) rectangle +(2,2);
  \fill [fancy radial inner=blue!50!cyan] (2,0) rectangle +(2,2);
  \fill [fancy radial outer=blue!50!cyan] (4,0) rectangle +(2,2);
  \fill [fancy radial mid=blue!50!cyan] (6,0) rectangle +(2,2);
  \fill [fancy radial inner=blue!50!cyan!25!black, fancy radial outer=blue!50!cyan!50!black, fancy radial mid=blue!50!cyan!25!white] (8,0) rectangle +(2,2);
\end{tikzpicture}

to produce this result:

variations on a shading

Complete code:

\documentclass[border=5pt, multi, tikz]{standalone}
\pgfdeclareradialshading[fradialcolour1,fradialcolour2,fradialcolour3]{fradial}{\pgfpoint{0}{0}}{% manual 1082-1083; later - shading is assumed to be 100bp diameter ??
  color(0)=(fradialcolour1);
  color(20bp)=(fradialcolour2);
  color(40bp)=(fradialcolour3)
}
\tikzset{%
  fradial inner colour/.code={
    \colorlet{fradialcolour1}{#1}
  },
  fradial mid colour/.code={
    \colorlet{fradialcolour2}{#1}
  },
  fradial outer colour/.code={
    \colorlet{fradialcolour3}{#1}
  },
  fradial inner colour=black,
  fradial outer colour=black,
  fradial mid colour=white,
  fancy radial/.style={
    shading=fradial,
  },
  fancy radial inner/.style={
    fradial inner colour=#1,
    shading=fradial,
  },
  fancy radial outer/.style={
    fradial outer colour=#1,
    shading=fradial,
  },
  fancy radial mid/.style={
    fradial mid colour=#1,
    shading=fradial,
  },
}
\begin{document}
\begin{tikzpicture}
  \fill [fancy radial] (0,0) rectangle +(2,2);
  \fill [fancy radial inner=blue!50!cyan] (2,0) rectangle +(2,2);
  \fill [fancy radial outer=blue!50!cyan] (4,0) rectangle +(2,2);
  \fill [fancy radial mid=blue!50!cyan] (6,0) rectangle +(2,2);
  \fill [fancy radial inner=blue!50!cyan!25!black, fancy radial outer=blue!50!cyan!50!black, fancy radial mid=blue!50!cyan!25!white] (8,0) rectangle +(2,2);
\end{tikzpicture}
\end{document}

EDIT

To use this as a page background, you can use something like this:

\documentclass{article}
\usepackage{tikz}
\pgfdeclareradialshading[fradialcolour1,fradialcolour2,fradialcolour3]{fradial}{\pgfpoint{0}{0}}{% manual 1082-1083; later - shading is assumed to be 100bp diameter ??
  color(0)=(fradialcolour1);
  color(20bp)=(fradialcolour2);
  color(40bp)=(fradialcolour3)
}
\tikzset{%
  fradial inner colour/.code={
    \colorlet{fradialcolour1}{#1}
  },
  fradial mid colour/.code={
    \colorlet{fradialcolour2}{#1}
  },
  fradial outer colour/.code={
    \colorlet{fradialcolour3}{#1}
  },
  fradial inner colour=black,
  fradial outer colour=black,
  fradial mid colour=white,
  fancy radial/.style={
    shading=fradial,
  },
  fancy radial inner/.style={
    fradial inner colour=#1,
    shading=fradial,
  },
  fancy radial outer/.style={
    fradial outer colour=#1,
    shading=fradial,
  },
  fancy radial mid/.style={
    fradial mid colour=#1,
    shading=fradial,
  },
}
\usepackage[%
%showframe,
%letterpaper,
papersize={100cm,100cm},
%includehead,
%includefoot,
left=1.0cm,
right=1.0cm,
top=1.0cm,
headheight=0.0cm,
bottom=1.0cm,
footskip=1.0cm
%hmargin=3cm,vmargin=3.75cm %only used to get rid of a overfull \hbox warning.
]{geometry}

\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
  \fill [fancy radial mid=blue!50!cyan] (current page.south west) rectangle (current page.north east);
\end{tikzpicture}
\end{document}

background shading

share|improve this answer
    
Thanks, this is an amazing answer. When I expand my dimensions I don't however get a full page image, I observe a white border. I have tried to place this code within a node, but I am not having much luck. – EngBIRD Jan 10 at 21:30
    
It seems to work for me. Please see edit above for the way I did it. Without seeing your code, I'm not sure what you did or why it might not have worked. I adapted the above from the code you posted in the question, so it should work for you. – cfr Jan 10 at 21:44
    
This is indeed working great, for my understanding, I have a further question. The color(20bp) command doesn't seem to depend on the bp unit as I can drop the bp text and get the same thing, but more importantly as in my MWE, I set up page geometry of 100cm x 100 cm. But if I try and use color(0.25\paperwidth) (i.e. what I thought would have given the equivalent of 50% total diameter) the size over-encompasses the complete page size. The documentation says This maximum will also be the radius of the circle but I seem to be misapplying this statement. – EngBIRD Jan 10 at 22:55
    
@EngBIRD I don't completely understand it. I've never defined a new shading before that I recall. When I used cm, I got strange results. I think it has to do with the stuff about \pgfshadepath on page 1085-6. Then you don't have to worry about the \pgfbox point described just before. So TikZ then assumes that the shading is 100bpx100bp. And it arranges things so that the centre of the path is at 50/50, the south west at 0/0 and the north east at 100/100. Hence, the shading is automatically scaled in the usual way. So, for radial, the radius is assumed to be 50bp. I think. – cfr Jan 10 at 23:01
    
Ah, now I understand what your comment about the 100bp meant in the code solution. I misunderstood and thought it was the default value if not specified. Thanks!!! – EngBIRD Jan 10 at 23:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.