Back in the day (2014), I've had some code posted in Drawing a styled node invisibly (phantom / off-screen)?, which is reposted below. Then it apparently compiled; with my current texlive 2014 (updated a month ago, maybe), now it fails with:
! Package pgf Error: Sorry, the requested layer 'invisible' is not part of the
layer list. Please verify that you provided \pgfsetlayers and that 'invisible'
is part of this list.
See the pgf package documentation for explanation.
So my guess (then), that:
just declare a pgf layer, but don't set it - and it will keep everything you draw on it invisible;
... is not valid anymore - as now it obviously raises an error.
So is it somehow possible to have an invisible layer in tikz with the current API?
The code:
\documentclass[varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\pagecolor{yellow!15}
% just declare the layer, and don't do
% \pgfsetlayers ; then it will be invisible:
\pgfdeclarelayer{invisible}
\begin{document}
\begin{tikzpicture}
\makeatletter
\pgfdeclareshape{testshape}{ %
\inheritsavedanchors[from={rectangle}] %
\inheritbackgroundpath[from={rectangle}] %
\inheritanchorborder[from={rectangle}] %
\foreach \x in {center,north,north east,north west,south,south east,south west,east,west}{ %
\inheritanchor[from={rectangle}]{\x} %
} %
%\backgroundpath{} %
\foregroundpath{ %
\draw[] (\tikz@fig@name.south west) -- (\tikz@fig@name.north east)
(\tikz@fig@name.north west) -- (\tikz@fig@name.south east);
}
}
\makeatother
\tikzstyle{mynode} = [testshape,draw=gray,line width=2pt,inner sep=2pt, outer sep=5pt, minimum width=2cm,minimum height=0pt,align=center]
\node[mynode] (Starter) {Testing the node\\(a bit)};
\node[mynode] (Ender) [right=2cm of Starter] {Also test\\(even more)};
\begin{pgfonlayer}{invisible}
\node[mynode] (tester) [at=(current bounding box.center)] {Trying to measure this one};
\end{pgfonlayer}
\path let \p1=(tester.north east), \p2=(tester.south west)
in coordinate (testerSize) at (\x1-\x2,\y1-\y2);
% \pgfpointanchor{testerSize}{center} % "returns"/sets a (last) pgfpoint
\path(testerSize.center); % a bit easier than \pgfpointanchor: https://tex.stackexchange.com/a/33706/2595
\pgfgetlastxy{\testerWidth}{\testerHeight} % ... and globalize:
\global\let\testerWidth\testerWidth
\global\let\testerHeight\testerHeight
\typeout{tester size is: \testerWidth\space X \testerHeight}
\end{tikzpicture}
tester size is: \testerWidth\ X \testerHeight
\end{document}

\elsestatement on line 17 under the\ifstatement on the above line. Then for sanity's sake simply replace all appearances of the wordinvisiblewithvisible. – NauticalMile Sep 03 '16 at 18:32