How to clip a background including nodes according to an arbitrary shape?How can I invert a 'clip' selection within TikZ?Tikz clip shapes with another (built in) shapeTikz clip shapes with another (built in) shapeFill Nodes according to table/data fileHow to define the default vertical distance between nodes?Rotate Tikzpicture including nodesInput/Output Nodes - Specification and Description Languageuse circuitikz picture inside tikzpictureBackground clip to text TikzRelative transparency in TikZ?Rectanglar cloud shaped node in TikZIdeal shape of elliptical nodes

How do you like my writing?

How does airport security verify that you can carry a battery bank over 100 Wh?

BitNot does not flip bits in the way I expected

What to do when during a meeting client people start to fight (even physically) with each others?

Does "variables should live in the smallest scope as possible" include the case "variables should not exist if possible"?

How do I express some one as a black person?

Should QA ask requirements to developers?

How are such low op-amp input currents possible?

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

Why is this plane circling around the Lucknow airport every day?

How could our ancestors have domesticated a solitary predator?

If the Captain's screens are out, does he switch seats with the co-pilot?

Why is there a voltage between the mains ground and my radiator?

A three room house but a three headED dog

The bar has been raised

Do Bugbears' arms literally get longer when it's their turn?

Examples of a statistic that is not independent of sample's distribution?

Fourth person (in Slavey language)

Virginia employer terminated employee and wants signing bonus returned

Best approach to update all entries in a list that is paginated?

What are some noteworthy "mic-drop" moments in math?

Is Gradient Descent central to every optimizer?

A question on the ultrafilter number

Can't find the Shader/UVs tab



How to clip a background including nodes according to an arbitrary shape?


How can I invert a 'clip' selection within TikZ?Tikz clip shapes with another (built in) shapeTikz clip shapes with another (built in) shapeFill Nodes according to table/data fileHow to define the default vertical distance between nodes?Rotate Tikzpicture including nodesInput/Output Nodes - Specification and Description Languageuse circuitikz picture inside tikzpictureBackground clip to text TikzRelative transparency in TikZ?Rectanglar cloud shaped node in TikZIdeal shape of elliptical nodes













5















The following WE



documentclass[border=10pt]standalone
usepackage[dvipsnames]xcolor
usepackagetikz
usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

tikzstylebackA=[rectangle,
fill=blue!30,
inner sep=0.2cm,
rounded corners=0mm]

tikzstylebackB=[rectangle,
fill=purple!15,
inner sep=0.2cm,
rounded corners=0mm]

tikzstylebackC=[rectangle,
fill=yellow!40,
inner sep=0.2cm,
rounded corners=0mm]

tikzset%
>=Latex[width=2mm,length=2mm],
base/.style = rectangle, rounded corners, draw=black,
minimum width=1cm, minimum height=1cm,
text centered,inner sep=0.3cm,
operation/.style = base, fill=SkyBlue,


begindocument
begintikzpicture[node distance=0.8cm,
every node/.style=fill=white, align=center]
node (controller) [operation] Microcontroller;
node (regulator) [operation, below = of controller] Regulator;
node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
node (sensor) [operation, above = of controller] Sensor;
node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
node (driver1) [operation, right = of sensor] Driver 1;
node (driver2) [operation, left = of sensor] Driver 2;
node (power) [operation, left = of regulator, align=center] Input \ Power;
node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
coordinate[left = of power] (d1) ;
coordinate[above = of d1, yshift=5.5cm] (d2) ;

draw[->] (controller) -- (transceiver);
draw[<->] (controller) -- (sensor);
draw[->] (driver1) -- (motor1);
draw[->] (driver2) -- (motor2);
draw[<->] (sensor) -- (motor2);
draw[<->] (sensor) -- (motor1);
draw[->] (controller) -- (driver1);
draw[->] (controller) -- (driver2);
draw[->] (controller) -- (flash);
draw[->] (regulator) -- (controller);
draw[->] (power) -- (regulator);
draw[<->] (transceiver) -- (computer);
draw[->] (power) -- (d1) |- (motor2);
draw[->] (power) -- (d1) -- (d2) -| (motor1);

beginpgfonlayerbackground
node [backC,
fit=(driver1) (driver2) (sensor) (motor1) (motor2),
label=above:] ;

node [backA,
fit=(computer) (transceiver),
label=above:] ;

node [backB,
fit=(regulator) (power),
label=above:] ;
endpgfonlayer
endtikzpicture
enddocument


yields



enter image description here



Since the driver1 node should have been exclusively covered by the yellow background, I need to subtract the specific part of the violet background which interferes with the yellow one. In particular, an acceptable boundary for the violet background may roughly be like this:



enter image description here



How can I achieve something like that?










share|improve this question






















  • Might be useful: tex.stackexchange.com/questions/53184/…

    – Raaja
    14 hours ago






  • 1





    I don't think you need to crop the blue part. You only have to draw the yellow part after the blue part -- in that case, the yellow part will overfill the blue part.

    – JouleV
    14 hours ago











  • @Roboticist If I understand your comment, you only need to put a white frame of the yellow part. This can be done with draw=white.

    – JouleV
    13 hours ago






  • 1





    @JouleV: The yellow background is indeed drawn "after" the blue background in the WE. Additionally, I'd like to know a potential approach to achieving margins with arbitrary shapes.

    – Roboticist
    13 hours ago
















5















The following WE



documentclass[border=10pt]standalone
usepackage[dvipsnames]xcolor
usepackagetikz
usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

tikzstylebackA=[rectangle,
fill=blue!30,
inner sep=0.2cm,
rounded corners=0mm]

tikzstylebackB=[rectangle,
fill=purple!15,
inner sep=0.2cm,
rounded corners=0mm]

tikzstylebackC=[rectangle,
fill=yellow!40,
inner sep=0.2cm,
rounded corners=0mm]

tikzset%
>=Latex[width=2mm,length=2mm],
base/.style = rectangle, rounded corners, draw=black,
minimum width=1cm, minimum height=1cm,
text centered,inner sep=0.3cm,
operation/.style = base, fill=SkyBlue,


begindocument
begintikzpicture[node distance=0.8cm,
every node/.style=fill=white, align=center]
node (controller) [operation] Microcontroller;
node (regulator) [operation, below = of controller] Regulator;
node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
node (sensor) [operation, above = of controller] Sensor;
node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
node (driver1) [operation, right = of sensor] Driver 1;
node (driver2) [operation, left = of sensor] Driver 2;
node (power) [operation, left = of regulator, align=center] Input \ Power;
node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
coordinate[left = of power] (d1) ;
coordinate[above = of d1, yshift=5.5cm] (d2) ;

draw[->] (controller) -- (transceiver);
draw[<->] (controller) -- (sensor);
draw[->] (driver1) -- (motor1);
draw[->] (driver2) -- (motor2);
draw[<->] (sensor) -- (motor2);
draw[<->] (sensor) -- (motor1);
draw[->] (controller) -- (driver1);
draw[->] (controller) -- (driver2);
draw[->] (controller) -- (flash);
draw[->] (regulator) -- (controller);
draw[->] (power) -- (regulator);
draw[<->] (transceiver) -- (computer);
draw[->] (power) -- (d1) |- (motor2);
draw[->] (power) -- (d1) -- (d2) -| (motor1);

beginpgfonlayerbackground
node [backC,
fit=(driver1) (driver2) (sensor) (motor1) (motor2),
label=above:] ;

node [backA,
fit=(computer) (transceiver),
label=above:] ;

node [backB,
fit=(regulator) (power),
label=above:] ;
endpgfonlayer
endtikzpicture
enddocument


yields



enter image description here



Since the driver1 node should have been exclusively covered by the yellow background, I need to subtract the specific part of the violet background which interferes with the yellow one. In particular, an acceptable boundary for the violet background may roughly be like this:



enter image description here



