I am attempting a simple format, that works well until I use a line width keyword in the \draw
command below. The keyword could be thick
or thin
or line width=2pt
. Running the code with thick
gives this:
and TikZ says, for example: No shape named S-3 is known.
Commenting-out thick
produces the expected graphic, sort of:
Yes, I know I could have used |-
for the drawing, but for simplicity and to maximize M of MWE I chose something more direct.
\documentclass{article}
\usepackage[]{geometry}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{positioning}
%% |=====8><----| %%
\newcounter{stepnum}
\newlength{\myxincr}
\newlength{\myyincr}
%% |=====8><-----| %%
\NewDocumentEnvironment{test}{m}{%
\begin{tikzpicture}
\coordinate (A) at (0,0);
\setlength{\myxincr}{\dimexpr0.5in/#1\relax}
\setlength{\myyincr}{\dimexpr-5in/#1\relax}
\pgfmathsetmacro{\incr}{1/#1}
\pgfmathparse{#1-1}
\draw[
%% Uncomment the next line and this fails -- any line width keyword causes failure
% thick, %% <<<---
red %% color is ok, seemingly
] (A) foreach \ss in {1,...,\pgfmathresult}
{ -- node[fill=white,name=S-\ss]{\ss} ++(0,\myyincr) -- ++(\myxincr,0)}
--node[fill=white,name=S-#1]{#1} ++(0,\myyincr) -- ++(\myxincr,0);
}{%
\end{tikzpicture}
}
\NewDocumentCommand{\foo}{+m}{%
\stepcounter{stepnum}
\node[right=6pt of S-\thestepnum] {%
#1
};%
}
\parindent=0pt
\begin{document}
\begin{test}{4}
\foo{First}
\foo{Second}
\foo{Third}
\foo{Fourth}
\end{test}
\end{document}
thick
does math calculations and overwrites\pgfmathresult
which should be saved somewhere else right after having done the calculation...\pgfmathparse...\pgfmathresult
in this way. Thank you.