4

I have the following code to add background for the document:

\documentclass{article}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{calc,fadings}
\AddToHook{shipout/background}{
    \begin{tikzpicture}[remember picture,overlay]
    \node[
     % path fading=north,
     inner sep=0pt,outer sep=0pt,
     anchor=south,opacity=.3,
] at (current page.south) {\includegraphics[width=\paperwidth]{bg.png}};
    % \path[path picture={
    %     \node[inner sep=0pt,outer sep=0pt,anchor=south,scope fading=south] at (current page.south) {\includegraphics[width=\paperwidth]{bg.png}};
    % }];
        \coordinate (L) at ($(current page.north west)!.5! (current page text area.north west)$);
        \coordinate (R) at ($(current page.south east)!.5! (current page text area.south east)$);
        \fill[white,opacity=.5] (L) rectangle (R);

    \end{tikzpicture}
}
\begin{document}

\lipsum[1-6]

\end{document}

It produced:

res

However, the intersection border's color transformation is too sharp! I want the image could smoothly fade to white, with multiple opacity, I have consulted this link, but it doesn't work.

The bg.png could be accessed as below(maybe example-image is okay, but its background is pure gray, I would prefer to show that on bg.png):

image

1 Answer 1

4

I used an image distributed in TeX Live as part of the pstricks documentation (doc/latex/tile-graphic/examples/postscript/flowers.eps).

I used the method explained in section 23 of the manual for fading a node. The example there uses text, but it does not matter what the content is.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
  \node {\includegraphics{flowers}};
  \node [anchor=west,scope fading=north] at (current bounding box.east) {\includegraphics{flowers}};
\end{tikzpicture}
\end{document}

flowers and fading flowers

'scope fadings` works in similar ways to regular fadings, but affect everything until the end of the current scope (details on p363).

So something like

\documentclass[landscape]{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\usepackage{kantlipsum}
\begin{document}
\AddToHook{shipout/background}{%
  \put (0pt,-\paperheight) {%
    \begin{tikzpicture}[baseline=(a.south),every node/.style={inner sep=0pt},]
      \node [anchor=south west] (a) {\includegraphics[width=.5\paperwidth]{flowers}};
      \node [anchor=west,scope fading=north] at (a.east) {\includegraphics[width=.5\paperwidth]{flowers}};
    \end{tikzpicture}%
  }%
}
\kant[1-3]
\end{document}

produces applied scope fading to background on right; without on left

Obviously you would not use half without the fading; that is just to show the effect of applying the fading.

4
  • wow! I forgot section23's feature. But on my computer, tex complained that it can't find flowers, could you tell me how to find this example image? Commented 20 hours ago
  • 1
    @Explorer I edited. I was wrong. context has the cows and mill. pstricks has flowers and tigers. Commented 20 hours ago
  • 1
    @Explorer as for flowers you need to add the path (or copy the file alongside your .tex file), you can alternatively replace the two \includegraphics[width=.5\paperwidth]{flowers} by \includegraphics[width=.5\paperwidth,page=5]{example-image-a4-numbered} so the file is directly found by the compiler (it is in the path). Result: i.sstatic.net/tCKCZXly.png Commented 20 hours ago
  • But I found a strange issues with .png but not in .pdf~~>_<~~ See my new post: tex.stackexchange.com/questions/759139/… Commented 19 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.