# Bounding box is larger than expected when drawing a curved path

I have been working on logo for my department and I have the following code. The problem is that whenever I compile the diagram seems to be larger than the actual logo. I do not know what is the problem. I know the numbers I have selected are not the best but any insights into the matter will be highly appreciated.

 \documentclass[letterpaper]{article}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
%\usepackage{amsmath,amssymb,units}
%\usepackage{enumitem,multicol}
\usepackage{tikz}
%\usetikzlibrary{arrows}
\usepackage{lipsum}

\begin{document}

\lipsum[1-2]
\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1]
\path[draw=black,fill=white]
(258.9527,290.5199) .. controls (173.9885,538.4766) and (568.5860,261.2969) ..
(306.5098,257.1141) .. controls (44.4337,252.9312) and (429.9845,542.5624) ..
(352.9767,292.0206) .. controls (275.9689,41.4788) and (119.6549,497.6604) ..
(334.1376,346.9999) .. controls (548.6203,196.3394) and (66.4622,188.6439) ..
(276.0276,346.0724) .. controls (485.5930,503.5010) and (343.9169,42.5633) ..
(258.9527,290.5199) -- cycle;
\end{tikzpicture}
\lipsum[1-2]
\end{document}


See image below:

-
Do you mean that the bounding box of the diagram is much larger than the diagram itself? –  krlmlr Feb 6 '12 at 20:24
Yes, my word choice was not the most appropriate but yes that is what I am asking –  azetina Feb 6 '12 at 20:29
I took the liberty to edit the title and to add a tag. –  krlmlr Feb 6 '12 at 20:39
@user946850 Thanks for the edit. That seems like a better title for the question. –  azetina Feb 6 '12 at 20:43
@azetina: Cool logo - How did you draw it? –  Hans-Peter E. Kristiansen Feb 6 '12 at 23:06

Update : before to use a grid it's possible to use pdfcrop to get the dimensions of the "real" picture. You need to use \thispagestyle{empty} and you need to compile only the picture. You get a pdf file then with pdfcrop you get a new pdf file. Inside this pdf, you can read /BBox [0 0 146.908 142.991] (be careful with the units). We don't have the origin but we get the dimensions. pdfcrop can also give a pdf file that you can include with a correct bounding box.

Manually : With a grid

\documentclass[letterpaper]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1]
\draw[help lines,step=8pt] (208,208) grid (400, 400);
\clip (208,208) rectangle (400, 400);
\path[draw=black]
(258.9527,290.5199) .. controls (173.9885,538.4766) and (568.5860,261.2969) ..
(306.5098,257.1141) .. controls (44.4337,252.9312) and (429.9845,542.5624) ..
(352.9767,292.0206) .. controls (275.9689,41.4788) and (119.6549,497.6604) ..
(334.1376,346.9999) .. controls (548.6203,196.3394) and (66.4622,188.6439) ..
(276.0276,346.0724) .. controls (485.5930,503.5010) and (343.9169,42.5633) ..
(258.9527,290.5199) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1]
\path[draw=black] (213,215) rectangle (398, 395);
\clip (213,215) rectangle (398, 395);
\path[draw=black]
(258.9527,290.5199) .. controls (173.9885,538.4766) and (568.5860,261.2969) ..
(306.5098,257.1141) .. controls (44.4337,252.9312)  and (429.9845,542.5624) ..
(352.9767,292.0206) .. controls (275.9689,41.4788)  and (119.6549,497.6604) ..
(334.1376,346.9999) .. controls (548.6203,196.3394) and (66.4622,188.6439) ..
(276.0276,346.0724) .. controls (485.5930,503.5010) and (343.9169,42.5633) ..
(258.9527,290.5199) -- cycle;
\end{tikzpicture}
\end{document}


-
Nice use of a grid to work out what the size should be. Definitely the most practical solution. –  Loop Space Feb 7 '12 at 9:46
I like the pdfcrop idea, I actually do that quite a lot. And +1 for the grid supports as well! –  yo' Feb 7 '12 at 10:31
@altermundus Thanks for providing a substantial solution. –  azetina Feb 7 '12 at 15:30

clip the figure before drawing

\documentclass[letterpaper]{article}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
%\usepackage{amsmath,amssymb,units}
%\usepackage{enumitem,multicol}
\usepackage{tikz}
%\usetikzlibrary{arrows}
\usepackage{lipsum}

\begin{document}

\lipsum[1-2]
\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1]
\clip[draw](305,305) circle (100);
\path[draw=red,fill=white]
(258.9527,290.5199) .. controls (173.9885,538.4766) and (568.5860,261.2969) ..
(306.5098,257.1141) .. controls (44.4337,252.9312) and (429.9845,542.5624) ..
(352.9767,292.0206) .. controls (275.9689,41.4788) and (119.6549,497.6604) ..
(334.1376,346.9999) .. controls (548.6203,196.3394) and (66.4622,188.6439) ..
(276.0276,346.0724) .. controls (485.5930,503.5010) and (343.9169,42.5633) ..
(258.9527,290.5199) -- cycle;
\end{tikzpicture}
\lipsum[1-2]
\end{document}

-

This is not an answer, but thought it might be useful to see why this is happening as @user946850 points out. I added the following to the code to see where the control points are:

\foreach \x in {{(173.9885,538.4766)}, {(568.5860,261.2969)}, {(44.4337,252.9312)},
{(429.9845,542.5624)}, {(275.9689,41.4788)}, {(119.6549,497.6604)}, {(548.6203,196.3394)}, {(66.4622,188.6439)}, {(485.5930,503.5010)}, {(343.9169,42.5633)}} {
\node [fill=red,shape=circle] at \x {};
};


Another way to see the bounding box is to apply the following at the end of the picture:

\draw [blue] (current bounding box.south west) rectangle (current bounding box.north east);


-
I suppose that is what is causing the bounding box to be so large. Is this customizable other than adding the bounding box as user946850 suggests. –  azetina Feb 6 '12 at 20:44
Thanks for the effort. I was just too lazy to figure out how to iterate over coordinates :-) –  krlmlr Feb 6 '12 at 20:47
Is there a simple general way to exclude control points from a bounding box before a picture is drawn? –  raxacoricofallapatorius May 27 '12 at 12:57

As seen in the answer by Peter Grill, the size of the bounding box is determined not only by the path points, but also by the control points. In order to reduce the size of the bounding box, we have to specify it explicitly.

The manual states:

PGF is reasonably good at keeping track of the size of your picture and reserving just the right amount of space for it in the main document. However, in some cases you may want to say things like “do not count this for the picture size” or “the picture is actually a little large.” For this you can use the option use as bounding box or the command \useasboundingbox, which is just a shorthand for \path[use as bounding box].

And especially with respect to curved lines:

... Controls points of a curve often lie far “outside” the curve and make the bounding box too large. In this case, you should use the [use as bounding box] option.

As a quick fix, you could add something like the following into your tikzpicture environment before drawing:

 \path[use as bounding box] (220, 200) rectangle (400, 400);


For more precise calculation, find points that will define the convex hull of your logo with sufficient precision and use a polygon as bounding box -- this works equally well.

Here is the result of the quick fix:

-
The bounding box is good but is it possible to edit the logo to get the same effect? Just wondering. –  azetina Feb 6 '12 at 20:50
If you used only the path points for computing the bounding box, the result would be equally wrong. (This is what I tried first.) TikZ would have to do rather difficult computations in order to get it right. –  krlmlr Feb 6 '12 at 21:01