5

Using the current page command from this answer

\documentclass[tikz,border=4pt]{standalone}
\usepackage{bm}
\usetikzlibrary{fadings}

\begin{document}

\def\hori{3}
\def\vert{2}
\def\zColor{black!40!green}
\def\EkColor{yellow!40}

\begin{tikzpicture}
\path
    (0,0) node (v) {$v$}
    (v) ++ (\vert,0) node (+1) {$\oplus$}
    (v) ++ (\vert,\vert) node (y1) {$y_1$}
    (+1) ++ (\hori,0) node (+2) {$\oplus$}
    (+1) ++ (\hori,\vert) node (y2) {$y_2$}
    (+2) ++ (\hori,0) node (+3) {$\oplus$}
    (+2) ++ (\hori,\vert) node (y3) {$y_3$}
    (+3) ++ (0.75*\hori,0) node (+dots) {$~\cdots~$}
    (+dots) ++ (0.75*\hori,0) node (+n) {$\oplus$}
    (+dots) ++ (0.75*\hori,\vert) node (yn) {$y_n$}
    (+n) ++ (\hori,0) node (z) {${\color{\zColor}\bm{z}}$};
\draw
    (y1) edge [-stealth] (+1)
    (y2) edge [-stealth] (+2)
    (y3) edge [-stealth] (+3) 
    (yn) edge [-stealth] (+n);
\draw
    (v) edge [-stealth] (+1)
    (+1) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+2)
    (+2) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+3)
    (+3) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+dots) 
    (+dots) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+n)
    (+n) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (z) ;
\end{tikzpicture}


\begin{tikzpicture}
\path
    (0,0) node (v) {$v$}
    (v) ++ (\vert,0) node (+1) {$\oplus$}
    (v) ++ (\vert,\vert) node (y1) {$y_1$}
    (+1) ++ (\hori,0) node (+2) {$\oplus$}
    (+1) ++ (\hori,\vert) node (y2) {$y_2$}
    (+2) ++ (\hori,0) node (+3) {$\oplus$}
    (+2) ++ (\hori,\vert) node (y3) {$y_3$}
    (+3) ++ (0.75*\hori,0) node (+dots) {$~\cdots~$}
    (+dots) ++ (0.75*\hori,0) node (+n) {$\oplus$}
    (+dots) ++ (0.75*\hori,\vert) node (yn) {$y_n$}
    (+n) ++ (\hori,0) node (z) {${\color{\zColor}\bm{z}}$}
    (+n) ++ (\hori,\vert) node (topr) {};
\draw
    (y1) edge [-stealth] (+1)
    (y2) edge [-stealth] (+2)
    (y3) edge [-stealth] (+3) 
    (yn) edge [-stealth] (+n);
\draw
    (v) edge [-stealth] (+1)
    (+1) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} node [below] (botl) {\phantom{$E_k$}} (+2)
    (+2) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+3)
    (+3) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+dots) 
    (+dots) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+n)
    (+n) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (z) ;

\fill[black, path fading=west] (current page.south west) rectangle (current page.north east);
\end{tikzpicture}

The first bit of code yields the correct image :

enter image description here

while the second piece of code doesn't :

enter image description here

Rather than shade the whole page,

  1. it shades the bottom half only,
  2. it doesn't shade what is at the very right
  3. and it changes the page size in the process.

How Would I do it properly, i.e. shade the correct region and not change the dimensions of the page ?

  • @marmot the answer I quote uses overlay, but when I include it, it produces rubbish. Do you know how to do it? – Olivier Bégassat May 17 '18 at 21:02
  • 2
    For that case, why not use current bounding box instead of current page? – Torbjørn T. May 17 '18 at 21:05
  • 1
    @TorbjørnT. You are right... I posted that not knowing that your comment is here... – user121799 May 17 '18 at 21:06
  • 1
    @marmot Never mind. – Torbjørn T. May 17 '18 at 21:07
  • 1
    Unrelated: you should in general use \newcommand and not \def, as the latter will overwrite existing macros without telling you. (\vert already exists.) It might not break anything in this case, but if you're a bit careless with macronames one day, you might end of breaking your document. – Torbjørn T. May 17 '18 at 21:10