How can I achieve something like that?










share|improve this question






















  • Might be useful: tex.stackexchange.com/questions/53184/…

    – Raaja
    14 hours ago






  • 1





    I don't think you need to crop the blue part. You only have to draw the yellow part after the blue part -- in that case, the yellow part will overfill the blue part.

    – JouleV
    14 hours ago











  • @Roboticist If I understand your comment, you only need to put a white frame of the yellow part. This can be done with draw=white.

    – JouleV
    13 hours ago






  • 1





    @JouleV: The yellow background is indeed drawn "after" the blue background in the WE. Additionally, I'd like to know a potential approach to achieving margins with arbitrary shapes.

    – Roboticist
    13 hours ago














5












5








5


1






The following WE



documentclass[border=10pt]standalone
usepackage[dvipsnames]xcolor
usepackagetikz
usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

tikzstylebackA=[rectangle,
fill=blue!30,
inner sep=0.2cm,
rounded corners=0mm]

tikzstylebackB=[rectangle,
fill=purple!15,
inner sep=0.2cm,
rounded corners=0mm]

tikzstylebackC=[rectangle,
fill=yellow!40,
inner sep=0.2cm,
rounded corners=0mm]

tikzset%
>=Latex[width=2mm,length=2mm],
base/.style = rectangle, rounded corners, draw=black,
minimum width=1cm, minimum height=1cm,
text centered,inner sep=0.3cm,
operation/.style = base, fill=SkyBlue,


begindocument
begintikzpicture[node distance=0.8cm,
every node/.style=fill=white, align=center]
node (controller) [operation] Microcontroller;
node (regulator) [operation, below = of controller] Regulator;
node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
node (sensor) [operation, above = of controller] Sensor;
node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
node (driver1) [operation, right = of sensor] Driver 1;
node (driver2) [operation, left = of sensor] Driver 2;
node (power) [operation, left = of regulator, align=center] Input \ Power;
node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
coordinate[left = of power] (d1) ;
coordinate[above = of d1, yshift=5.5cm] (d2) ;

draw[->] (controller) -- (transceiver);
draw[<->] (controller) -- (sensor);
draw[->] (driver1) -- (motor1);
draw[->] (driver2) -- (motor2);
draw[<->] (sensor) -- (motor2);
draw[<->] (sensor) -- (motor1);
draw[->] (controller) -- (driver1);
draw[->] (controller) -- (driver2);
draw[->] (controller) -- (flash);
draw[->] (regulator) -- (controller);
draw[->] (power) -- (regulator);
draw[<->] (transceiver) -- (computer);
draw[->] (power) -- (d1) |- (motor2);
draw[->] (power) -- (d1) -- (d2) -| (motor1);

beginpgfonlayerbackground
node [backC,
fit=(driver1) (driver2) (sensor) (motor1) (motor2),
label=above:] ;

node [backA,
fit=(computer) (transceiver),
label=above:] ;

node [backB,
fit=(regulator) (power),
label=above:] ;
endpgfonlayer
endtikzpicture
enddocument


yields



enter image description here



Since the driver1 node should have been exclusively covered by the yellow background, I need to subtract the specific part of the violet background which interferes with the yellow one. In particular, an acceptable boundary for the violet background may roughly be like this:



enter image description here



How can I achieve something like that?










share|improve this question














The following WE



documentclass[border=10pt]standalone
usepackage[dvipsnames]xcolor
usepackagetikz
usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

tikzstylebackA=[rectangle,
fill=blue!30,
inner sep=0.2cm,
rounded corners=0mm]

tikzstylebackB=[rectangle,
fill=purple!15,
inner sep=0.2cm,
rounded corners=0mm]

tikzstylebackC=[rectangle,
fill=yellow!40,
inner sep=0.2cm,
rounded corners=0mm]

tikzset%
>=Latex[width=2mm,length=2mm],
base/.style = rectangle, rounded corners, draw=black,
minimum width=1cm, minimum height=1cm,
text centered,inner sep=0.3cm,
operation/.style = base, fill=SkyBlue,


begindocument
begintikzpicture[node distance=0.8cm,
every node/.style=fill=white, align=center]
node (controller) [operation] Microcontroller;
node (regulator) [operation, below = of controller] Regulator;
node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
node (sensor) [operation, above = of controller] Sensor;
node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
node (driver1) [operation, right = of sensor] Driver 1;
node (driver2) [operation, left = of sensor] Driver 2;
node (power) [operation, left = of regulator, align=center] Input \ Power;
node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
coordinate[left = of power] (d1) ;
coordinate[above = of d1, yshift=5.5cm] (d2) ;

draw[->] (controller) -- (transceiver);
draw[<->] (controller) -- (sensor);
draw[->] (driver1) -- (motor1);
draw[->] (driver2) -- (motor2);
draw[<->] (sensor) -- (motor2);
draw[<->] (sensor) -- (motor1);
draw[->] (controller) -- (driver1);
draw[->] (controller) -- (driver2);
draw[->] (controller) -- (flash);
draw[->] (regulator) -- (controller);
draw[->] (power) -- (regulator);
draw[<->] (transceiver) -- (computer);
draw[->] (power) -- (d1) |- (motor2);
draw[->] (power) -- (d1) -- (d2) -| (motor1);

beginpgfonlayerbackground
node [backC,
fit=(driver1) (driver2) (sensor) (motor1) (motor2),
label=above:] ;

node [backA,
fit=(computer) (transceiver),
label=above:] ;

node [backB,
fit=(regulator) (power),
label=above:] ;
endpgfonlayer
endtikzpicture
enddocument


yields



enter image description here



Since the driver1 node should have been exclusively covered by the yellow background, I need to subtract the specific part of the violet background which interferes with the yellow one. In particular, an acceptable boundary for the violet background may roughly be like this:



enter image description here



How can I achieve something like that?







tikz-pgf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 14 hours ago









RoboticistRoboticist

1,69121231




1,69121231












  • Might be useful: tex.stackexchange.com/questions/53184/…

    – Raaja
    14 hours ago






  • 1





    I don't think you need to crop the blue part. You only have to draw the yellow part after the blue part -- in that case, the yellow part will overfill the blue part.

    – JouleV
    14 hours ago











  • @Roboticist If I understand your comment, you only need to put a white frame of the yellow part. This can be done with draw=white.

    – JouleV
    13 hours ago






  • 1





    @JouleV: The yellow background is indeed drawn "after" the blue background in the WE. Additionally, I'd like to know a potential approach to achieving margins with arbitrary shapes.

    – Roboticist
    13 hours ago


















  • Might be useful: tex.stackexchange.com/questions/53184/…

    – Raaja
    14 hours ago






  • 1





    I don't think you need to crop the blue part. You only have to draw the yellow part after the blue part -- in that case, the yellow part will overfill the blue part.

    – JouleV
    14 hours ago











  • @Roboticist If I understand your comment, you only need to put a white frame of the yellow part. This can be done with draw=white.

    – JouleV
    13 hours ago






  • 1





    @JouleV: The yellow background is indeed drawn "after" the blue background in the WE. Additionally, I'd like to know a potential approach to achieving margins with arbitrary shapes.

    – Roboticist
    13 hours ago

















Might be useful: tex.stackexchange.com/questions/53184/…

– Raaja
14 hours ago





Might be useful: tex.stackexchange.com/questions/53184/…

– Raaja
14 hours ago




1




1





I don't think you need to crop the blue part. You only have to draw the yellow part after the blue part -- in that case, the yellow part will overfill the blue part.

– JouleV
14 hours ago





I don't think you need to crop the blue part. You only have to draw the yellow part after the blue part -- in that case, the yellow part will overfill the blue part.

– JouleV
14 hours ago













@Roboticist If I understand your comment, you only need to put a white frame of the yellow part. This can be done with draw=white.

– JouleV
13 hours ago





