Take the 2-minute tour ×
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.

Arrow heads from the following MWE are cropped when externalized. What am I doing wrong?

MWE:

\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize

\begin{document}
  \begin{tikzpicture}
     \draw[->,ultra thick] (0,0) -- (0,5);
     \draw[->,ultra thick] (0,0) -- (5,0);
  \end{tikzpicture}
\end{document}

enter image description here

share|improve this question
3  
You're not doing anything wrong. Arrowheads aren't taken into account when computing the bounding box of a tikzpicture. You can explicitly enlargen the bounding box if this cropping occurs, or there may be a sneakier way to do it automatically which I'm unaware of (but would love to know about). –  Loop Space Dec 11 '12 at 13:18
    
Is it a duplicate of tex.stackexchange.com/q/71299/19356? –  Please don't touch Dec 12 '12 at 0:58
    
The newest update for TikZ CVS does now support the inclusion of arrowheads into the bounding box. See tex.stackexchange.com/a/134047! –  LaRiFaRi Sep 19 '13 at 14:13

2 Answers 2

up vote 13 down vote accepted

That is nasty, indeed. At least with pdf output (the resulting bounding box of the image is also used to clip the image). It might work better with ps output (I do not know).

I guess the only solution is to increase the size of the bounding box manually. In your example, you could use

\useasboundingbox (-0.2,-0.2);

as last statement (otherwise it would overwrite the entire bounding box). In our case, we simply "append" the (-0.2,-0.2) coordinate to the picture's bounding box.


This alters your image's bounding box, of course. That is probably what you want. If not, you might be interested in the following part of the answer.

A solution which keeps the current bounding box would be to rely on trim left, trim right, and baseline to undo the effects of \useasboundingbox.

Here is a possible approach:

\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize

\begin{document}
\thispagestyle{empty}

\fboxsep=0pt
\dotfill
\fbox{%
  \begin{tikzpicture}[trim left=0pt,trim right=5cm,baseline]
     \draw[->,ultra thick] (0,0) -- (0,5);
     \draw[->,ultra thick] (0,0) -- (5,0);

    \useasboundingbox (-0.2,-0.2);
  \end{tikzpicture}%
}
\dotfill
\end{document}

enter image description here

as you guessed correctly, the \fboxsep, \dotfill, and \fbox stuff is just syntactical sugar to verify that it works. The key idea is trim left,trim right,baseline combined with \useasboundingbox.

The first two keys allow to modify the bounding box of a picture and the third key controls vertical displacement. However, unlike the "tight" bounding box produced by the external lib, the resulting image has a larger bounding box than the trim values. The trim values are implemented by means of negative \hspaces and are also applied by the external lib. The baseline thing simply moves the complete image vertically; that appears to be enough.

share|improve this answer
    
Perhaps it's more "tikzien" to use ` \draw (current bounding box.south west) rectangle (current bounding box.north east);` instead of \fbox. –  Alain Matthes Apr 16 '13 at 19:33

Here is a simple method to add some margin (2mm in this example) to your tikzpicture:

\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{external,fit}
\tikzexternalize

\begin{document}
  \begin{tikzpicture}
     \draw[->,ultra thick] (0,0) -- (0,5);
     \draw[->,ultra thick] (0,0) -- (5,0);

     \node[fit=(current bounding box),inner sep=2mm]{};
  \end{tikzpicture}
\end{document}
share|improve this answer

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.