4

You may just shade the picture. If you remove border=4pt then the full thing will be shaded.

\documentclass[tikz,border=4pt]{standalone}
\usepackage{bm}
\usetikzlibrary{fadings}

\begin{document}

\def\hori{3}
\def\vert{2}
\def\zColor{black!40!green}
\def\EkColor{yellow!40}

\begin{tikzpicture}
\path
    (0,0) node (v) {$v$}
    (v) ++ (\vert,0) node (+1) {$\oplus$}
    (v) ++ (\vert,\vert) node (y1) {$y_1$}
    (+1) ++ (\hori,0) node (+2) {$\oplus$}
    (+1) ++ (\hori,\vert) node (y2) {$y_2$}
    (+2) ++ (\hori,0) node (+3) {$\oplus$}
    (+2) ++ (\hori,\vert) node (y3) {$y_3$}
    (+3) ++ (0.75*\hori,0) node (+dots) {$~\cdots~$}
    (+dots) ++ (0.75*\hori,0) node (+n) {$\oplus$}
    (+dots) ++ (0.75*\hori,\vert) node (yn) {$y_n$}
    (+n) ++ (\hori,0) node (z) {${\color{\zColor}\bm{z}}$};
\draw
    (y1) edge [-stealth] (+1)
    (y2) edge [-stealth] (+2)
    (y3) edge [-stealth] (+3) 
    (yn) edge [-stealth] (+n);
\draw
    (v) edge [-stealth] (+1)
    (+1) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+2)
    (+2) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+3)
    (+3) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+dots) 
    (+dots) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+n)
    (+n) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (z) ;
\end{tikzpicture}


\begin{tikzpicture}
\path
    (0,0) node (v) {$v$}
    (v) ++ (\vert,0) node (+1) {$\oplus$}
    (v) ++ (\vert,\vert) node (y1) {$y_1$}
    (+1) ++ (\hori,0) node (+2) {$\oplus$}
    (+1) ++ (\hori,\vert) node (y2) {$y_2$}
    (+2) ++ (\hori,0) node (+3) {$\oplus$}
    (+2) ++ (\hori,\vert) node (y3) {$y_3$}
    (+3) ++ (0.75*\hori,0) node (+dots) {$~\cdots~$}
    (+dots) ++ (0.75*\hori,0) node (+n) {$\oplus$}
    (+dots) ++ (0.75*\hori,\vert) node (yn) {$y_n$}
    (+n) ++ (\hori,0) node (z) {${\color{\zColor}\bm{z}}$}
    (+n) ++ (\hori,\vert) node (topr) {};
\draw
    (y1) edge [-stealth] (+1)
    (y2) edge [-stealth] (+2)
    (y3) edge [-stealth] (+3) 
    (yn) edge [-stealth] (+n);
\draw
    (v) edge [-stealth] (+1)
    (+1) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} node [below] (botl) {\phantom{$E_k$}} (+2)
    (+2) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+3)
    (+3) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+dots) 
    (+dots) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+n)
    (+n) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (z) ;
\fill[black, path fading=west] (current bounding box.south west) 
rectangle (current bounding box.north east);
\end{tikzpicture}
\end{document}

As for your comment:

\documentclass[tikz,border=4pt]{standalone}
\usepackage{bm}
\usetikzlibrary{fadings}

\begin{document}

\def\hori{3}
\def\vert{2}
\def\zColor{black!40!green}
\def\EkColor{yellow!40}

