EDIT: I'd like to set the yshift of a node to be some factor of the number of lines in the node's contents. In trying to determine the number of lines, I originally wrote the question below.
EDIT A partial solution, based on the answer of Schrödinger's cat, is below with figure and code. It is not fully automated, specifying boxes and the use of \pgftruncatemacro before each node is not desirable.
\documentclass[margin=6]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\begin{document}
\newbox\mybox\setbox\mybox=\vbox{\hbox{foo}\hbox{bar}\hbox{bazzy}}
\newbox\myboxb\setbox\myboxb=\vbox{\hbox{\ttfamily abc\#xyz}}
\begin{tikzpicture}[
card/.style={
draw,
dashed,
anchor=base west,
inner sep=0,
append after command={[/utils/exec=\let\mytikzlastnode\tikzlastnode]
node [
below=5mm of \tikzlastnode.base east,
anchor=base east,
font=\scriptsize,
inner sep=0
] (mynode) {#1}
node [draw,fit={(\mytikzlastnode) (mynode.base east)}] {}
},
}
]
\draw (-1,0) -- (5,0);
\pgfmathtruncatemacro{\myn}{(\dp\mybox+\ht\mybox+2pt)/11.5pt}\myn
\node [card=num1,yshift=-(\myn-1)*\baselineskip] (A) {\box\mybox};
\pgfmathtruncatemacro{\myn}{(\dp\myboxb+\ht\myboxb+2pt)/11.5pt}\myn
\node [card=c2,right=1cm of A,yshift=-(\myn-1)*\baselineskip] (B) {\box\myboxb};
\end{tikzpicture}
\end{document}
Original question: I'd like to attach the number of lines in a node's contents as an "auxiliary" node, MWE below.
I have a candidate solution to count the number of lines of something from this answer, but I cannot parse the code well enough to untangle that solution from \title. I have not been able to find a way to access the node contents from the style.
\documentclass[margin=6]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\begin{document}
\begin{tikzpicture}[
card/.style={
draw,
dashed,
inner sep=0,
append after command={
\pgfextra{
\node [
below=5mm of \tikzlastnode.base east,
anchor=base east,
font=\scriptsize,
inner sep=0
] (mynode) {????}; % get node contents and count lines
\node [draw,fit={(\tikzlastnode) (mynode.base east)}] {};
}
}
}
]
\node [card] (C) {foobar\\baz};
\end{tikzpicture}
\end{document}


cardobjects by the baseline of the first line of text, so what I was thinking was to anchor a new object atbase(baseline of the last line), compute the number of lines less 1, multiply times\baselineskip, then set the result as theyshiftin the node style. I'm still learning aboutappend after...,execute after...etc. Is it possible to do the calculation you provided, but set the result asyshiftof the initial node? – tsj Nov 04 '19 at 14:49