@Roboticist If I understand your comment, you only need to put a white frame of the yellow part. This can be done with draw=white.

– JouleV
13 hours ago




1




1





@JouleV: The yellow background is indeed drawn "after" the blue background in the WE. Additionally, I'd like to know a potential approach to achieving margins with arbitrary shapes.

– Roboticist
13 hours ago






@JouleV: The yellow background is indeed drawn "after" the blue background in the WE. Additionally, I'd like to know a potential approach to achieving margins with arbitrary shapes.

– Roboticist
13 hours ago











3 Answers
3






active

oldest

votes


















4














I would not overdraw areas with white, imagine you have some background you want to keep. And tikzstyle is deprecated.



documentclass[border=10pt]standalone
usepackage[dvipsnames]xcolor
usepackagetikz
usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

% based on https://tex.stackexchange.com/a/12033/121799
tikzsetreverseclip/.style=insert path=(current bounding box.south west)rectangle
(current bounding box.north east)

tikzsetbackA/.style=rectangle,
fill=blue!30,
inner sep=0.2cm,
rounded corners=0mm,
backB/.style=rectangle,
fill=purple!15,
inner sep=0.2cm,
rounded corners=0mm,
backC/.style=rectangle,
fill=yellow!40,
inner sep=0.2cm,
rounded corners=0mm

tikzset%
>=Latex[width=2mm,length=2mm],
base/.style = rectangle, rounded corners, draw=black,
minimum width=1cm, minimum height=1cm,
text centered,inner sep=0.3cm,
operation/.style = base, fill=SkyBlue,


begindocument
begintikzpicture[node distance=0.8cm,
every node/.style=fill=white, align=center]
node (controller) [operation] Microcontroller;
node (regulator) [operation, below = of controller] Regulator;
node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
node (sensor) [operation, above = of controller] Sensor;
node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
node (driver1) [operation, right = of sensor] Driver 1;
node (driver2) [operation, left = of sensor] Driver 2;
node (power) [operation, left = of regulator, align=center] Input \ Power;
node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
coordinate[left = of power] (d1) ;
coordinate[above = of d1, yshift=5.5cm] (d2) ;

draw[->] (controller) -- (transceiver);
draw[<->] (controller) -- (sensor);
draw[->] (driver1) -- (motor1);
draw[->] (driver2) -- (motor2);
draw[<->] (sensor) -- (motor2);
draw[<->] (sensor) -- (motor1);
draw[->] (controller) -- (driver1);
draw[->] (controller) -- (driver2);
draw[->] (controller) -- (flash);
draw[->] (regulator) -- (controller);
draw[->] (power) -- (regulator);
draw[<->] (transceiver) -- (computer);
draw[->] (power) -- (d1) |- (motor2);
draw[->] (power) -- (d1) -- (d2) -| (motor1);

beginpgfonlayerbackground
node [backC,
fit=(driver1) (driver2) (sensor) (motor1) (motor2),
label=above:] (F1);

node [backB,
fit=(regulator) (power),
label=above:] ;
clip ([xshift=-5pt,yshift=-5pt]F1.south west) -|
([xshift=5pt,yshift=5pt]F1.north east) -| cycle [reverseclip];
node [backA,
fit=(computer) (transceiver),
label=above:] ;
endpgfonlayer
endtikzpicture
enddocument


enter image description here






