2

When I try to make a PNG image using TikZ by using the convert option for the standalone class, I cannot figure out how to make the background transparent. I seem to recall some years ago that this happened by default; while I could be misremembering, other questions and answers on here seem to back up that memory (e.g. tikzpicture has clear background by default, this recent question stating that the TikZ standalone picture background was clear and asking how to make it white...). In any case, the default behavior on my machine currently seems to be a white background. Using a minimal example,

\documentclass[convert={density=300},tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\draw [ultra thick] (0,0) circle (2.5cm);
\end{tikzpicture}
\end{document}

I get a circle with a white background:

enter image description here

How can I make the background transparent?

It may be that software version details matter; I have the following setup:

  • OS: Ubuntu 21.10
  • LaTeX distribution: TeX Live 2020
  • (can provide other details on request, not sure what else to add)
2
  • 1
    I do not know GraphicsMagick 1.4. On my system I have: convert -version Version: ImageMagick 7.1.0-2 Q16 x86_64 2021-06-25 https://imagemagick.org. First step is to make it work in a terminal - see tex.stackexchange.com/a/618059/8650 Commented Mar 13, 2022 at 21:43
  • Thanks @hpekristiansen . The more I think about it, I suspect this is some kind of difference between GraphicsMagick and ImageMagick. Installing GraphicsMagick was not a deliberate choice but was chosen to satisfy a dependency by some other program I suppose. I will try to investigate this difference, thanks for the tip
    – duckmayr
    Commented Mar 13, 2022 at 21:47

1 Answer 1

2

You could use the command= suboption to convert= to further specify the convert command. Something like this should work:

\documentclass[convert={density=300,command=\unexpanded{{\convertexe\space -density \density\space \infile\space -transparent \space white \outfile}}},tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\draw [ultra thick] (0,0) circle (2.5cm);
\end{tikzpicture}
\end{document}

This is adapted from the example in the standalone documentation you linked to.

Be sure to run with --shell-escape.

1
  • This worked perfectly, thanks! At some point I will try to investigate why GraphicsMagick is different to ImageMagick in this respect, but for now, this gives me the result I need
    – duckmayr
    Commented Mar 13, 2022 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .