The package standalone
does just that. It is a new package (released this year, I think) which will produce a document exactly as big as your figure (and you can use this for text or other things as well). Here is how you would set up your document
\documentclass{standalone}
\usepackage{tikz}
%include other needed packages here
\begin{document}
\begin{tikzpicture}
% include your tikz code here
\end{tikzpicture}
\end{document}
If you do that, then you will be able to compile this directly to get a .pdf document exactly as big as the figure, which can then be included in emails, word documents, or even as a picture in another .tex document using the \includegraphics{}
command.
The best thing about this is that it can also be included in a .tex document (e.g. article
, beamer
, etc.) as a .tex file using the \input{}
command without having to change anything in the .tex document above. The main thing is to include the package standalone in your preamble (i.e. before \begin{document}
) together with any packages you used in the above code, which in my example would be:
\usepackage{standalone}
\usepackage{tikz}
and then where you want the picture to go put, for example:
\begin{figure}[!h]
\input{mytikzfig.tex}
\caption{ }
\end{figure}
where mytikzfig.tex is the .tex document with your tikz picture using the standalone package.
You can see this solution given in an answer to an StackOverflow question.