I want to combine two of my posts to get a running example for my electrical installation plan in TikZ.
In this post, I got the answer how to create a alphanumerical string with fixed length.
In this post, I got the answer how to derive a dynamic table and a TikZ input just from one single data list.
Now I want to combine both topics and bring the generated alphanumerical string into my single data list. From there, the \hash within the dynamic table should be the same hash value than used as my TikZ label.
MWE
\documentclass{article}
\usepackage[a4paper, margin=10mm]{geometry}
\usepackage{pgfplotstable}
\usepackage{mwe}
\pgfplotsset{compat=newest}
\ExplSyntaxOn
\sys_gset_rand_seed:n {0}
\NewExpandableDocumentCommand{\hash}{}
{
__new_hash_three:e { \int_to_Base:nn { \int_rand:n { 46655 } } { 36 } } % three digits
}
\cs_new:Nn __new_hash_three:n
{
\prg_replicate:nn { 3 - \tl_count:n { #1 } } { 0 } #1
}
\cs_generate_variant:Nn __new_hash_three:n { e }
\ExplSyntaxOff
\begin{filecontents}{data.csv}
id, name, x-coord, y-coord, rotation
\hash, PowerSupply1, 3590, 2000, 270 %The \hash function seems to be called twice
\hash, PowerSupply2, 5590, 2500, 270
\end{filecontents}
\pgfplotstableread[col sep=comma]{data.csv}{\csvdata}
\pgfplotstablegetrowsof{\csvdata}
\pgfmathtruncatemacro\CSVDataRows{\pgfplotsretval-1}
\tikzset{
pics/PowerSupply/.style={
code={
\tikzset{PowerSupply/.cd, #1}
\node[anchor=north, inner sep=0pt] (-p)
{\includegraphics[scale=0.09]{example-image-a}};
\node[
inner sep=0pt,
anchor={90+\pgfkeysvalueof{/tikz/PowerSupply/label position}},
rotate={-1*\pgfkeysvalueof{/tikz/PowerSupply/label position}}
] at (-p.south) {\tiny \pgfkeysvalueof{/tikz/PowerSupply/label}};
}
},
PowerSupply/label/.initial={},
PowerSupply/label position/.initial={0}
}
\begin{document}
\begin{center}
\pgfplotstabletypeset[
col sep=comma,
columns={id, name, x-coord, y-coord},
columns/id/.style={
column name=ID,
string type
},
columns/name/.style={
column name=Description,
string type
},
columns/x-coord/.style={
column name=X-Pos
},
columns/y-coord/.style={
column name=Y-Pos,
column type/.add={}{|}
},
column type/.add={|}{},
after row={\hline},
every head row/.style={before row=\hline},
]{data.csv}
\end{center}
\begin{figure}[h!]
\centering
\begin{tikzpicture}[x=0.01mm, y=-0.01mm]
\node[inner sep=0pt] (ground_floor)
{\includegraphics[width=99.0mm, height=107.4mm]{example-image}};
\begin{scope}[shift=(ground_floor.north west)]
\foreach \row in {0,...,\CSVDataRows} {
\pgfplotstablegetelem{\row}{x-coord}\of{\csvdata}
\pgfmathsetmacro{\x}{\pgfplotsretval}
\pgfplotstablegetelem{\row}{y-coord}\of{\csvdata}
\pgfmathsetmacro{\y}{\pgfplotsretval}
\pgfplotstablegetelem{\row}{rotation}\of{\csvdata}
\pgfmathsetmacro{\r}{\pgfplotsretval}
\pgfplotstablegetelem{\row}{id}\of{\csvdata}
\pgfmathsetmacro{\i}{"\pgfplotsretval"}
\pic[rotate=\r, transform shape] at (\x,\y) {
PowerSupply={
label={\i}, % This label is different to the label in the table
label position={\r}
}
};
}
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}
PROBLEM
As you can see, the "shared" \hash from filecontents data list is different between the table representation and within the TikZ label. My assumption is, that the \hash function is called twice...


\hash" in the CSV and not the generated hashes. So, when the file is read (which happens indeed twice), TeX reads\hashand finally expands this. You can look into the file and you will not see any hashes in there. What you want to do is to generate hashes and store these in your CSV in the first place. – Jasper Habicht Feb 19 '24 at 10:30pgfplotstableyou don't necessarily need to use a CSV. You can also just put the data inline. Search for\pgfplotstablereadin the documentation of the package to get some examples for different ways to read in data. – Jasper Habicht Feb 19 '24 at 18:35pgfplotstablethat often and you stitch together a lot of interesting things! So it is nice to follow your thoughts and come up with solutions =) – Jasper Habicht Feb 19 '24 at 19:22