share|improve this answer






























    3














    Like this?



    screenshot



    documentclass[border=10pt]standalone
    usepackage[dvipsnames]xcolor
    usepackagetikz
    usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds
    pgfdeclarelayerbackground
    pgfdeclarelayermiddle
    pgfdeclarelayerforeground
    pgfsetlayersbackground,main,middle,foreground
    tikzstylebackA=[rectangle,
    fill=blue!30,
    inner sep=0.2cm,
    rounded corners=0mm]

    tikzstylebackB=[rectangle,
    fill=purple!15,
    inner sep=0.2cm,
    rounded corners=0mm]

    tikzstylebackC=[rectangle,
    fill=yellow!40,
    %inner sep=0.2cm,
    rounded corners=0mm]

    tikzset%
    >=Latex[width=2mm,length=2mm],
    base/.style = rectangle, rounded corners, draw=black,
    minimum width=1cm, minimum height=1cm,
    text centered,inner sep=0.3cm,
    operation/.style = base, fill=SkyBlue,


    begindocument
    begintikzpicture[node distance=0.8cm,
    every node/.style=fill=white, align=center]
    beginpgfonlayerforeground
    node (controller) [operation] Microcontroller;
    node (regulator) [operation, below = of controller] Regulator;
    node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
    node (sensor) [operation, above = of controller] Sensor;
    node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
    node (driver1) [operation, right = of sensor] Driver 1;
    node (driver2) [operation, left = of sensor] Driver 2;
    node (power) [operation, left = of regulator, align=center] Input \ Power;
    node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
    node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
    node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
    coordinate[left = of power] (d1) ;
    coordinate[above = of d1, yshift=5.5cm] (d2) ;

    draw[->] (controller) -- (transceiver);
    draw[<->] (controller) -- (sensor);
    draw[->] (driver1) -- (motor1);
    draw[->] (driver2) -- (motor2);
    draw[<->] (sensor) -- (motor2);
    draw[<->] (sensor) -- (motor1);
    draw[->] (controller) -- (driver1);
    draw[->] (controller) -- (driver2);
    draw[->] (controller) -- (flash);
    draw[->] (regulator) -- (controller);
    draw[->] (power) -- (regulator);
    draw[<->] (transceiver) -- (computer);
    draw[->] (power) -- (d1) |- (motor2);
    draw[->] (power) -- (d1) -- (d2) -| (motor1);
    endpgfonlayer
    beginpgfonlayermiddle
    node [backC,
    fit=(driver1) (driver2) (sensor) (motor1) (motor2),
    label=above:] ;
    endpgfonlayer
    beginpgfonlayermain
    node [fill=white,inner sep=3mm,
    fit=(driver1) (driver2) (sensor) (motor1) (motor2),
    label=above:] ;
    endpgfonlayer
    beginpgfonlayerbackground
    node [backA,
    fit=(computer) (transceiver),
    label=above:] ;
    endpgfonlayer
    node [backB,
    fit=(regulator) (power),
    label=above:] ;
    endtikzpicture
    enddocument





    share|improve this answer




















    • 1





      How can one insert a little of white margin between the boundaries of the two backgrounds? I mean, the backgrounds are tangent to each other right now.

      – Roboticist
      13 hours ago












    • @Roboticist I have updated my answer by adding another layer named middle

      – AndréC
      13 hours ago



















    2














    For arbitrary shapes (not nodes), one cannot use fitting.
    demo



    documentclass[border=10pt]standalone
    usepackage[dvipsnames]xcolor
    usepackagetikz
    usetikzlibraryarrows.meta,shapes, positioning, calc, backgrounds

    tikzset%
    >=Latex[width=2mm,length=2mm],
    base/.style = rectangle, rounded corners, draw=black,
    minimum width=1cm, minimum height=1cm,
    text centered,inner sep=0.3cm,
    operation/.style = base, fill=SkyBlue,


    begindocument
    begintikzpicture[node distance=0.8cm,
    every node/.style=fill=white, align=center]
    node (controller) [operation] Microcontroller;
    node (regulator) [operation, below = of controller] Regulator;
    node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
    node (sensor) [operation, above = of controller] Sensor;
    node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
    node (driver1) [operation, right = of sensor] Driver 1;
    node (driver2) [operation, left = of sensor] Driver 2;
    node (power) [operation, left = of regulator, align=center] Input \ Power;
    node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
    node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
    node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
    coordinate[left = of power] (d1) ;
    coordinate[above = of d1, yshift=5.5cm] (d2) ;

    draw[->] (controller) -- (transceiver);
    draw[<->] (controller) -- (sensor);
    draw[->] (driver1) -- (motor1);
    draw[->] (driver2) -- (motor2);
    draw[<->] (sensor) -- (motor2);
    draw[<->] (sensor) -- (motor1);
    draw[->] (controller) -- (driver1);
    draw[->] (controller) -- (driver2);
    draw[->] (controller) -- (flash);
    draw[->] (regulator) -- (controller);
    draw[->] (power) -- (regulator);
    draw[<->] (transceiver) -- (computer);
    draw[->] (power) -- (d1) |- (motor2);
    draw[->] (power) -- (d1) -- (d2) -| (motor1);

    beginpgfonlayerbackground
    path (driver1.east |- computer.north) ++ (0.2,0.2) coordinate(int1);
    path (driver2.south -| transceiver.west) ++ (-0.2,-0.2) coordinate(int2);

    fill[yellow!40] ($(driver2.south west)+(-0.2,-0.2)$) |- ($(motor2.north)+(0,0.2)$) -| (int1) -- (int2) -- cycle;
    fill[blue!30] ($(transceiver.south west)+(-0.2,-0.2)$) -- (int2) -- (int1) --
    ($(computer.north)+(0,0.2)$) -| ($(computer.east)+(0.2,0)$) |- cycle;
    fill[purple!15] ($(power.south west)+(-0.2,-0.2)$) |- ($(power.north)+(0,0.2)$) -| ($(regulator.east)+(0.2,0.2)$) |- cycle;
    endpgfonlayer
    endtikzpicture
    enddocument





    share|improve this answer






















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "85"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f479108%2fhow-to-clip-a-background-including-nodes-according-to-an-arbitrary-shape%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      I would not overdraw areas with white, imagine you have some background you want to keep. And tikzstyle is deprecated.



      documentclass[border=10pt]standalone
      usepackage[dvipsnames]xcolor
      usepackagetikz
      usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

      % based on https://tex.stackexchange.com/a/12033/121799
      tikzsetreverseclip/.style=insert path=(current bounding box.south west)rectangle
      (current bounding box.north east)

      tikzsetbackA/.style=rectangle,
      fill=blue!30,
      inner sep=0.2cm,
      rounded corners=0mm,
      backB/.style=rectangle,
      fill=purple!15,
      inner sep=0.2cm,
      rounded corners=0mm,
      backC/.style=rectangle,
      fill=yellow!40,
      inner sep=0.2cm,
      rounded corners=0mm

      tikzset%
      >=Latex[width=2mm,length=2mm],
      base/.style = rectangle, rounded corners, draw=black,
      minimum width=1cm, minimum height=1cm,
      text centered,inner sep=0.3cm,
      operation/.style = base, fill=SkyBlue,


      begindocument
      begintikzpicture[node distance=0.8cm,
      every node/.style=fill=white, align=center]
      node (controller) [operation] Microcontroller;
      node (regulator) [operation, below = of controller] Regulator;
      node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
      node (sensor) [operation, above = of controller] Sensor;
      node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
      node (driver1) [operation, right = of sensor] Driver 1;
      node (driver2) [operation, left = of sensor] Driver 2;
      node (power) [operation, left = of regulator, align=center] Input \ Power;
      node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
      node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
      node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
      coordinate[left = of power] (d1) ;
      coordinate[above = of d1, yshift=5.5cm] (d2) ;

      draw[->] (controller) -- (transceiver);
      draw[<->] (controller) -- (sensor);
      draw[->] (driver1) -- (motor1);
      draw[->] (driver2) -- (motor2);
      draw[<->] (sensor) -- (motor2);
      draw[<->] (sensor) -- (motor1);
      draw[->] (controller) -- (driver1);
      draw[->] (controller) -- (driver2);
      draw[->] (controller) -- (flash);
      draw[->] (regulator) -- (controller);
      draw[->] (power) -- (regulator);
      draw[<->] (transceiver) -- (computer);
      draw[->] (power) -- (d1) |- (motor2);
      draw[->] (power) -- (d1) -- (d2) -| (motor1);

      beginpgfonlayerbackground
      node [backC,
      fit=(driver1) (driver2) (sensor) (motor1) (motor2),
      label=above:] (F1);

      node [backB,
      fit=(regulator) (power),
      label=above:] ;
      clip ([xshift=-5pt,yshift=-5pt]F1.south west) -|
      ([xshift=5pt,yshift=5pt]F1.north east) -| cycle [reverseclip];
      node [backA,
      fit=(computer) (transceiver),
      label=above:] ;
      endpgfonlayer
      endtikzpicture
      enddocument


      enter image description here






      share|improve this answer



























        4














        I would not overdraw areas with white, imagine you have some background you want to keep. And tikzstyle is deprecated.



        documentclass[border=10pt]standalone
        usepackage[dvipsnames]xcolor
        usepackagetikz
        usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

        % based on https://tex.stackexchange.com/a/12033/121799
        tikzsetreverseclip/.style=insert path=(current bounding box.south west)rectangle
        (current bounding box.north east)

        tikzsetbackA/.style=rectangle,
        fill=blue!30,
        inner sep=0.2cm,
        rounded corners=0mm,
        backB/.style=rectangle,
        fill=purple!15,
        inner sep=0.2cm,
        rounded corners=0mm,
        backC/.style=rectangle,
        fill=yellow!40,
        inner sep=0.2cm,
        rounded corners=0mm

        tikzset%
        >=Latex[width=2mm,length=2mm],
        base/.style = rectangle, rounded corners, draw=black,
        minimum width=1cm, minimum height=1cm,
        text centered,inner sep=0.3cm,
        operation/.style = base, fill=SkyBlue,


        begindocument
        begintikzpicture[node distance=0.8cm,
        every node/.style=fill=white, align=center]
        node (controller) [operation] Microcontroller;
        node (regulator) [operation, below = of controller] Regulator;
        node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
        node (sensor) [operation, above = of controller] Sensor;
        node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
        node (driver1) [operation, right = of sensor] Driver 1;
        node (driver2) [operation, left = of sensor] Driver 2;
        node (power) [operation, left = of regulator, align=center] Input \ Power;
        node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
        node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
        node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
        coordinate[left = of power] (d1) ;
        coordinate[above = of d1, yshift=5.5cm] (d2) ;

        draw[->] (controller) -- (transceiver);
        draw[<->] (controller) -- (sensor);
        draw[->] (driver1) -- (motor1);
        draw[->] (driver2) -- (motor2);
        draw[<->] (sensor) -- (motor2);
        draw[<->] (sensor) -- (motor1);
        draw[->] (controller) -- (driver1);
        draw[->] (controller) -- (driver2);
        draw[->] (controller) -- (flash);
        draw[->] (regulator) -- (controller);
        draw[->] (power) -- (regulator);
        draw[<->] (transceiver) -- (computer);
        draw[->] (power) -- (d1) |- (motor2);
        draw[->] (power) -- (d1) -- (d2) -| (motor1);

        beginpgfonlayerbackground
        node [backC,
        fit=(driver1) (driver2) (sensor) (motor1) (motor2),
        label=above:] (F1);

        node [backB,
        fit=(regulator) (power),
        label=above:] ;
        clip ([xshift=-5pt,yshift=-5pt]F1.south west) -|
        ([xshift=5pt,yshift=5pt]F1.north east) -| cycle [reverseclip];
        node [backA,
        fit=(computer) (transceiver),
        label=above:] ;
        endpgfonlayer
        endtikzpicture
        enddocument


        enter image description here






        share|improve this answer

























          4












          4








          4







          I would not overdraw areas with white, imagine you have some background you want to keep. And tikzstyle is deprecated.



          documentclass[border=10pt]standalone
          usepackage[dvipsnames]xcolor
          usepackagetikz
          usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

          % based on https://tex.stackexchange.com/a/12033/121799
          tikzsetreverseclip/.style=insert path=(current bounding box.south west)rectangle
          (current bounding box.north east)

          tikzsetbackA/.style=rectangle,
          fill=blue!30,
          inner sep=0.2cm,
          rounded corners=0mm,
          backB/.style=rectangle,
          fill=purple!15,
          inner sep=0.2cm,
          rounded corners=0mm,
          backC/.style=rectangle,
          fill=yellow!40,
          inner sep=0.2cm,
          rounded corners=0mm

          tikzset%
          >=Latex[width=2mm,length=2mm],
          base/.style = rectangle, rounded corners, draw=black,
          minimum width=1cm, minimum height=1cm,
          text centered,inner sep=0.3cm,
          operation/.style = base, fill=SkyBlue,


          begindocument
          begintikzpicture[node distance=0.8cm,
          every node/.style=fill=white, align=center]
          node (controller) [operation] Microcontroller;
          node (regulator) [operation, below = of controller] Regulator;
          node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
          node (sensor) [operation, above = of controller] Sensor;
          node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
          node (driver1) [operation, right = of sensor] Driver 1;
          node (driver2) [operation, left = of sensor] Driver 2;
          node (power) [operation, left = of regulator, align=center] Input \ Power;
          node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
          node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
          node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
          coordinate[left = of power] (d1) ;
          coordinate[above = of d1, yshift=5.5cm] (d2) ;

          draw[->] (controller) -- (transceiver);
          draw[<->] (controller) -- (sensor);
          draw[->] (driver1) -- (motor1);
          draw[->] (driver2) -- (motor2);
          draw[<->] (sensor) -- (motor2);
          draw[<->] (sensor) -- (motor1);
          draw[->] (controller) -- (driver1);
          draw[->] (controller) -- (driver2);
          draw[->] (controller) -- (flash);
          draw[->] (regulator) -- (controller);
          draw[->] (power) -- (regulator);
          draw[<->] (transceiver) -- (computer);
          draw[->] (power) -- (d1) |- (motor2);
          draw[->] (power) -- (d1) -- (d2) -| (motor1);

          beginpgfonlayerbackground
          node [backC,
          fit=(driver1) (driver2) (sensor) (motor1) (motor2),
          label=above:] (F1);

          node [backB,
          fit=(regulator) (power),
          label=above:] ;
          clip ([xshift=-5pt,yshift=-5pt]F1.south west) -|
          ([xshift=5pt,yshift=5pt]F1.north east) -| cycle [reverseclip];
          node [backA,
          fit=(computer) (transceiver),
          label=above:] ;
          endpgfonlayer
          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer













          I would not overdraw areas with white, imagine you have some background you want to keep. And tikzstyle is deprecated.



          documentclass[border=10pt]standalone
          usepackage[dvipsnames]xcolor
          usepackagetikz
          usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds

          % based on https://tex.stackexchange.com/a/12033/121799
          tikzsetreverseclip/.style=insert path=(current bounding box.south west)rectangle
          (current bounding box.north east)

          tikzsetbackA/.style=rectangle,
          fill=blue!30,
          inner sep=0.2cm,
          rounded corners=0mm,
          backB/.style=rectangle,
          fill=purple!15,
          inner sep=0.2cm,
          rounded corners=0mm,
          backC/.style=rectangle,
          fill=yellow!40,
          inner sep=0.2cm,
          rounded corners=0mm

          tikzset%
          >=Latex[width=2mm,length=2mm],
          base/.style = rectangle, rounded corners, draw=black,
          minimum width=1cm, minimum height=1cm,
          text centered,inner sep=0.3cm,
          operation/.style = base, fill=SkyBlue,


          begindocument
          begintikzpicture[node distance=0.8cm,
          every node/.style=fill=white, align=center]
          node (controller) [operation] Microcontroller;
          node (regulator) [operation, below = of controller] Regulator;
          node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
          node (sensor) [operation, above = of controller] Sensor;
          node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
          node (driver1) [operation, right = of sensor] Driver 1;
          node (driver2) [operation, left = of sensor] Driver 2;
          node (power) [operation, left = of regulator, align=center] Input \ Power;
          node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
          node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
          node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
          coordinate[left = of power] (d1) ;
          coordinate[above = of d1, yshift=5.5cm] (d2) ;

          draw[->] (controller) -- (transceiver);
          draw[<->] (controller) -- (sensor);
          draw[->] (driver1) -- (motor1);
          draw[->] (driver2) -- (motor2);
          draw[<->] (sensor) -- (motor2);
          draw[<->] (sensor) -- (motor1);
          draw[->] (controller) -- (driver1);
          draw[->] (controller) -- (driver2);
          draw[->] (controller) -- (flash);
          draw[->] (regulator) -- (controller);
          draw[->] (power) -- (regulator);
          draw[<->] (transceiver) -- (computer);
          draw[->] (power) -- (d1) |- (motor2);
          draw[->] (power) -- (d1) -- (d2) -| (motor1);

          beginpgfonlayerbackground
          node [backC,
          fit=(driver1) (driver2) (sensor) (motor1) (motor2),
          label=above:] (F1);

          node [backB,
          fit=(regulator) (power),
          label=above:] ;
          clip ([xshift=-5pt,yshift=-5pt]F1.south west) -|
          ([xshift=5pt,yshift=5pt]F1.north east) -| cycle [reverseclip];
          node [backA,
          fit=(computer) (transceiver),
          label=above:] ;
          endpgfonlayer
          endtikzpicture
          enddocument


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 12 hours ago









          marmotmarmot

          108k5131247




          108k5131247





















              3














              Like this?



              screenshot



              documentclass[border=10pt]standalone
              usepackage[dvipsnames]xcolor
              usepackagetikz
              usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds
              pgfdeclarelayerbackground
              pgfdeclarelayermiddle
              pgfdeclarelayerforeground
              pgfsetlayersbackground,main,middle,foreground
              tikzstylebackA=[rectangle,
              fill=blue!30,
              inner sep=0.2cm,
              rounded corners=0mm]

              tikzstylebackB=[rectangle,
              fill=purple!15,
              inner sep=0.2cm,
              rounded corners=0mm]

              tikzstylebackC=[rectangle,
              fill=yellow!40,
              %inner sep=0.2cm,
              rounded corners=0mm]

              tikzset%
              >=Latex[width=2mm,length=2mm],
              base/.style = rectangle, rounded corners, draw=black,
              minimum width=1cm, minimum height=1cm,
              text centered,inner sep=0.3cm,
              operation/.style = base, fill=SkyBlue,


              begindocument
              begintikzpicture[node distance=0.8cm,
              every node/.style=fill=white, align=center]
              beginpgfonlayerforeground
              node (controller) [operation] Microcontroller;
              node (regulator) [operation, below = of controller] Regulator;
              node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
              node (sensor) [operation, above = of controller] Sensor;
              node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
              node (driver1) [operation, right = of sensor] Driver 1;
              node (driver2) [operation, left = of sensor] Driver 2;
              node (power) [operation, left = of regulator, align=center] Input \ Power;
              node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
              node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
              node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
              coordinate[left = of power] (d1) ;
              coordinate[above = of d1, yshift=5.5cm] (d2) ;

              draw[->] (controller) -- (transceiver);
              draw[<->] (controller) -- (sensor);
              draw[->] (driver1) -- (motor1);
              draw[->] (driver2) -- (motor2);
              draw[<->] (sensor) -- (motor2);
              draw[<->] (sensor) -- (motor1);
              draw[->] (controller) -- (driver1);
              draw[->] (controller) -- (driver2);
              draw[->] (controller) -- (flash);
              draw[->] (regulator) -- (controller);
              draw[->] (power) -- (regulator);
              draw[<->] (transceiver) -- (computer);
              draw[->] (power) -- (d1) |- (motor2);
              draw[->] (power) -- (d1) -- (d2) -| (motor1);
              endpgfonlayer
              beginpgfonlayermiddle
              node [backC,
              fit=(driver1) (driver2) (sensor) (motor1) (motor2),
              label=above:] ;
              endpgfonlayer
              beginpgfonlayermain
              node [fill=white,inner sep=3mm,
              fit=(driver1) (driver2) (sensor) (motor1) (motor2),
              label=above:] ;
              endpgfonlayer
              beginpgfonlayerbackground
              node [backA,
              fit=(computer) (transceiver),
              label=above:] ;
              endpgfonlayer
              node [backB,
              fit=(regulator) (power),
              label=above:] ;
              endtikzpicture
              enddocument





              share|improve this answer




















              • 1





                How can one insert a little of white margin between the boundaries of the two backgrounds? I mean, the backgrounds are tangent to each other right now.

                – Roboticist
                13 hours ago












              • @Roboticist I have updated my answer by adding another layer named middle

                – AndréC
                13 hours ago
















              3














              Like this?



              screenshot



              documentclass[border=10pt]standalone
              usepackage[dvipsnames]xcolor
              usepackagetikz
              usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds
              pgfdeclarelayerbackground
              pgfdeclarelayermiddle
              pgfdeclarelayerforeground
              pgfsetlayersbackground,main,middle,foreground
              tikzstylebackA=[rectangle,
              fill=blue!30,
              inner sep=0.2cm,
              rounded corners=0mm]

              tikzstylebackB=[rectangle,
              fill=purple!15,
              inner sep=0.2cm,
              rounded corners=0mm]

              tikzstylebackC=[rectangle,
              fill=yellow!40,
              %inner sep=0.2cm,
              rounded corners=0mm]

              tikzset%
              >=Latex[width=2mm,length=2mm],
              base/.style = rectangle, rounded corners, draw=black,
              minimum width=1cm, minimum height=1cm,
              text centered,inner sep=0.3cm,
              operation/.style = base, fill=SkyBlue,


              begindocument
              begintikzpicture[node distance=0.8cm,
              every node/.style=fill=white, align=center]
              beginpgfonlayerforeground
              node (controller) [operation] Microcontroller;
              node (regulator) [operation, below = of controller] Regulator;
              node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
              node (sensor) [operation, above = of controller] Sensor;
              node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
              node (driver1) [operation, right = of sensor] Driver 1;
              node (driver2) [operation, left = of sensor] Driver 2;
              node (power) [operation, left = of regulator, align=center] Input \ Power;
              node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
              node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
              node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
              coordinate[left = of power] (d1) ;
              coordinate[above = of d1, yshift=5.5cm] (d2) ;

              draw[->] (controller) -- (transceiver);
              draw[<->] (controller) -- (sensor);
              draw[->] (driver1) -- (motor1);
              draw[->] (driver2) -- (motor2);
              draw[<->] (sensor) -- (motor2);
              draw[<->] (sensor) -- (motor1);
              draw[->] (controller) -- (driver1);
              draw[->] (controller) -- (driver2);
              draw[->] (controller) -- (flash);
              draw[->] (regulator) -- (controller);
              draw[->] (power) -- (regulator);
              draw[<->] (transceiver) -- (computer);
              draw[->] (power) -- (d1) |- (motor2);
              draw[->] (power) -- (d1) -- (d2) -| (motor1);
              endpgfonlayer
              beginpgfonlayermiddle
              node [backC,
              fit=(driver1) (driver2) (sensor) (motor1) (motor2),
              label=above:] ;
              endpgfonlayer
              beginpgfonlayermain
              node [fill=white,inner sep=3mm,
              fit=(driver1) (driver2) (sensor) (motor1) (motor2),
              label=above:] ;
              endpgfonlayer
              beginpgfonlayerbackground
              node [backA,
              fit=(computer) (transceiver),
              label=above:] ;
              endpgfonlayer
              node [backB,
              fit=(regulator) (power),
              label=above:] ;
              endtikzpicture
              enddocument





              share|improve this answer




















              • 1





                How can one insert a little of white margin between the boundaries of the two backgrounds? I mean, the backgrounds are tangent to each other right now.

                – Roboticist
                13 hours ago












              • @Roboticist I have updated my answer by adding another layer named middle

                – AndréC
                13 hours ago














              3












              3








              3







              Like this?



              screenshot



              documentclass[border=10pt]standalone
              usepackage[dvipsnames]xcolor
              usepackagetikz
              usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds
              pgfdeclarelayerbackground
              pgfdeclarelayermiddle
              pgfdeclarelayerforeground
              pgfsetlayersbackground,main,middle,foreground
              tikzstylebackA=[rectangle,
              fill=blue!30,
              inner sep=0.2cm,
              rounded corners=0mm]

              tikzstylebackB=[rectangle,
              fill=purple!15,
              inner sep=0.2cm,
              rounded corners=0mm]

              tikzstylebackC=[rectangle,
              fill=yellow!40,
              %inner sep=0.2cm,
              rounded corners=0mm]

              tikzset%
              >=Latex[width=2mm,length=2mm],
              base/.style = rectangle, rounded corners, draw=black,
              minimum width=1cm, minimum height=1cm,
              text centered,inner sep=0.3cm,
              operation/.style = base, fill=SkyBlue,


              begindocument
              begintikzpicture[node distance=0.8cm,
              every node/.style=fill=white, align=center]
              beginpgfonlayerforeground
              node (controller) [operation] Microcontroller;
              node (regulator) [operation, below = of controller] Regulator;
              node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
              node (sensor) [operation, above = of controller] Sensor;
              node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
              node (driver1) [operation, right = of sensor] Driver 1;
              node (driver2) [operation, left = of sensor] Driver 2;
              node (power) [operation, left = of regulator, align=center] Input \ Power;
              node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
              node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
              node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
              coordinate[left = of power] (d1) ;
              coordinate[above = of d1, yshift=5.5cm] (d2) ;

              draw[->] (controller) -- (transceiver);
              draw[<->] (controller) -- (sensor);
              draw[->] (driver1) -- (motor1);
              draw[->] (driver2) -- (motor2);
              draw[<->] (sensor) -- (motor2);
              draw[<->] (sensor) -- (motor1);
              draw[->] (controller) -- (driver1);
              draw[->] (controller) -- (driver2);
              draw[->] (controller) -- (flash);
              draw[->] (regulator) -- (controller);
              draw[->] (power) -- (regulator);
              draw[<->] (transceiver) -- (computer);
              draw[->] (power) -- (d1) |- (motor2);
              draw[->] (power) -- (d1) -- (d2) -| (motor1);
              endpgfonlayer
              beginpgfonlayermiddle
              node [backC,
              fit=(driver1) (driver2) (sensor) (motor1) (motor2),
              label=above:] ;
              endpgfonlayer
              beginpgfonlayermain
              node [fill=white,inner sep=3mm,
              fit=(driver1) (driver2) (sensor) (motor1) (motor2),
              label=above:] ;
              endpgfonlayer
              beginpgfonlayerbackground
              node [backA,
              fit=(computer) (transceiver),
              label=above:] ;
              endpgfonlayer
              node [backB,
              fit=(regulator) (power),
              label=above:] ;
              endtikzpicture
              enddocument





              share|improve this answer















              Like this?



              screenshot



              documentclass[border=10pt]standalone
              usepackage[dvipsnames]xcolor
              usepackagetikz
              usetikzlibraryarrows.meta,shapes, positioning, fit, backgrounds
              pgfdeclarelayerbackground
              pgfdeclarelayermiddle
              pgfdeclarelayerforeground
              pgfsetlayersbackground,main,middle,foreground
              tikzstylebackA=[rectangle,
              fill=blue!30,
              inner sep=0.2cm,
              rounded corners=0mm]

              tikzstylebackB=[rectangle,
              fill=purple!15,
              inner sep=0.2cm,
              rounded corners=0mm]

              tikzstylebackC=[rectangle,
              fill=yellow!40,
              %inner sep=0.2cm,
              rounded corners=0mm]

              tikzset%
              >=Latex[width=2mm,length=2mm],
              base/.style = rectangle, rounded corners, draw=black,
              minimum width=1cm, minimum height=1cm,
              text centered,inner sep=0.3cm,
              operation/.style = base, fill=SkyBlue,


              begindocument
              begintikzpicture[node distance=0.8cm,
              every node/.style=fill=white, align=center]
              beginpgfonlayerforeground
              node (controller) [operation] Microcontroller;
              node (regulator) [operation, below = of controller] Regulator;
              node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
              node (sensor) [operation, above = of controller] Sensor;
              node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
              node (driver1) [operation, right = of sensor] Driver 1;
              node (driver2) [operation, left = of sensor] Driver 2;
              node (power) [operation, left = of regulator, align=center] Input \ Power;
              node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
              node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
              node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
              coordinate[left = of power] (d1) ;
              coordinate[above = of d1, yshift=5.5cm] (d2) ;

              draw[->] (controller) -- (transceiver);
              draw[<->] (controller) -- (sensor);
              draw[->] (driver1) -- (motor1);
              draw[->] (driver2) -- (motor2);
              draw[<->] (sensor) -- (motor2);
              draw[<->] (sensor) -- (motor1);
              draw[->] (controller) -- (driver1);
              draw[->] (controller) -- (driver2);
              draw[->] (controller) -- (flash);
              draw[->] (regulator) -- (controller);
              draw[->] (power) -- (regulator);
              draw[<->] (transceiver) -- (computer);
              draw[->] (power) -- (d1) |- (motor2);
              draw[->] (power) -- (d1) -- (d2) -| (motor1);
              endpgfonlayer
              beginpgfonlayermiddle
              node [backC,
              fit=(driver1) (driver2) (sensor) (motor1) (motor2),
              label=above:] ;
              endpgfonlayer
              beginpgfonlayermain
              node [fill=white,inner sep=3mm,
              fit=(driver1) (driver2) (sensor) (motor1) (motor2),
              label=above:] ;
              endpgfonlayer
              beginpgfonlayerbackground
              node [backA,
              fit=(computer) (transceiver),
              label=above:] ;
              endpgfonlayer
              node [backB,
              fit=(regulator) (power),
              label=above:] ;
              endtikzpicture
              enddocument






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 13 hours ago

























              answered 13 hours ago









              AndréCAndréC

              1




              1







              • 1





                How can one insert a little of white margin between the boundaries of the two backgrounds? I mean, the backgrounds are tangent to each other right now.

                – Roboticist
                13 hours ago












              • @Roboticist I have updated my answer by adding another layer named middle

                – AndréC
                13 hours ago













              • 1





                How can one insert a little of white margin between the boundaries of the two backgrounds? I mean, the backgrounds are tangent to each other right now.

                – Roboticist
                13 hours ago












              • @Roboticist I have updated my answer by adding another layer named middle

                – AndréC
                13 hours ago








              1




              1





              How can one insert a little of white margin between the boundaries of the two backgrounds? I mean, the backgrounds are tangent to each other right now.

              – Roboticist
              13 hours ago






              How can one insert a little of white margin between the boundaries of the two backgrounds? I mean, the backgrounds are tangent to each other right now.

              – Roboticist
              13 hours ago














              @Roboticist I have updated my answer by adding another layer named middle

              – AndréC
              13 hours ago






              @Roboticist I have updated my answer by adding another layer named middle

              – AndréC
              13 hours ago












              2














              For arbitrary shapes (not nodes), one cannot use fitting.
              demo



              documentclass[border=10pt]standalone
              usepackage[dvipsnames]xcolor
              usepackagetikz
              usetikzlibraryarrows.meta,shapes, positioning, calc, backgrounds

              tikzset%
              >=Latex[width=2mm,length=2mm],
              base/.style = rectangle, rounded corners, draw=black,
              minimum width=1cm, minimum height=1cm,
              text centered,inner sep=0.3cm,
              operation/.style = base, fill=SkyBlue,


              begindocument
              begintikzpicture[node distance=0.8cm,
              every node/.style=fill=white, align=center]
              node (controller) [operation] Microcontroller;
              node (regulator) [operation, below = of controller] Regulator;
              node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
              node (sensor) [operation, above = of controller] Sensor;
              node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
              node (driver1) [operation, right = of sensor] Driver 1;
              node (driver2) [operation, left = of sensor] Driver 2;
              node (power) [operation, left = of regulator, align=center] Input \ Power;
              node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
              node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
              node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
              coordinate[left = of power] (d1) ;
              coordinate[above = of d1, yshift=5.5cm] (d2) ;

              draw[->] (controller) -- (transceiver);
              draw[<->] (controller) -- (sensor);
              draw[->] (driver1) -- (motor1);
              draw[->] (driver2) -- (motor2);
              draw[<->] (sensor) -- (motor2);
              draw[<->] (sensor) -- (motor1);
              draw[->] (controller) -- (driver1);
              draw[->] (controller) -- (driver2);
              draw[->] (controller) -- (flash);
              draw[->] (regulator) -- (controller);
              draw[->] (power) -- (regulator);
              draw[<->] (transceiver) -- (computer);
              draw[->] (power) -- (d1) |- (motor2);
              draw[->] (power) -- (d1) -- (d2) -| (motor1);

              beginpgfonlayerbackground
              path (driver1.east |- computer.north) ++ (0.2,0.2) coordinate(int1);
              path (driver2.south -| transceiver.west) ++ (-0.2,-0.2) coordinate(int2);

              fill[yellow!40] ($(driver2.south west)+(-0.2,-0.2)$) |- ($(motor2.north)+(0,0.2)$) -| (int1) -- (int2) -- cycle;
              fill[blue!30] ($(transceiver.south west)+(-0.2,-0.2)$) -- (int2) -- (int1) --
              ($(computer.north)+(0,0.2)$) -| ($(computer.east)+(0.2,0)$) |- cycle;
              fill[purple!15] ($(power.south west)+(-0.2,-0.2)$) |- ($(power.north)+(0,0.2)$) -| ($(regulator.east)+(0.2,0.2)$) |- cycle;
              endpgfonlayer
              endtikzpicture
              enddocument





              share|improve this answer



























                2














                For arbitrary shapes (not nodes), one cannot use fitting.
                demo



                documentclass[border=10pt]standalone
                usepackage[dvipsnames]xcolor
                usepackagetikz
                usetikzlibraryarrows.meta,shapes, positioning, calc, backgrounds

                tikzset%
                >=Latex[width=2mm,length=2mm],
                base/.style = rectangle, rounded corners, draw=black,
                minimum width=1cm, minimum height=1cm,
                text centered,inner sep=0.3cm,
                operation/.style = base, fill=SkyBlue,


                begindocument
                begintikzpicture[node distance=0.8cm,
                every node/.style=fill=white, align=center]
                node (controller) [operation] Microcontroller;
                node (regulator) [operation, below = of controller] Regulator;
                node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
                node (sensor) [operation, above = of controller] Sensor;
                node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
                node (driver1) [operation, right = of sensor] Driver 1;
                node (driver2) [operation, left = of sensor] Driver 2;
                node (power) [operation, left = of regulator, align=center] Input \ Power;
                node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
                node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
                node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
                coordinate[left = of power] (d1) ;
                coordinate[above = of d1, yshift=5.5cm] (d2) ;

                draw[->] (controller) -- (transceiver);
                draw[<->] (controller) -- (sensor);
                draw[->] (driver1) -- (motor1);
                draw[->] (driver2) -- (motor2);
                draw[<->] (sensor) -- (motor2);
                draw[<->] (sensor) -- (motor1);
                draw[->] (controller) -- (driver1);
                draw[->] (controller) -- (driver2);
                draw[->] (controller) -- (flash);
                draw[->] (regulator) -- (controller);
                draw[->] (power) -- (regulator);
                draw[<->] (transceiver) -- (computer);
                draw[->] (power) -- (d1) |- (motor2);
                draw[->] (power) -- (d1) -- (d2) -| (motor1);

                beginpgfonlayerbackground
                path (driver1.east |- computer.north) ++ (0.2,0.2) coordinate(int1);
                path (driver2.south -| transceiver.west) ++ (-0.2,-0.2) coordinate(int2);

                fill[yellow!40] ($(driver2.south west)+(-0.2,-0.2)$) |- ($(motor2.north)+(0,0.2)$) -| (int1) -- (int2) -- cycle;
                fill[blue!30] ($(transceiver.south west)+(-0.2,-0.2)$) -- (int2) -- (int1) --
                ($(computer.north)+(0,0.2)$) -| ($(computer.east)+(0.2,0)$) |- cycle;
                fill[purple!15] ($(power.south west)+(-0.2,-0.2)$) |- ($(power.north)+(0,0.2)$) -| ($(regulator.east)+(0.2,0.2)$) |- cycle;
                endpgfonlayer
                endtikzpicture
                enddocument





                share|improve this answer

























                  2












                  2








                  2







                  For arbitrary shapes (not nodes), one cannot use fitting.
                  demo



                  documentclass[border=10pt]standalone
                  usepackage[dvipsnames]xcolor
                  usepackagetikz
                  usetikzlibraryarrows.meta,shapes, positioning, calc, backgrounds

                  tikzset%
                  >=Latex[width=2mm,length=2mm],
                  base/.style = rectangle, rounded corners, draw=black,
                  minimum width=1cm, minimum height=1cm,
                  text centered,inner sep=0.3cm,
                  operation/.style = base, fill=SkyBlue,


                  begindocument
                  begintikzpicture[node distance=0.8cm,
                  every node/.style=fill=white, align=center]
                  node (controller) [operation] Microcontroller;
                  node (regulator) [operation, below = of controller] Regulator;
                  node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
                  node (sensor) [operation, above = of controller] Sensor;
                  node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
                  node (driver1) [operation, right = of sensor] Driver 1;
                  node (driver2) [operation, left = of sensor] Driver 2;
                  node (power) [operation, left = of regulator, align=center] Input \ Power;
                  node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
                  node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
                  node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
                  coordinate[left = of power] (d1) ;
                  coordinate[above = of d1, yshift=5.5cm] (d2) ;

                  draw[->] (controller) -- (transceiver);
                  draw[<->] (controller) -- (sensor);
                  draw[->] (driver1) -- (motor1);
                  draw[->] (driver2) -- (motor2);
                  draw[<->] (sensor) -- (motor2);
                  draw[<->] (sensor) -- (motor1);
                  draw[->] (controller) -- (driver1);
                  draw[->] (controller) -- (driver2);
                  draw[->] (controller) -- (flash);
                  draw[->] (regulator) -- (controller);
                  draw[->] (power) -- (regulator);
                  draw[<->] (transceiver) -- (computer);
                  draw[->] (power) -- (d1) |- (motor2);
                  draw[->] (power) -- (d1) -- (d2) -| (motor1);

                  beginpgfonlayerbackground
                  path (driver1.east |- computer.north) ++ (0.2,0.2) coordinate(int1);
                  path (driver2.south -| transceiver.west) ++ (-0.2,-0.2) coordinate(int2);

                  fill[yellow!40] ($(driver2.south west)+(-0.2,-0.2)$) |- ($(motor2.north)+(0,0.2)$) -| (int1) -- (int2) -- cycle;
                  fill[blue!30] ($(transceiver.south west)+(-0.2,-0.2)$) -- (int2) -- (int1) --
                  ($(computer.north)+(0,0.2)$) -| ($(computer.east)+(0.2,0)$) |- cycle;
                  fill[purple!15] ($(power.south west)+(-0.2,-0.2)$) |- ($(power.north)+(0,0.2)$) -| ($(regulator.east)+(0.2,0.2)$) |- cycle;
                  endpgfonlayer
                  endtikzpicture
                  enddocument





                  share|improve this answer













                  For arbitrary shapes (not nodes), one cannot use fitting.
                  demo



                  documentclass[border=10pt]standalone
                  usepackage[dvipsnames]xcolor
                  usepackagetikz
                  usetikzlibraryarrows.meta,shapes, positioning, calc, backgrounds

                  tikzset%
                  >=Latex[width=2mm,length=2mm],
                  base/.style = rectangle, rounded corners, draw=black,
                  minimum width=1cm, minimum height=1cm,
                  text centered,inner sep=0.3cm,
                  operation/.style = base, fill=SkyBlue,


                  begindocument
                  begintikzpicture[node distance=0.8cm,
                  every node/.style=fill=white, align=center]
                  node (controller) [operation] Microcontroller;
                  node (regulator) [operation, below = of controller] Regulator;
                  node (transceiver) [operation, right = of controller, align = center] CAN \ Transceiver;
                  node (sensor) [operation, above = of controller] Sensor;
                  node (flash) [operation, below = of transceiver, yshift=4mm] Flash \ Memeory;
                  node (driver1) [operation, right = of sensor] Driver 1;
                  node (driver2) [operation, left = of sensor] Driver 2;
                  node (power) [operation, left = of regulator, align=center] Input \ Power;
                  node (motor1) [operation, above = of sensor, align=center, xshift=1cm] Motor 1;
                  node (motor2) [operation, above = of sensor, align=center, xshift=-1cm] Motor 2;
                  node[circle,draw,fill=SkyBlue] (computer) [right = of driver1] Computer;
                  coordinate[left = of power] (d1) ;
                  coordinate[above = of d1, yshift=5.5cm] (d2) ;

                  draw[->] (controller) -- (transceiver);
                  draw[<->] (controller) -- (sensor);
                  draw[->] (driver1) -- (motor1);
                  draw[->] (driver2) -- (motor2);
                  draw[<->] (sensor) -- (motor2);
                  draw[<->] (sensor) -- (motor1);
                  draw[->] (controller) -- (driver1);
                  draw[->] (controller) -- (driver2);
                  draw[->] (controller) -- (flash);
                  draw[->] (regulator) -- (controller);
                  draw[->] (power) -- (regulator);
                  draw[<->] (transceiver) -- (computer);
                  draw[->] (power) -- (d1) |- (motor2);
                  draw[->] (power) -- (d1) -- (d2) -| (motor1);

                  beginpgfonlayerbackground
                  path (driver1.east |- computer.north) ++ (0.2,0.2) coordinate(int1);
                  path (driver2.south -| transceiver.west) ++ (-0.2,-0.2) coordinate(int2);

                  fill[yellow!40] ($(driver2.south west)+(-0.2,-0.2)$) |- ($(motor2.north)+(0,0.2)$) -| (int1) -- (int2) -- cycle;
                  fill[blue!30] ($(transceiver.south west)+(-0.2,-0.2)$) -- (int2) -- (int1) --
                  ($(computer.north)+(0,0.2)$) -| ($(computer.east)+(0.2,0)$) |- cycle;
                  fill[purple!15] ($(power.south west)+(-0.2,-0.2)$) |- ($(power.north)+(0,0.2)$) -| ($(regulator.east)+(0.2,0.2)$) |- cycle;
                  endpgfonlayer
                  endtikzpicture
                  enddocument






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 12 hours ago









                  John KormyloJohn Kormylo

                  45.2k12570




                  45.2k12570



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f479108%2fhow-to-clip-a-background-including-nodes-according-to-an-arbitrary-shape%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

                      Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                      How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2