1

Currently I am unable to get all the edges coming out of a node with a double border to start exactly on the outside of the outer border. The edges are all starting in between the two borders. For example this code doesn't look perfect.

\documentclass{article}

\usepackage{tikz}
\tikzstyle{double_border} = [draw, double, double distance=2pt]

\begin{document}

\begin{tikzpicture}
    \node[double_border] (a) at (0,0) {A};
    \node[double_border] (b) at (1,0) {B} edge (a);
\end{tikzpicture}

\end{document}

output

I want to be able to set every double_border node to have all outgoing and incoming edges start on the outside border. I know I can specify it as a property of the edge (I'd have to look up how) but I want to be able to have it apply to the node settings specifically (or globally would be okay also) because I am trying to extend a 'library' called tikz-er2 and I want it to apply to all nodes of a certain type without having to complicate the user's syntax.

2

Please note that \tikzstyle is deprecated. One solution is to increase the outer sep.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\tikzset{double_border/.style={draw, double, double distance=2pt,outer sep=1.2pt}}

\begin{document}

\begin{tikzpicture}
    \node[double_border] (a) at (0,0) {A};
    \node[double_border,circle] (b) at (1,0) {B} edge (a) ; 
    \node[double_border,diamond] (c) at (0.6,1) {C} edge (a) edge (b) ; 
\end{tikzpicture}

\end{document}

enter image description here

As usual with double, these double line are not truly double lines but a thicker line overpainted with a somewhat thinner line. So if you put these on top of some background, the background will be overpainted. If you do not want to do that, you can define, for specific node shapes, another version of the double_border style such that the node boundary is realistic.

\documentclass{article}

\usepackage{tikz}
\tikzset{double_border/.style={draw,inner sep=#1+2pt,
path picture={
\draw ([xshift=#1,yshift=#1]path picture bounding box.south west)
rectangle ([xshift=-#1,yshift=-#1]path picture bounding box.north east);}},
double_border/.default=2pt}

\begin{document}

\begin{tikzpicture}
    \node[double_border] (a) at (0,0) {A};
    \node[double_border] (b) at (1,0) {B} edge (a); 
    \node[double_border] (c) at (0.6,1) {C}  edge (a)  edge (b); 
\end{tikzpicture}
\end{document}

enter image description here

The downside of this method is that it has to be done one a shape-by-shape basis, and, as usual with path pictures, not all transformations may give good results.

Other than that you might shorten the edges with shorten > and shorten <, but this is a bit cumbersome. Yet another way is to draw the edges on the background layer.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{backgrounds}
\tikzset{double_border/.style={draw, double, double distance=2pt}}

\begin{document}

\begin{tikzpicture}
    \node[double_border] (a) at (0,0) {A};
    \node[double_border] (b) at (1,0) {B}; 
    \node[double_border] (c) at (0.6,1) {C}; 
    \begin{scope}[on background layer]
    \path (b) edge (a)   edge (c) (a)  edge (c);
    \end{scope}
\end{tikzpicture}

\end{document}

enter image description here

This works because a double line is just a thick (black in this case) line overpainted by a somewhat thinner white line.

7
  • Thanks, this works. Im trying to figure out how to apply the first soluton to other shapes, specifically diamonds. Follow up Q: what is the #1 reffering to? and is there a way to do something like xshift=2*#1 Apr 6 '20 at 0:13
  • @AbrahamMurcianoBenzadon The first solution works in this form only for rectangle nodes. It draws a smaller rectangle inside the node, and the xshift and yshift is really just to define the south west and north east anchors of the smaller rectangle. Of course, the inner sep gets increased such that the rectangle does not come too close to the node contents, i.e. texts in this case. For other nodes one can repeat the trick but has to replace the rectangle by other paths such as circles etc. Only the second solution works for arbitrary node shapes out of the box.
    – user194703
    Apr 6 '20 at 0:16
  • @AbrahamMurcianoBenzadon #1 is the parameter of the style. It's default value is set to 2pt. If you use \node[double_border=4pt] (a) at (0,0) {A};, then the distance between the double lines will be 4pt.
    – user194703
    Apr 6 '20 at 0:18
  • Thanks, I just figured out how to do it for diamonds. Turns out xshift=#1+#1 works to double it (im using a skewed diamond so I have to double it on the east and west vertices) Apr 6 '20 at 0:19
  • 1
    @AbrahamMurcianoBenzadon I just realized that there is another simple solution: increase the outer sep. This also works across all node shapes, at least it should.
    – user194703
    Apr 6 '20 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.