I have a large number of tikz figures involving circular nodes (some of which are filled white), which are connected by edges (some of which are thick).
The problem I am having is that whichever line cap I use, the edge either doesn't properly meet the node (e.g. line cap=butt
), or it bleeds into the white fill, as in the following MWE:
\documentclass[tikz]{standalone}
\tikzset{
every picture/.style={line width=0.45pt, line cap=round},
vtx/.style={circle, draw, fill, inner sep=0pt, minimum width=4.88125pt},
whitevtx/.style={circle, draw, fill=white, inner sep=0pt, minimum width=4.88125pt},
}
\tikzstyle{very thick}=[line width=1.65pt]
\begin{document}
\begin{tikzpicture}
\node[vtx] (A1) at (0,0) {};
\node[whitevtx] (B1) at (2,0) {};
\draw[very thick] (A1) -- (B1);
\end{tikzpicture}
\end{document}
This draws the following simple figure:
Here it is zoomed in:
Does anyone have an elegant solution to fix this? I've considered the following possibilities:
Place the edges on a background pgflayer. The problem with this is that the line cap defaults to
butt
so then needs to be re-specified (but maybe I did something wrong and there is a solution here).Draw all nodes as coordinates first, draw the lines, and then draw the vertices over the coordinates. Ugh.
I have a very large number of these images, so the solution really does need to be elegant and simple, and ideally fixed simply by applying some new global style.
Finally, some other constraints: it's against the rules to change the specified line widths, and I would ideally also keep the line cap=round
generic specifier for edges (though not necessary for edges between nodes, if these can be distinguished), as the styles set here will be applied to other types of figure too.
Edit: Thought not necessary in my particular case, a solution that could cope with really thick lines (e.g. line width=4pt
) would get extra brownie points!
outer sep=
?!line cap=butt
applied to thevery thick
style, together with specifyingouter sep=0.1
(or smaller) on thewhitevtx
style might actually just do it! Thanks.\tikzstyle{very thick}=[line width=1.65pt]
>>> we should not redefine[very thick]
(already defined, see pgfmanual) although in this case it causes no problems. Also we should use\tikzset
instead of outdatedtikzstyle
.very thick
?very thick
; or when the code is shared etc. I recommend the namemy thick
.