# setting a tight bounding box when amsmath symbols touch it

I would like the straight lines to end exactly ON the line of the various \circ. Red boxes show why this doesn't happen: \circ has more space below it then above (Please, note that still a white space is present between lower circles and the lines ending on them. Simply remove the red box to check this). I tried with inner sep=-.75 for upper cicles and inner sep=-.3 for lower cicles, but this makes the bounding box cut out a part of the upper ones and still leaves a white space under the lower ones.

If you are wandering why I use \circ and not draw a circle, the answer is that \circ is text and doesn't scale with the image (indeed I don't want it to!). Moreover I can refer to this symbols in-line simply writing $\circ$ with no new tikzpicture every few lines..

The MWE is the following

\documentclass{standalone}

\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{bm}
\usepackage{calc}
\usepackage{tikz}
%\usepackage{pbox}
\usetikzlibrary{decorations}
\usetikzlibrary{calc}
\usetikzlibrary{patterns}
\usetikzlibrary{shapes.arrows}
\usepackage{tikzscale}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\newcommand{\mat}{\mathbf}
\renewcommand{\vec}{\bm}

\begin{document}

\begin{tikzpicture}

%\useasboundingbox ($(1,-.5)-(.1,.2)$) rectangle ($(4,.5)+(.1,.2)$);

\draw (1,0) -- (4,0); % linea centrale

\foreach \x in {1,...,4} % ciclo sui cerchi
{
\draw (\x,0) -- +(0,.5);
\node[black,draw=red,very thin,fill=white,inner sep=0] at (\x,.5) {$\circ$};
}
\foreach \x in {1.5,2.5,...,3.5} % ciclo sulle barrette
{
\draw (\x,0) -- +(0,-.5);
\node[black,draw=red,very thin,fill=white,inner sep=0] at (\x,-.5) {$\circ$};
}
%\node[left] at (2.5,-.5) {1};

%\draw[dashed,red] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}

\end{document}

• This is because \circ glyph has white space around. Check with another character in place and you will see (for example a dot). One workaround is, if you really need a node, is to put \tikz\draw circle(2pt); in place of $\circ$. By the way your code is not MWE : a lot of libraries are not necessary here. And one more suggestion, the package calc is not the same thing as the tikz library calc. – Kpym Oct 10 '15 at 6:28
• You can try this command \draw(0.5,0)--+(3,0)foreach[evaluate={\i=2*mod(\x,2)-1}]\x in{1,...,7}{(\x/2,0)--+(0,.5*\i)node[draw=red,very thin,fill=white,inner sep=0] {\tikz\draw circle(2pt);}}; – Kpym Oct 10 '15 at 7:08

The problem is that the bottom of \circ is above the baseline. You can either raise the baseline using \raisebox, or use \Circle from the wasysym package.

\documentclass{standalone}

\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{bm}
\usepackage{wasysym}
\usepackage{calc}
\usepackage{tikz}
%\usepackage{pbox}
\usetikzlibrary{decorations}
\usetikzlibrary{calc}
\usetikzlibrary{patterns}
\usetikzlibrary{shapes.arrows}
\usepackage{tikzscale}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\newcommand{\mat}{\mathbf}
\renewcommand{\vec}{\bm}
\newcommand{\mycirc}{\raisebox{-.11ex}[\dimexpr\height-.11ex][0pt]{$\circ$}}

\begin{document}

\begin{tikzpicture}

%\useasboundingbox ($(1,-.5)-(.1,.2)$) rectangle ($(4,.5)+(.1,.2)$);

\draw (1,0) -- (4,0); % linea centrale

\foreach \x in {1,...,4} % ciclo sui cerchi
{
\draw (\x,0) -- +(0,.5);
\node[black,draw=red,very thin,fill=white,inner sep=0] at (\x,.5) {\Circle};
}
\foreach \x in {1.5,2.5,...,3.5} % ciclo sulle barrette
{
\draw (\x,0) -- +(0,-.5);
\node[black,draw=red,very thin,fill=white,inner sep=0] at (\x,-.5) {\Circle};
}
%\node[left] at (2.5,-.5) {1};

%\draw[dashed,red] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}

\end{document}