TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I change article to standalone the result shows no difference except that the edge around the picture turning gray. Then what's the benefit of using {standalone} compared to {article}?

standalone

  \documentclass[margin=10pt]{standalone}    
  \usepackage{tikz}  
  \begin{document}  
  \begin{tikzpicture}  
  \draw[step=1cm, color=gray] (0, 0) grid (3, 2);       
  \end{tikzpicture}  
  \end{document}

article

  \documentclass[margin=10pt]{article}    
  \usepackage{tikz}  
  \begin{document}  
  \begin{tikzpicture}  
  \draw[step=1cm, color=gray] (0, 0) grid (3, 2);       
  \end{tikzpicture}  
  \end{document}
share|improve this question
2  
I mostly use standalone so that I don't have to crop images before copying them here. BTW, the gray area is from [margin=10pt]. – John Kormylo Mar 22 at 4:11
2  
@JohnKormylo The white area around grid is from [margin=10pt]. They gray area is part of the display background which OP included when cropped the results. – Ignasi Mar 22 at 7:46
up vote 33 down vote accepted

The main advantages, in my opinion, are:

  1. You can readily compile your figure and make modifications without compiling the whole document.
  2. You can include the standalone .tex file using the \includestandalone{filename} command (from the standalone package) . This command discards the preamble automatically so you don't need to cancel out the lines containing \documentclass[]{}, \usepackage{} etc. as you would do when using \input{} without the standalone package. Indeed, loading the standalone package will redefine the \documentclass macro so that also \input will ignore the preamble making the behavior of \input the same as \includestandalone command (without any option, see point 3 below).
  3. The \includestandalone[mode=image]{filename} command is able to include the content of filename.tex as a pdf (it requires the option -shell-escape when you run pdflatex). This is particularly useful when the TikZ/pgfplots figure is complicated and expensive to create. It works like the externalize library while the option mode=tex is equivalent to include the code between begin{tikzpicture} and \end{tikzpicture} in your article (or whatever) document class. Furthermore, the option mode=buildnew let standalone to recognize whether the tex file is newer than its image and, in this case, the newer image is built and included as pdf for future compilations. This is (in my opinion) fantastic. To do that globally (for all of your standalone files) you can add the option mode=buildnew as a package option to standalone.

  4. If you install ImageMagick, you can easily convert the tikzpicture to png/jpg and many other formats by simply running pdflatex (with the option -shell-escape activated) by simply adding \documentclass[convert]{standalone}.

  5. The documentation of both the documentclass and package is well written and easy to understand. More advantages in using standalone over article are available there.

Disadvantages: if the images to be included in your document are few and computationally easy to create as well as the document itself can be quickly produced it may not be beneficial to create and include a standalone file.

share|improve this answer
1  
You can use \input and the preamble will still be discarded - you don't need \includestandalone for this. (You need standalone to be loaded, of course.) – cfr Mar 27 at 4:17
    
(1) and modified (2) are the real advantages, I think. The rest you can get easily anyway (e.g. with externalisation). I tend to combine externalisation with standalone, actually. And I always use \input rather than \includestandalone ;). – cfr Mar 27 at 4:20
    
@cfr Thanks for your comments. In this answer I took the opportunity to show the potential of the command \includestandalone, not as a substitute to \input (i.e. mode=tex) but rather combined with the options mode=image and, most of all, mode=buildnew which I've found quite useful. I believe it may be tedious to find and delete (in order to update) an externalized pdf picture if there are hundreds of them, with standalone mode=buildnew I go faster... That being said, I will definitely include the behavior of \input for the sake of completeness. Thanks for pointing that out! :) – mirkom Mar 31 at 14:38
    
Yes, externalisation does that automatically i.e. it's the default, which is convenient. – cfr Mar 31 at 19:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.