4

I am trying to extract/convert a tikzpicture to a format that is suitable for powerpoint without losing quality. The code that I have found and adjusted is the following:

\documentclass[a4paper]{scrartcl}
\usepackage{pgfplots, tikz}

\pgfrealjobname{mytikzpicture}

\begin{document}
\beginpgfgraphicnamed{outputpicture}%

\begin{tikzpicture}
\begin{axis} [height=7cm, width=10cm, title=\textbf{Title}, xlabel= XYZ, ylabel = ABC]
\addplot coordinates {(0,-30) (30,-30) (60, 0) (90, 30) (120, 60) (150, 90) (200, 140)} node[pos=0.115,pin=-360:{A}] {};
\addplot coordinates {(0, -40) (30, -40) (30, 60) (60, 60) (90, 60)(120, 60) (150, 60) (200, 60)} node[pos=0.734,pin=-90:{B}] {};
\legend {{XYZ}, {ABC}}
\end{axis}
\end{tikzpicture}
\endpgfgraphicnamed
\end{document}

mytikzpicutre is the name of the file with the initial graph. I named the output as outputpicture; the entire code is saved under the name output. However I get an error:

pgf: Sorry, image externalization failed: the resulting image wdpgfgraphicnamed'. 

Could anybody help me with this problem?

ajafarov
  • 757
  • 4
    Have you considered making a separate .tex file using the standalone class, with the content just being the picture? That's my approach: LaTeX -> PDF -> IrfanView -> Paste into PowerPoint. – Joseph Wright Jan 21 '14 at 19:48
  • @JosephWright I tried it your way but I dont really know how IrfanView works, hope to receive alternative solutions, thanks in anyway! – ajafarov Jan 21 '14 at 20:02
  • IrfanView is just a front end here, but one I find convenient. What you need to have is a copy of GhostScript installed: IrfanView uses it to do the PDF conversion. I usually set the resolution for conversion to 600 x 600 dpi: there is a setting in IrfanView for that. There are other approaches, but the basic idea is that PowerPoint can't properly work with vector images, which includes PDFs, so you need a raster (bitmap). We've got other general questions on this sort of conversion. – Joseph Wright Jan 21 '14 at 20:08
  • Alternatively, you can export the TikZ picture to .eps format, as described in http://tex.stackexchange.com/a/8646/18228, and insert the .eps image in powerpoint. – Herr K. Jan 21 '14 at 20:17
  • @KevinC I have tried it out but still without success – ajafarov Jan 21 '14 at 21:20
  • You can try the Python script tikz2pdf to create a single pdf picture with your drawing: http://kogs-www.informatik.uni-hamburg.de/~meine/tikz/process/ – Robert Jan 21 '14 at 21:32
  • @Robert Is there any possibility to post the correct code including my tikzpicture data, so that I can use it? I am not that strong with Latex and I dont really know what to do. Thanks! – ajafarov Jan 21 '14 at 21:42
  • @KevinC Could you please show me the right code including my tikzpicture data? I receive an error. Thanks in advance! – ajafarov Jan 21 '14 at 21:45

1 Answers1

2

You can use the Python script "tikz2pdf" (http://kogs-www.informatik.uni-hamburg.de/~meine/software/scripts/tikz2pdf): Save the tikz image in a separate file (e.g. foo.tex):

\begin{tikzpicture}
\begin{axis} [height=7cm, width=10cm, title=\textbf{Title}, xlabel= XYZ, ylabel = ABC]
\addplot coordinates {(0,-30) (30,-30) (60, 0) (90, 30) (120, 60) (150, 90) (200, 140)} node[pos=0.115,pin=-360:{A}] {};
\addplot coordinates {(0, -40) (30, -40) (30, 60) (60, 60) (90, 60)(120, 60) (150, 60) (200, 60)} node[pos=0.734,pin=-90:{B}] {};
\legend {{XYZ}, {ABC}}
\end{axis}
\end{tikzpicture}

Run "tikz2pdf foo.tex".

Note that if you haven't run the script before it will generate a template file called .tikz2pdf.tex and this does not include the "pgfplots" package default.

If you don't want to use the tikz2pdf script you can copy the template file it provides:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\newlength{\imagewidth}
\newlength{\imagescale}

\begin{document}

\begin{tikzpicture}
\begin{axis} [height=7cm, width=10cm, title=\textbf{Title}, xlabel= XYZ, ylabel = ABC]
\addplot coordinates {(0,-30) (30,-30) (60, 0) (90, 30) (120, 60) (150, 90) (200, 140)} node[pos=0.115,pin=-360:{A}] {};
\addplot coordinates {(0, -40) (30, -40) (30, 60) (60, 60) (90, 60)(120, 60) (150, 60) (200, 60)} node[pos=0.734,pin=-90:{B}] {};
\legend {{XYZ}, {ABC}}
\end{axis}
\end{tikzpicture}

\end{document}

Compile this using pdflatex and you get a pdf file that is tightly cropped around your image.

I hope this helps!

Robert
  • 451
  • thank you very much for your help! I have tried it out and it basically generates the standalone class file. I do lose the quality since I then use the snapshot tool to integrate the graph into the powerpoint file. I guess an eps file would really solve my problem, at least I hope so! nevertheless, thank you for your effort! I appreciate your help! – ajafarov Jan 21 '14 at 22:09
  • You can also compile with the classical latex and dvips (e.g. using "dvips -q foo.dvi -E -o foo.eps"). I'm on a Mac that won't open eps files, so I'm sure if this works. – Robert Jan 22 '14 at 07:37
  • I am getting following error message: ! LaTeX Error: Environment axis undefined. – alper Jan 08 '23 at 13:53