# Opacity options not working when exporting tikzfigure to png [closed]

I have been trying to export a tikzfigure to a standalone .png picture. Searching around the internet I found a good answer in the following command, which I am launching from the Windows Command Prompt:

latexmk mytexfile.tex -shell-escape -f

I get a satisfying output with only a few issues:

1. The last blue barplot is only half rendered
2. (most important) the background fill of the "severity" node should have partial opacity (50%?) instead it renders in solid white fill
3. how to make sure that the overall picture background is transparent and not white?

This is the code I am compiling

\documentclass[preview,border=1mm,convert={density=600,outext=.png}]{standalone}

\usepackage{tikz}
\usepackage{color}
\usepackage{graphicx}

\usepackage{pgfplots}    \pgfplotsset{/pgf/number format/.cd, 1000 sep={}}
\pgfplotsset{compat=1.17}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\usepackage{comment}
\usepackage{textcomp}
\usepackage{longtable}
%\usepackage{pgf-pie}
\usepackage[toc,page]{appendix}
\usepackage[bibstyle=numeric,citestyle=numeric,backend=biber]{biblatex}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing,calligraphy,backgrounds}

\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{axis}[area style,width=0.8\textwidth, height=6cm, bar width=10pt,axis x line=bottom,axis y line=left, xlabel={time [months]}, ylabel={SPEI},ymin=-3,ymax=2.5]
\addplot+[ybar, color=blue] coordinates {(1,0.15) (2,0.32) (3,1.2) (4,0.8)  (11,0.8) (12,0.8) (13,1.2) (14,2.3) (15,0.7) (16,0.5) (19,1.5) (20,1.1)};
\addplot+[ybar, color=red, mark=no] coordinates {(5,-1.2) (6,-1.72) (7,-1.6) (8,-1.9) (9,-2.1) (10, -1.2) (17,-1.1) (18,-1.5) };
\end{axis}
%\draw[help lines] (0,0) grid (10,4);
\draw[<->, black, line width=0.8pt] (1.85,0.3) -- (4.25,0.3);
\node [] at (3.05,0.5) {duration};
\draw[<->, black, line width=0.8pt] (1.7,2.4) -- (1.7,1.35);
\draw [decorate, decoration = {calligraphic brace}] (1.85,2.5) --  (4.25,2.5);
%\draw[dashed,help lines] (2.1,1.1) -- (5.3,1.1);
\node [] at (0.9,1.9) {intensity};
\node at (3.0,1.8) [rectangle,fill=white!50, fill opacity=0.5, draw]  {severity};
\node [] at (3.0,2.75) {severity};
\end{tikzpicture}
\label{fig:spi_car}
\end{figure}

\end{document}


And this is the output

EDIT1: solved issue #1, it was sufficient to push the x-axis to a length of 21 instead of just 20, then I had to readjust all coordinates

• I can not reproduce your problem with pdflatex --file-line-error --synctex=1 --shell-escape filename.tex. Aug 2 at 16:07
• Do you want xmax=21 to show the full width of the last bar - a separate issue. Aug 2 at 16:07
• @hpekristiansen Do you get the expected output (i.e. 50% white shading in the severity box) with pdflatex? also, will it export to a png anyway? EDIT: i tried running pdflatex and it gives the correct output in the TexWorks previewer, however no .png file is saved anywhere by doing this. how to do so? Aug 2 at 16:42
• You need convert and --shell-escape AND permissions to run it. I can not help with that - I do not use windows or latexmk. I can not see how your problem can be related to latexmk. You could create a Minimal Working Example. -your problem is not really related to much/anything in your code. Aug 2 at 16:53
• Windows users must have installed ImageMagick and change the options in documentclass as follow: \documentclass[preview,border=1mm,convert={convertexe={magick convert},density=600,outext=.png}]{standalone} Aug 3 at 12:40

Thanks to the commenters and some extra help around the internet i found what did the trick for me:

1. I installed ImageMagick, which in turns requires Ghostscript to be installed, and ran my code with the modification suggested by @vipa

 \documentclass[preview,border=1mm,convert={convertexe={magick convert},density=600,outext=.png}]{standalone}

2. as @hpekristiansen pointed out, I needed -shell-escape to be enabled in my TexWorks IDE. This was easily done by following THIS

3. This was, sadly, not enough as TexWorks would return an error of this sort

gs: Interpreter revision (9561) does not match gs_init.ps revision (9533)

meaning that conflicting versions of Ghostscript are found by TexWorks. Indeed, by looking into the TexLive installation folder i noticed that a pre-installed, simplified version of ghostscript is included in TexLive, in a folder called tlgs, under tlpkgs. Removing the tlgs dependency from TexLive preferences did not fix the issue. What finally fixed the issue was to remove the tlgs folder altogether, leaving my GhostScript installation the only one, thus avoiding conflicts. The code now saves a correctly rendered .png when ran by using PdfLaTex, whereas I discarded the latexmk way i was initially working with.

Again, thanks to everybody here and to the GhostScript discord server, bunch of nice pals over there too

• Welcome to this "show". Aug 4 at 10:39