The code adds some completely useless invisible (or rather white) stuff. The lines
\clip(0pt,403pt) -- (389.957pt,403pt) -- (389.957pt,99.6166pt) -- (0pt,99.6166pt) -- (0pt,403pt);
\color[rgb]{1,1,1}
\fill(3.76406pt,399.236pt) -- (380.923pt,399.236pt) -- (380.923pt,253.19pt) -- (3.76406pt,253.19pt) -- (3.76406pt,399.236pt);
\fill(53.4497pt,394.719pt) -- (374.901pt,394.719pt) -- (374.901pt,289.325pt) -- (53.4497pt,289.325pt) -- (53.4497pt,394.719pt);
draw a white background that is larger than the actual picture. TikZ sees that and thinks it is part of the picture. Simply removing/uncommenting these lines removes most of the whitespace.
Near the end of the first scope,
\color[rgb]{1,1,1}
\fill(3.76406pt,249.426pt) -- (386.193pt,249.426pt) -- (386.193pt,103.381pt) -- (3.76406pt,103.381pt) -- (3.76406pt,249.426pt);
does the same.
Additionally (near the end of the second scope
),
\pgftext[center, base, at={\pgfpoint{220.95pt}{106.392pt}}]{\sffamily\fontsize{9}{0}\selectfont{\textbf{ }}}
adds a blank node below the picture, again enlarging the bounding box.
Removing all those lines gives a tight bounding box.
As far as I know, TikZ cannot do the cropping for you, as it can't know whether the white stuff is intentional or not (there might for example be a dark background behind the image so that white is visible).
Knuth in the TeXBook gave an example of "poor
man's bold," (The TeXbook, p. 386) which can be typeset obtained by overprinting the normal weight symbol with slight offsets.
As he says:
The results are somewhat fuzzy, and
they certainly are no match for the
real thing if it's available; but poor
man's bold is better than nothing, and
once in a while you can get away with
it.
Here, one can use a similar technique and the code is shown below:
\documentclass{article}
\usepackage{graphicx,xcolor}
\usepackage{amsmath}
\def\PoorManContour#1#2#3{\leavevmode
\setbox0=\hbox{{#1}}%
\color{#3}\kern-.002em\copy0\kern-\wd0
\color{#3}\raise-.04em\copy0\kern-\wd0
\color{#3}\lower.04em\copy0\kern-\wd0
\color{#3}\raise0.04em\copy0\kern-\wd0
\color{#2}\raise-.012em\copy0\kern-\wd0
\color{#2}\kern.06em\copy0\kern-\wd0
\color{blue}\kern-.020em\lower.003em\box0
}
\begin{document}
\colorbox{gray!5}{\scalebox{5}{\PoorManContour{$\sqrt{\dfrac{A^3_i}{B^2}}$}{gray!60}{gray!60}}}
\end{document}
To achieve the best results possible one has to kern in small steps for possibly twenty steps or so. For simplicity, I have not done that. In the final version, you need to adjust the colors to suit, possibly changing the shading to white.
Edit
After reading Jan's comment below I read the manual and true, as the commenter said the easiest way to achieve what the OP wanted is to include the package without an option i.e., \usepackage{contour}
. Helps to RFM!
Best Answer
The following is PSTricks' solution. Just for fun!
Features
The feature I propose here is that you can determine the dimension of diagram in advance. For example, the total width must be
10 cm
and its height must be4 cm
. You can also specify offsets to make the border, labels, and arrows have enough spaces and balanced.Output
User Interface
User Interface Explanation
Note that the following diagram uses different values to provide spaces for annotations. If you are trying to map the values described above to the corresponding annotations below, then you are comparing orange with banana!
Complete Code
Notes
Compile the code with
latex->dvips->ps2pdf
.