This is a follow up question to Create array of specific counter values and Using self-defined fields in NewEnviron.
I want to use the function mtadd that fills the array mtarr depending on the value of lines, inside of the environement myenv that creates the line between the columns. To do so, I have to include the body definded outside. But this produces the error ! Misplaced alignment tab character &., apparently related to the redefinition of & starting at line 10, which I don't entirely understand (taken from Claudio Fiandrino in How can you create a vertical timeline?).
Commenting out \BODY leads to the correct line, but the function mtadddoesn't work and thus myarr stays empty.
Here is the code:
\documentclass{article}
\usepackage{pgfmath,pgffor}
\usepackage{environ}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage{charter}
\makeatletter
\let\matamp=&
\catcode`\&=13
\makeatletter
\def&{\iftikz@is@matrix
\pgfmatrixnextcell
\else
\matamp
\fi}
\makeatother
\newcounter{lines}
\def\endlr{\stepcounter{lines}\\}
\newcounter{envcount}
\setcounter{envcount}{0}
\newcommand*\myarr{}
\newcommand{\mtadd}{
\ifx\myarr\empty
\edef\myarr{\arabic{lines}}
\else\edef\myarr{\myarr,\arabic{lines}}
\fi}
\tikzset{description/.style={
column 2/.append style={#1}
},
line color/.store in=\lcolor,
line color=white!80!black,
line color st/.style={fill=\lcolor,draw=\lcolor},
}
\NewEnviron{myenv}[1][]{%
\def\myarr{}
\setcounter{lines}{1}
\stepcounter{envcount}%
\BODY
\begin{tikzpicture}[column 1/.style={anchor=east},
column 2/.style={anchor=west},
#1
]
\matrix(myenv\theenvcount)[matrix of nodes]{\BODY};
\pgfmathtruncatemacro\endmtx{\thelines-1}
\path [line color st]
($(myenv\theenvcount-1-1.north east)!0.5!(myenv\theenvcount-1-2.north west)$)--
($(myenv\theenvcount-\endmtx-1.south east)!0.5!(myenv\theenvcount-\endmtx-2.south west)$);
\end{tikzpicture}
}
\def\names{{"Katie","Frank","Laura","Joe","Peter","Jens","Carolin","Anna","Steph","Stef"}}
\begin{document}
\begin{myenv}
test & now\mtadd\endlr
test & \foreach \i in \myarr {%
Name \i: \pgfmathparse{\names[\i]}\pgfmathresult, }\endlr
\end{myenv}
\end{document}
\BODYin the figure or above, just if I place it before the definitions of the counters, they don't apply. Sorry, if I don't understand entirely what you mean. I'm completely new to laTex coding. – PeMa Feb 15 '16 at 16:32\mtaddto fill the array\myarronly with specific line numbers of my choice. The array\myarris supposed to be used in the figure to create a set of points. What's behind, is a generalization of the timeline in the post of Claudio Fiandrino in http://tex.stackexchange.com/questions/196794/how-can-you-create-a-vertical-timeline. I want to have different spacings between the entries of one timeline, sometimes 3 lines, somtimes 1 ... . – PeMa Feb 15 '16 at 22:15\mtaddto work inside the environment. – PeMa Feb 18 '16 at 10:14