2

I try to understand a answer from here, I modified the answer with inner xsep=0 inner ysep=0. The expected results should be the inner sep should take effect between latter B and the inner circle, but actually it the it overlapped with latter B.

How should I modify the code to not overlap with the inner circle?

Modified code:

\documentclass[border=4mm] {standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\tikzset{
    old inner xsep/.estore in=\oldinnerxsep,
    old inner ysep/.estore in=\oldinnerysep,
    double circle/.style 2 args={
        circle,
        old inner xsep=\pgfkeysvalueof{/pgf/inner xsep},
        old inner ysep=\pgfkeysvalueof{/pgf/inner ysep},
        /pgf/inner xsep=\oldinnerxsep+#1,
        /pgf/inner ysep=\oldinnerysep+#1,
        alias=sourcenode,
        append after command={
        let     \p1 = (sourcenode.center),
                \p2 = (sourcenode.east),
                \n1 = {\x2-\x1-#1-0.5*\pgflinewidth}
        in
            node [inner sep=0pt, draw, circle, minimum width=2*\n1,at=(\p1),#2] {}
        }
    },
    double circle/.default={2pt}{blue}
}


\begin{tikzpicture}
\node (A) [double circle={5pt}{red}, draw=red,font=\Huge,inner xsep=0,inner ysep=0] {B};
\node (B) at (2,0) [draw, double circle={-2pt}{orange},font=\Huge] {ABC};
\draw (A) -- (B);
\end{tikzpicture}%
%
\end{document}

Output: enter image description here

1
  • 1
    The inner sep is the space between the outer circle and your letter. To avoid overlapping with the inner circle, increase the inner sep. Commented 2 days ago

1 Answer 1

3

You can see what is happening a bit more clearly if you use different colours to distinguish the inner and outer circle around B:

\begin{tikzpicture}
  \node (A) [double circle={5pt}{red}, draw=blue,font=\Huge,inner xsep=0,inner ysep=0] {B};
  \node (B) at (2,0) [draw, double circle={-2pt}{orange},font=\Huge] {ABC};
  \draw (A) -- (B);
\end{tikzpicture}

colour for clarity

The overlapping circle is the second circle drawn. The overlap is due to the use of a positive first argument, 5pt. This is because we have

\n1 = {\x2-\x1-#1-0.5*\pgflinewidth}

So #1 is subtracted from the dimension used for the minimum width. This has nothing to do with zeroing the inner xsep and inner ysep since this node already uses inner sep=0 which implies both.

There is some discussion about this in the comments below Jake's answer and the solution was later edited, but the behaviour is not, I think, quite what was proposed in those comments.

So you really have two choices

  1. change the code so a positive first argument increases the minimum width; or
  2. specify a negative first argument rather than a positive one.

First option:

\n1 = {\x2-\x1+#1-0.5*\pgflinewidth}

first option

Second option:

\node (A) [double circle={-5pt}{red}, draw=blue,font=\Huge,inner xsep=0,inner ysep=0] {B};

second option

Note that the choice of tweak here affects the separation of the nodes, so you may prefer one or the other in any particular case.

Complete code:

\documentclass[border=4mm,tikz] {standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\tikzset{
  old inner xsep/.estore in=\oldinnerxsep,
  old inner ysep/.estore in=\oldinnerysep,
  double circle/.style 2 args={
    circle,
    old inner xsep=\pgfkeysvalueof{/pgf/inner xsep},
    old inner ysep=\pgfkeysvalueof{/pgf/inner ysep},
    /pgf/inner xsep=\oldinnerxsep+#1,
    /pgf/inner ysep=\oldinnerysep+#1,
    alias=sourcenode,
    append after command={
      let     \p1 = (sourcenode.center),
      \p2 = (sourcenode.east),
      \n1 = {\x2-\x1+#1-0.5*\pgflinewidth}
      in
      node [inner sep=0pt, draw, circle, minimum width=2*\n1,at=(\p1),#2] {}
    }
  },
  double circle/.default={2pt}{blue}
}%
\begin{tikzpicture}
  \node (A) [double circle={5pt}{red}, draw=blue,font=\Huge,inner xsep=0,inner ysep=0] {B};
  \node (B) at (2,0) [draw, double circle={2pt}{orange},font=\Huge] {ABC};
  \draw (A) -- (B);
\end{tikzpicture}
\tikzset{
  old inner xsep/.estore in=\oldinnerxsep,
  old inner ysep/.estore in=\oldinnerysep,
  double circle/.style 2 args={
    circle,
    old inner xsep=\pgfkeysvalueof{/pgf/inner xsep},
    old inner ysep=\pgfkeysvalueof{/pgf/inner ysep},
    /pgf/inner xsep=\oldinnerxsep+#1,
    /pgf/inner ysep=\oldinnerysep+#1,
    alias=sourcenode,
    append after command={
      let     \p1 = (sourcenode.center),
      \p2 = (sourcenode.east),
      \n1 = {\x2-\x1-#1-0.5*\pgflinewidth}
      in
      node [inner sep=0pt, draw, circle, minimum width=2*\n1,at=(\p1),#2] {}
    }
  },
  double circle/.default={2pt}{blue}
}%
\begin{tikzpicture}
  \node (A) [double circle={-5pt}{red}, draw=blue,font=\Huge,inner xsep=0,inner ysep=0] {B};
  \node (B) at (2,0) [draw, double circle={-2pt}{orange},font=\Huge] {ABC};
  \draw (A) -- (B);
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .