5

I would like to show a picture (in the example replaced by a red rectangle), but only parts of this picture should be visible, defined by a text. So, in this example only the part of the picture behind the 'TEST' will appear in the final result. The text probably has to have opacity=0, but how to cover the rest of picture?

\documentclass{scrartcl}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
 \fill[red] (0,0) rectangle (10,5);
 \node[font=\Huge] at (5,2.5) {TEST};
\end{tikzpicture}
\end{document}
Jürgen
  • 2,160

2 Answers2

4

Here is a suggestion using the fadings library. Note that I use a lightgray background to show the size of the picture.

enter image description here

Code:

\documentclass[margin=5mm]{standalone}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{fadings}
\newsavebox\picturebox

\begin{document}
\savebox\picturebox{\includegraphics[width=10cm]{picture}}
\begin{tikzfadingfrompicture}[name=fading text]
  \node[
      text=transparent!100,
      minimum width=\wd\picturebox+2\pgflinewidth,
      minimum height=\ht\picturebox+\dp\picturebox+2\pgflinewidth,
      font=\bfseries\fontsize{95}{95}\selectfont,
      fill=white
    ] {TEST};
\end{tikzfadingfrompicture}
\begin{tikzpicture}
  %\clip(-5cm,-50pt)rectangle(5cm,50pt);
  \node(p){\usebox\picturebox};
  \fill[path fading=fading text,fit fading=false,
      lightgray!10% <- maybe you want to change the color to white
    ](p.south west) rectangle (p.north east);
\end{tikzpicture}
\end{document}

If I uncomment \clip(-5cm,-50pt)rectangle(5cm,50pt); I get

enter image description here

esdd
  • 85,675
2

You mean something like this?

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}

 \node[font=\Huge] (A) at (5,2.5) {TEST};

 \begin{scope}[on background layer]
 \clip(A.south west) rectangle (A.north east);
 \fill[red] (0,0) rectangle (10,5);
 \end{scope}


\end{tikzpicture}
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Sorry, but no. You can get the idea by looking at this link: [link] (https://sylviamoessinger.files.wordpress.com/2012/05/bergfest.jpg) – Jürgen Jun 02 '16 at 07:46