Figures and Images

Transparent Images and Overlays in LaTeX

Make LaTeX images transparent: use PNG alpha channels for see-through backgrounds, the transparent package for fading, and TikZ opacity for overlays.

On this page
  1. Two meanings of “transparent image”
  2. Transparent backgrounds with PNG
  3. Check whether your image really has transparency
  4. Fade an image with the transparent package
  5. Overlay images with TikZ opacity
  6. Engine and format limits
  7. Troubleshooting
  8. Summary

A “transparent image” in LaTeX can mean one of two things. The image file itself may have see-through pixels, such as a PNG logo with a transparent background. Or you may want an image, or part of a page, to be partly see-through so that content behind it shows. Use an alpha-channel PNG for the first case. Use the transparent package or TikZ opacity for the second.

Two meanings of “transparent image”

  • Transparent background. The transparency is stored in the image file. The image keeps it wherever you place it.
  • Semi-transparent content. The transparency is set in the LaTeX source at compile time. It applies to whatever you wrap in the command.

The first case needs only graphicx. The second needs transparent or tikz, depending on the effect you want.

Transparent backgrounds with PNG

pdfLaTeX includes PNG files with an alpha channel, so the transparent pixels stay see-through. You can check this by placing the image over a coloured background:

\usepackage{tikz}
...
\begin{tikzpicture}
  \fill[blue!20] (0,0) rectangle (6,3);
  \node at (3,1.5) {\includegraphics[width=3cm]{logo}};
\end{tikzpicture}

The blue block shows through the logo’s transparent areas. Without the block, the logo sits on the white page.

JPG files have no alpha channel. If you need a transparent background, save the image as PNG from your image editor and keep the transparency when you export.

Check whether your image really has transparency

Open the file in an image editor or viewer that shows a checkerboard pattern for transparent areas. If the background looks solid or white in the compiled PDF, the file probably has a solid background, not an alpha channel. Export it again with the transparent background option turned on. The option name depends on the program.

Fade an image with the transparent package

The transparent package sets how opaque the content that follows will be:

\usepackage{transparent}
...
{\transparent{0.3}\includegraphics[width=4cm]{photo}}

The value runs from 0 (invisible) to 1 (fully opaque). Wrapping the command in braces usually limits the effect to that image. Without braces, the setting can carry on to later content. Reset it with \transparent{1} if you don’t use braces.

The package needs a PDF output engine such as pdfLaTeX. It doesn’t work with DVI output, which is the classic latex and dvips route. Check the package documentation if you use another engine.

Overlay images with TikZ opacity

To stack one image on top of another with a set opacity, use TikZ. The opacity key applies to a node, and the image goes inside the node. The guide to block diagrams and flowcharts introduces TikZ nodes in more depth:

\usepackage{tikz}
...
\begin{tikzpicture}
  \node at (0,0) {\includegraphics[width=6cm]{base-photo}};
  \node[opacity=0.5] at (2,1) {\includegraphics[width=3cm]{logo}};
\end{tikzpicture}

Coordinates are in centimetres by default. The base photo is centred at the origin, and the logo is placed above and to the right of it at half opacity. Change the values to move or fade either image.

If you need to position images on a page more precisely, the guide to inserting images in LaTeX covers the basic \includegraphics options that go inside these nodes.

Engine and format limits

  • PDF and PNG with alpha work in pdfLaTeX. Test other PDF-producing engines with one image before you rely on them.
  • JPG has no transparency at all.
  • The classic latex and dvips route may not show PNG transparency as you expect. Check the output if you use it.
  • The transparent package needs a PDF output engine, as noted above.

Troubleshooting

  • The background is still white. The file is probably a JPG, or a PNG that was exported with a solid background. Re-export it with transparency.
  • The faded image is not faded. The transparent package may not be loaded, or the engine may not support it. Check the preamble and the engine.
  • Later content is faded too. The \transparent command isn’t wrapped in braces. Put it inside a group so it stops at the closing brace.
  • A faint halo appears around the edges. The PNG was probably exported over a coloured background. Export again over a transparent background, or use a clean cutout.
  • The overlay doesn’t appear. Check that tikz is loaded and that the tikzpicture environment is closed.

Summary

For a see-through logo or photo, save it as a PNG with an alpha channel and include it with \includegraphics. To fade an image, use \transparent inside braces with a PDF engine. To stack images with a set opacity, use TikZ nodes with opacity.

The complete guide to figures and images

Inserting Images in LaTeX: PDF, PNG and More
Read the guide

Keep exploring

Guides from other topics

All topics →