\begin{tikzpicture}
\path
    (0,0) node (v) {$v$}
    (v) ++ (\vert,0) node (+1) {$\oplus$}
    (v) ++ (\vert,\vert) node (y1) {$y_1$}
    (+1) ++ (\hori,0) node (+2) {$\oplus$}
    (+1) ++ (\hori,\vert) node (y2) {$y_2$}
    (+2) ++ (\hori,0) node (+3) {$\oplus$}
    (+2) ++ (\hori,\vert) node (y3) {$y_3$}
    (+3) ++ (0.75*\hori,0) node (+dots) {$~\cdots~$}
    (+dots) ++ (0.75*\hori,0) node (+n) {$\oplus$}
    (+dots) ++ (0.75*\hori,\vert) node (yn) {$y_n$}
    (+n) ++ (\hori,0) node (z) {${\color{\zColor}\bm{z}}$};
\draw
    (y1) edge [-stealth] (+1)
    (y2) edge [-stealth] (+2)
    (y3) edge [-stealth] (+3) 
    (yn) edge [-stealth] (+n);
\draw
    (v) edge [-stealth] (+1)
    (+1) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+2)
    (+2) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+3)
    (+3) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+dots) 
    (+dots) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+n)
    (+n) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (z) ;
\end{tikzpicture}


\begin{tikzpicture}
\path
    (0,0) node (v) {$v$}
    (v) ++ (\vert,0) node (+1) {$\oplus$}
    (v) ++ (\vert,\vert) node (y1) {$y_1$}
    (+1) ++ (\hori,0) node (+2) {$\oplus$}
    (+1) ++ (\hori,\vert) node (y2) {$y_2$}
    (+2) ++ (\hori,0) node (+3) {$\oplus$}
    (+2) ++ (\hori,\vert) node (y3) {$y_3$}
    (+3) ++ (0.75*\hori,0) node (+dots) {$~\cdots~$}
    (+dots) ++ (0.75*\hori,0) node (+n) {$\oplus$}
    (+dots) ++ (0.75*\hori,\vert) node (yn) {$y_n$}
    (+n) ++ (\hori,0) node (z) {${\color{\zColor}\bm{z}}$}
    (+n) ++ (\hori,\vert) node (topr) {};
\draw
    (y1) edge [-stealth] (+1)
    (y2) edge [-stealth] (+2)
    (y3) edge [-stealth] (+3) 
    (yn) edge [-stealth] (+n);
\draw
    (v) edge [-stealth] (+1)
    (+1) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} node [below] (botl) {\phantom{$E_k$}} (+2)
    (+2) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+3)
    (+3) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+dots) 
    (+dots) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (+n)
    (+n) edge [-stealth] node [rectangle, draw=black, fill=\EkColor] {$E_k$} (z) ;
\fill[black, path fading=west] (current bounding box.south west) 
rectangle (current bounding box.north);
\fill[black] ([xshift=-0.5\pgflinewidth]current bounding box.south) 
rectangle (current bounding box.north east);
\end{tikzpicture}
\end{document}

enter image description here

  • How would you get it to start shading from the first Ek box to the second Ek box, and then being all black to the right of that second box ? – Olivier Bégassat May 17 '18 at 21:09
  • Ok, and how do I find the right coordinates ? I would rather not guess an angle for the bottom left position current bounding box.angle and similarly for the upper right position where shading stops and filling takes over. – Olivier Bégassat May 17 '18 at 21:17
  • Thanks for the updated answer. But what if I want that shading to only cover the portion (+1).x to (+2).x (where I write p.x for the x coordinate of the point p) ? (so the whole y-range of the picture, but the shading takes place between to two extremities defined by their x coordinates). – Olivier Bégassat May 17 '18 at 21:23
  • @OlivierBégassat Which coordinates? Are you looking for \fill[black, path fading=west] (current bounding box.south -| p) rectangle (current bounding box.north); ? This will start the shading at p. – user121799 May 17 '18 at 21:30
  • Thank you ! that is precisely what I wanted :D, that's it from me tonight, you've been of tremendous help to me : ) – Olivier Bégassat May 17 '18 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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