Skip to content

Instantly share code, notes, and snippets.

@sampollard
Last active October 7, 2020 05:57
Show Gist options
  • Save sampollard/ac45743a5f0d7014d32e5d2d61efe665 to your computer and use it in GitHub Desktop.
Save sampollard/ac45743a5f0d7014d32e5d2d61efe665 to your computer and use it in GitHub Desktop.
Highlight a part of a bounding box in Tikz. Use with \negativebox{x1,y1}{x2,y2} inside tikzpicture
\newcommand\negativebox[2]{%
\def\opc{0.75}
\def\opcol{white}
% Left
\fill[opacity=\opc, color=\opcol]
let
\p{sw} = (current bounding box.south west),
\p{nw} = (current bounding box.north west),
\p1 = (#1)
in (\p{sw}) rectangle (\x1, \y{nw});%
% Above
\fill[opacity=\opc, color=\opcol]
let
\p{sw} = (current bounding box.south west),
\p{ne} = (current bounding box.north east),
\p1 = (#1),
\p2 = (#2)
in (\x1, \y2) rectangle (\x2, \y{ne});
% Right
\fill[opacity=\opc, color=\opcol]
let
\p{se} = (current bounding box.south east),
\p{ne} = (current bounding box.north east),
\p2 = (#2)
in (\x2, \y{se}) rectangle (\p{ne});
% Below
\fill[opacity=\opc, color=\opcol]
let
\p{sw} = (current bounding box.south west),
\p{nw} = (current bounding box.north west),
\p1 = (#1),
\p2 = (#2)
in (\x1, \y{sw}) rectangle (\x2, \y1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment