2

Suppose I have a tikz graph like this one:

enter image description here

\documentclass{standalone}

\usepackage{tikz} \usetikzlibrary{graphs,graphs.standard}

\tikzset{v-label/.style={ every node/.style={circle,draw,minimum size=1.5em,inner sep=1},}}

\begin{document}

\begin{tikzpicture}[v-label,] \graph[clockwise,radius=1cm,]{ subgraph I_n [n=5,V={f,g,h,i,j},]--subgraph C_n [n=5,V={a,b,c,d,e}]; f--h--j--g--i--f; {[edges={very thick,red,}]e--j--g--b--c--h--f--i--d--e};}; \end{tikzpicture}

\end{document}

And I wish to delete a vertex, say a, and all incident edges while mantaining the rest of the graph as it is. Like so:

enter image description here

What's the best way to do this? I've thought about manually positioning the vertices b,...,e but there's gotta be a better way, no?

1 Answers1

4

A coordinate

With this small fix to subgraph I_n from a recent answer of mine you could define

\tikzgraphsset{
  hide me/.style={
    shape=coordinate,
    target edge style=move to,
    source edge style=move to}}

and use it as such:

   subgraph I_n [n=5,V={f,g,h,i,j}]
-- subgraph C_n [n=5,V={a[hide me],b,c,d,e}];

(We could also use draw=none instead of move to.)

Unfortunately, the bounding box will include this coordinate and the option overlay won't work.

An invisible node

It does interestingly work with a real node, i.e.

\tikzgraphsset{
  hide me/.style={
    draw=none, fill=none, overlay,
    /utils/exec=\def\tikzgraphnodetext{},
    target edge style=move to,
    source edge style=move to}

Since we don't want the node's name to show up we either have to use a/[hide me] (so that the node's text is the part between / and [, i.e. nothing) or as I did here, we set it to {}.

The mentioned fix is needed for the syntax a[hide me] not for the hide me style.

Only four nodes

Thirdly, you could just place only four nodes:

 subgraph I_n [n=5,V={f,g,h,i,j}];
{[circular placement, /tikz/shift=(-90:1cm), radius=2cm,
  chain polar shift=(-72:0cm), phase=18] b -- c -- d -- e};

The chain polar shift value makes sure the node are placed at the same radius with a distance of 72° (clockwise). The phase value makes sure that the b node is placed in the same position as before. (Initially, that value is 90 which leads to the first node always placed at the top.)

Why the /tikz/shift is necessary I can't tell you exactly. It looks like it uses the f node (the first one of the previous subgraph) as the new center. And this node is placed at (90:1cm) as per the default placement.

Only four nodes using subgraph I_n

We can use a bit of the magic of the built-in subgraphs by using

subgraph I_n [n=5, V={f,g,h,i,j}];
subgraph I_n [n=4, V={b,c,d,e}, radius=2cm, 
              group polar shift=(-72:0cm), phase=18];
d -- c;

where we have to specify the connections manually (subgraph C_n would connecnt b and e) but in your case only d -- c since all others you'd overdraw anyway in thick red.

Though, we still need to specify the radius and we can't connect the subgraphs by -- because it would do f -- b, g -- c and so one. We could probably phase the first subgraph and reorder the names and …

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs.standard}
\makeatletter
\tikzgraphsset{
  declare={subgraph I_n}{
    \foreach \tikz@lib@graph@node@num in \tikzgraphV
      {[parse/.expand once=\tikz@lib@graph@node@num]}}}
\makeatother
\tikzset{
  v-label/.style={
    every node/.style={circle,draw,minimum size=1.5em,inner sep=1}}}
\tikzgraphsset{% shortcut
  connect without a/.style={
    parse={f--h--j--g--i--f;
          {[edges={very thick,red}] e--j--g--b--c--h--f--i--d--e};}}}
\begin{document}
\tikz[
  v-label,
  graphs/hide me/.style={
    shape=coordinate,
    target edge style=move to,
    source edge style=move to}
]
\graph[clockwise, radius=1cm]{
  subgraph I_n [n=5, V={f,g,h,i,j}]
--subgraph C_n [n=5, V={a[hide me],b,c,d,e}];
  {[connect without a]};
};

\tikz[ v-label, graphs/hide me/.style={ draw=none, fill=none, overlay, /utils/exec=\def\tikzgraphnodetext{}, target edge style=move to, source edge style=move to} ] \graph[clockwise, radius=1cm]{ subgraph I_n [n=5, V={f,g,h,i,j}] --subgraph C_n [n=5, V={a[hide me],b,c,d,e}]; {[connect without a]}; };

\tikz[v-label] \graph[clockwise, radius=1cm]{ subgraph I_n [n=5, V={f,g,h,i,j}]; {[circular placement, /tikz/shift=(-90:1cm), radius=2cm, chain polar shift=(-72:0cm), phase=18] b -- c -- d -- e}; {[connect without a]}; };

\tikz[v-label] \graph[clockwise, radius=1cm]{ subgraph I_n [n=5, V={f,g,h,i,j}]; subgraph I_n [n=4, V={b,c,d,e}, radius=2cm, group polar shift=(-72:0cm), phase=18]; d -- c; {[connect without a]}; }; \end{document}

Output

The output is always the same, except the first one has a higher bounding box.

enter image description here

Qrrbrbirlbel
  • 119,821
  • Thank you, I went with the first option as it mantains a constant height between graphs, so if I remove a and f on two copies of the graph and place them side by side, it looks nicer. – The Fourth Man Sep 25 '22 at 05:00