Is there a way to have tikz
ignore the white space produced by a node
's inner sep
when calculating the picture's bounding box?
Consider the following MWE:
\documentclass{article}
\usepackage[showframe,pass]{geometry}
\usepackage{tikz}
\begin{document}
\noindent \begin{tikzpicture}
\node[inner sep=0pt] (X) {X};
\draw (X) -- ++ (0.5, 0);
\draw[gray] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\noindent X
\noindent \begin{tikzpicture}
\node[inner sep=2pt] (X) {X};
\draw (X) -- ++ (0.5, 0);
\draw[gray] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\end{document}
Here's the output:
In this example, the inner sep
is useful when drawing lines from/to the node (see the horizontal line in the example), but on the other side, it indents the second X
with regard to the normal text. Some way of specifying the bounding box as the smallest rectangle containing all "ink" (and thereby clipping all inner sep
s and possibly other white spaces that needlessly extend the bounding box) would be great here…
Best Answer
This solution does not really ignore
inner sep
for bounding box calculation, but might give the desired result in many cases.It seems that the value of
outer sep
does not influence the bounding box. So usingouter sep
instead and settinginner sep = 0
does the trick.This approach does even work partially for other shapes. In this case a negative
inner sep
(orinner xsep
orinner ysep
) may help with quick and dirty fine tuning.I have printed out the default value for
inner sep
for reference.