1

I have made quite a few figures for my thesis in LaTeX. I now want to export about five of those figures as .png with a clear background, so I can use them in my PowerPoint presentation. I'm using TexStudio with MikTex. I've found some old posts about this (TeX to image over command line, How can I create a transparent background in a logo?, how to remove the background for png picture, Making an image with a transparent background), but none seem to answer my question.

Example figure:

\PassOptionsToPackage{table,dvipsnames,svgnames}{xcolor}
\documentclass[11pt, twoside, a4paper]{report}
\usepackage[inner = 30mm, outer = 20mm,  top = 30mm, bottom = 20mm, headheight = 13.6pt]{geometry}
\usepackage{tikz}
\usepackage[pdfpagelayout=TwoPageRight]{hyperref}
\usepackage[export]{adjustbox}
%\usepackage{showframe}
\hypersetup{colorlinks=true, linktoc=all, allcolors=green!30!black,}

\usepackage{pgfplots}
\pgfplotsset{
    compat=1.16,
    %made the beginnings of a second axis style, because I figured it needs to be different for grouped
    my second axis style/.style={
    width=\linewidth,
    height=0.35\linewidth,
    bar width=0.2, %<- changed
    enlarge x limits={abs=0.45},    % <-- changed to absolute coordinates
    ymin=0,
    legend style={
        at={(0.5,1.15)},    % <-- adapted
        anchor=north,       % <-- changed from `north'
        legend columns=3,
    },
    ylabel={PR\textsubscript{A}},
    xtick=data,
    axis lines*=left,
    ymajorgrids,
    %
    table/x=x,
    },
    % created a style for the common `ybar' options
    my second ybar style/.style={
        ybar,
        my ybar legend,            % <-- change legend image accordingly
        #1!50!black,
        fill=white!70!black,, %<- changed back
        nodes near coords,      % <-- moved from `axis' options here
        % state absolute positions for the `nodes near coords'
        scatter/position=absolute,
        node near coords style={
            % state where the nodes should appear
            at={(\pgfkeysvalueof{/data point/x},0.5*\pgfkeysvalueof{/data point/y})},
            anchor=center,rotate=90, %<-added
            % make the font a bit smaller
            font=\footnotesize,
            /pgf/number format/.cd,
            fixed,
            precision=2,
            zerofill,
        },
    },
    my ybar legend/.style={
        /pgfplots/legend image code/.code={
            \draw [
            ##1,
            /tikz/.cd,
            yshift=-0.25em,
            ] (0cm,0cm) rectangle (3pt,0.8em);
        },
    },
}



%data for the grouped bar chart
\pgfplotstableread{
    x          SP_cSi_2_3   SP_cSi_2_4  Reference
    1   0.500   0.627   0.868
    2   0.781   0.778   0.859
    3   0.819   0.868   0.871
    4   0.732   0.824   0.876
    5   0.853   0.873   0.954
    6    0.813   0.838   0.940
    7    0.712   0.759   0.876
    8    0.864   0.894   0.887
    9    0.465   0.614   0.891
}{\loadedtablesppr}


\begin{document}

    \begin{figure}
        \begin{tikzpicture}
        \begin{axis}[my second axis style,
        ybar,
        ylabel={PR\textsubscript{A}},
        xtick= data,
        ]
        \addplot [my second ybar style=blue!50!black,] table [y=SP_cSi_2_3] {\loadedtablesppr};
        \addplot [my second ybar style=orange!50!black,] table [y=SP_cSi_2_4] {\loadedtablesppr};
        \addplot [my second ybar style=red!50!black,] table [y=Reference] {\loadedtablesppr};
        \legend{Floating 2.3~~ , Floating 2.4~~ , Reference}
        \end{axis}
        \end{tikzpicture}
    \end{figure}

\end{document}

Is there a command like \savefig{'my_export_image.png', clear = True}?

Hans
  • 491
  • 2
    You could simply compile the pictures in a standalone document. –  Aug 01 '18 at 14:52
  • 3
    why don't you create your presentation with beamer? that way, you don't need to convert your tikzcodes. – naphaneal Aug 01 '18 at 14:52
  • I've never heard of beamer and my time is pretty limited. Also, uni won't allow anything other than .ppt – Hans Aug 01 '18 at 14:53
  • 6
    Switch the Uni ;-) –  Aug 01 '18 at 14:59
  • @marmot, If I compile the pictures in a standalone document, I get PDF files (without clear background I think). I don't know how I would import them to PowerPoint with clear background – Hans Aug 01 '18 at 15:07
  • 1
    have you checked this question? https://tex.stackexchange.com/questions/13349/tikz-to-non-pdf – naphaneal Aug 01 '18 at 15:09
  • @naphaneal I did, but I can't figure it out. My legend gets all weird in the previewer, and I can't find the .png file that's supposed to appear (it's not in the folder where the LaTeX and .pdf files are). – Hans Aug 01 '18 at 15:36
  • @Hans If you already have the standalone pdf files you could convert them via sips -s format png test.pdf --out test.png which will give transparent background. – samcarter_is_at_topanswers.xyz Aug 01 '18 at 15:43
  • @samcarter I'm a big LaTeX noob. Where do I typ in that code? – Hans Aug 01 '18 at 15:56
  • @Hans Oh, that is no latex code, you will have to execute it from a command line (and check if you have sips installed). There are also similar tools like convert from the ImageMagick suite, but I don't know from the top of my head what command is necessary to produce transparent background. – samcarter_is_at_topanswers.xyz Aug 01 '18 at 16:00
  • 1
    @samcarter Since mixtex was mentioned, I assume the OP uses windows. I doubt that sips is available there (but I could be wrong). But GraphicsMagick exist as a precompiled package for Windows. A good starting point looks like gm convert -transparent white file.pdf file.png. Then you'd probably need to add -density somenumber to get the right resolution. gm help convert gets the options. – Harald Hanche-Olsen Aug 01 '18 at 16:16
  • @HaraldHanche-Olsen Probably right. Though we already had questions about miktex used on mac.... – samcarter_is_at_topanswers.xyz Aug 01 '18 at 16:21
  • @samcarter I've downloaded GraphicsMagick but have no idea how to operate it. Could you make an example using my_export_image.pdf and my_export_image.png? – Hans Aug 01 '18 at 19:23
  • @Hans You'll find an example in the comment from @HaraldHanche-Olsen gm convert -transparent white file.pdf file.png. You'll need to paste this in some command line, not sure what it is called in windows. – samcarter_is_at_topanswers.xyz Aug 01 '18 at 19:32
  • @HaraldHanche-Olsen Do you happen to have any tips how to use GraphicsMagick on windows? – samcarter_is_at_topanswers.xyz Aug 01 '18 at 19:35
  • @samcarter No, sorry. I am a total idiot when it comes to windows. (Unix user for an eternity, now that extends to mac.) I know that windows used to have a terminal interface, used to be called a command window or something like that, but I don't even know if that's still the case. – Harald Hanche-Olsen Aug 01 '18 at 20:00
  • @HaraldHanche-Olsen cmd is still integrated in Win. it can be found by Windows Start button -> and then type cmd in the search field. (or Cortana search) – naphaneal Aug 02 '18 at 15:41
  • @Hans what are your system specifications? – naphaneal Aug 02 '18 at 15:42

1 Answers1

-1

If it's just tikz pictures, you could try using the Latex Previewer by Troy Henderson http://www.tlhiv.org/ltxpreview/ . Just add the tikz package under "Packages" and then you can choose what type of ouput you want - for instance png.

Discovered that recently and it works perfectly fine!