2

I am reading this question and try to modify it as below:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,positioning,fit,calc}  
\makeatletter
\pgfdeclareshape{cross}{
    \inheritsavedanchors[from=circle]
    \inheritanchorborder[from=circle]
    \inheritbackgroundpath[from=circle]
    \foreach \i in {center,north,south,east,west} {
        \inheritanchor[from=circle]{\i}
    }
    \backgroundpath{
        \pgfpathcircle{\pgfpointorigin}{\radius}%
    }
    \foregroundpath{
        \pgfpathmoveto{\pgfpointpolar{-135}{\radius}}%
        \pgfpathlineto{\pgfpointpolar{45}{\radius}}%
        \pgfpathmoveto{\pgfpointpolar{135}{\radius}}%
        \pgfpathlineto{\pgfpointpolar{-45}{\radius}}%
        \pgfusepath{draw}
    }
}
\makeatother
\tikzset{
    pics/PINH/.style n args={1}{
        code = {
            \message{PINH params: #1}
            \foreach \s [count=\i] in {#1} {
                \message{count: \i,\s}
                \node[draw,cross,minimum size=0.5cm,label={above:\s},xshift={\i*0.6cm}] (-\i) {};
            }
            \node[fit=(-1)(-\i),draw] () {};
}}}
\tikzset{
    pics/PINV/.style n args={2}{
        code = {
            \message{PINV params: #1,#2}
            \foreach \s [count=\i] in {#2} {
                \node[draw,cross,minimum size=0.5cm,label={left:\s},yshift={-\i*0.6cm}] (-\i) {};
            }
            \node[fit=(-1)(-\i),draw] () {};
}}}
\begin{document}
    \begin{tikzpicture}
    \pic (A) {PINH={A,B,C,D}};
    \message{test here:}
    \pic (B) [below=1em of A.south west] {PINV={}{E,F,G,H}};
    \end{tikzpicture}
\end{document}

You can see, PINH and PINV actually only use 1 argument, but PINH only parsed the first letter A and PINV parsed all letters E,F,G,H.

That means the first argument actually handled differently in pics. Maybe my understand is wrong!

enter image description here

2

AFAIK n args={1} is not officially supported, and indeed, if you leave it out, you get

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,positioning,fit,calc}  
\makeatletter
\pgfdeclareshape{cross}{
    \inheritsavedanchors[from=circle]
    \inheritanchorborder[from=circle]
    \inheritbackgroundpath[from=circle]
    \foreach \i in {center,north,south,east,west} {
        \inheritanchor[from=circle]{\i}
    }
    \backgroundpath{
        \pgfpathcircle{\pgfpointorigin}{\radius}%
    }
    \foregroundpath{
        \pgfpathmoveto{\pgfpointpolar{-135}{\radius}}%
        \pgfpathlineto{\pgfpointpolar{45}{\radius}}%
        \pgfpathmoveto{\pgfpointpolar{135}{\radius}}%
        \pgfpathlineto{\pgfpointpolar{-45}{\radius}}%
        \pgfusepath{draw}
    }
}
\makeatother
\tikzset{
    pics/PINH/.style={
        code = {
            \message{PINH params: #1}
            \foreach \s [count=\i] in {#1} {
                \message{count: \i,\s}
                \node[draw,cross,minimum size=0.5cm,label={above:\s},xshift={\i*0.6cm}] (-\i) {};
            }
            \node[fit=(-1)(-\i),draw] () {};
}}}
\tikzset{
    pics/PINV/.style n args={2}{
        code = {
            \message{PINV params: #1,#2}
            \foreach \s [count=\i] in {#2} {
                \node[draw,cross,minimum size=0.5cm,label={left:\s},yshift={-\i*0.6cm}] (-\i) {};
            }
            \node[fit=(-1)(-\i),draw] () {};
}}}
\begin{document}
    \begin{tikzpicture}
    \pic (A) {PINH={A,B,C,D}};
    \message{test here:}
    \pic (B) [below=1em of A.south west] {PINV={}{E,F,G,H}};
    \end{tikzpicture}
\end{document}

enter image description here

1
  • 1
    I just modify original code so just try down counter to 1. I really don't know 1 actually is special! :-) Thanks!
    – beetlej
    Nov 29 '18 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.