This PGFkeys supported solution supports both lists in the form of
{{Header 1, Content 1}, {Header 2, Content 2}, {…}, …}
as well as
{Header 1, Content 1, Header 2, Content 2, …
The latter is the default list use = all comma
, the former can be used with list use = tuples
.
For placing the green nodes, I'm using the chains
library's
on chain = <chain name> placed {at = (<calculation>)}
where (<calculation>)
simply is
(\tikzchaincount*20: \tikzchaincount*3cm)
i.e. the same as yours but \i
replaced by \tikzchaincount
.
Code
\documentclass[tikz]{standalone}
\usetikzlibrary{chains}
\makeatletter
\tikzset{
/utils/if not empty/.code 2 args={%
\if\relax\detokenize{#1}\relax\expandafter\pgfutil@gobble
\else\expandafter\pgfutil@firstofone\fi
{\pgfkeysalso{#2}}}}
\makeatother
\tikzset{
% defaults
topic style/.style={shape=circle, minimum size=3cm, fill=cyan},
list style/.style={fill=green, text width=2cm, circle, align=center},
topic/.initial=Topic,
list/.initial={Header 1, Contents 1,
Header 2, Contents 2,
Header 3, Contents 3,
Header 4, Contents 4,
Header 5, Contents 5,
Header 6, Contents 6},
% mantaining the lists/settings
reset list/.style={list=},
add to list/.style={list/.append={,#1}},
list use/.is choice,
list use/all comma/.style={use list/.style={% H1, C1, H2, C2, …
list parser/.expand twice/.expand once={\pgfkeysvalueof{/tikz/list},}}},
list use/tuples/.style={use list/.style={% {H1, C1}, {H2, C2}, …
placer/.list/.expand twice/.expand once=\pgfkeysvalueof{/tikz/list}}},
list use=all comma,% default: all comma
% actual placing
list parser/.style args={#1,#2,#3}{ % parsing H1, C1, H2, C2, …
placer={{#1},{#2}},
/utils/if not empty={#3}{list parser={#3}}},
tuples parser/.style args={#1,#2}{placer={{#1},{#2}}},% parsing {H1, C1}, {H2, C2}, …
placer/.code args={#1,#2}{%
\node [list style, on chain] {\textbf{#1}\\#2} edge (center);}}
\newcommand*\myTikz[1][]{%
\begin{tikzpicture}[#1,
start chain=headers placed {at=(\tikzchaincount*20:\tikzchaincount*3cm)}]
\node (center) [topic style] at (135:10cm) {\pgfkeysvalueof{/tikz/topic}};
\tikzset{use list}
\end{tikzpicture}}
\begin{document}
\myTikz
\myTikz[add to list={Header X, Content X, Header Y, Content Y}]
\myTikz[topic=\TeX, list={TikZ, extends PGF, \LaTeX, extends \TeX}]
\tikzset{
list use=tuples,
list={{Header 1, Contents 1},
{Header 2, Contents 2},
{Header 3, Contents 3},
{Header 4, Contents 4},
{Header 5, Contents 5},
{Header 6, Contents 6}}}
\myTikz
\myTikz[add to list={{Header X, Content X}, {Header Y, Content Y}}]
\myTikz[topic=\TeX, list={{TikZ, extends PGF}, {\LaTeX, extends \TeX}}]
\end{document}
clist
s and push the data in there, then retrieve it inside the\foreach
loop? Something like this?