2

I plot graph in my article with the command '\begin{tikzpicture} ..\end{tikzpicture}'. First, I extract datas from matlab in a text file and I use \addplot with all the options. It is great, but my compilation is very very long ( I have a lot of figures ). Is it possible to have all the figures in tikz external files ( which I can modify sometimes ) and convert into a pdf file (because using \includegraphics with a pdf file is very fast) ?

3 Answers 3

6

You can process your tikzpictures as standalone documents and then include them as pictures. E.g., the file myplot.tex might contain

\documentclass[border=0.1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[...]
  ...
  \end{axis}
\end{tikzpicture}
\end{document}

Your main document then includes the generated pdfs:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{myplot.pdf}
\end{document}
1

My advise is to put the tikz-code of your plots in separate files as it is easier to manage. I use an alias for \input to include these files just in case it requires special treatment later on.

\documentclass{article}
\newcommand{\tikzinput}[1]{%
    \input{#1}%
}

\begin{document}
\tikzinput{myplot.tikz}
\end{document}

Second, you should use \tikzexternalize to speed up compilation. See the pgfplots manual: 7.1.1 Using the Automatic Externalization Framework of TikZ

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize% activate externalization!

\begin{document}
  \begin{tikzpicture}
  \begin{axis}
  \addplot {x^2};
  \end{axis}
  \end{tikzpicture}
\end{figure}
\end{document}
2
  • Thanks for your answer, both of you! I don't why, but it does not for one for my figure. I have a double figure which is 4 tikz pictures. ( \begin{figure} \begin{minipage} 2 tikz picture \end{minipage} \end {figure} + the same for the 2 others ). How can i do that?
    – J.Darmody
    Sep 15, 2016 at 19:06
  • You should create a new question with a minimal example and don't forget to specify your environment (pdflatex, windows, ...). Sep 16, 2016 at 5:43
0

As an alternative to using tikzexternalize if the document is stable and you will make few modifications to tikzpicture, it is better to handle it in separate files and include them as an image (or with \input{file-tkz-1.tex}). The ltximg script you can do the following:

$ ltximg --subenv --imgdir=mypics --prefix=tkz -o test-out test-in.tex

Now you will have a document with the tikzpicture environments converted into images (preserving the consistency of the fonts) and you will also have each tikzpicture environment in separate files (in case you need some extra modification). First check the documentation to see the options and conditions that the input file must meet.

You must log in to answer this question.

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