Last active
October 7, 2020 05:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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