0

In the mwe below, I try to have different name inside a pgfplotsinvokeforeach loop. I don't understand why the name is the same with the last value

\documentclass{article}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{pgfplots}


\begin{document}

\begin{tikzpicture}[scale=1]
\begin{axis}[height=8cm,width=12cm, 
            axis y line=middle,
            axis x line=middle,
            x label style={anchor=west},
            y label style={anchor=south},           
            xlabel=$t$,ylabel=$e(t)$,
            xmin=0,xmax=6,ymin=-1,ymax=6,
            xtick={1,2,3,4,5},
            xticklabels = {$\tau$,$2\tau$,$3\tau$,$4\tau$,$5\tau$},
            ytick={5},
            yticklabels = {$E$},
            clip mode=individual
        ]
\addplot[domain=0:6, samples=30,red]{5};    
\addplot[domain=0:6, samples=100,blue]{5*(1-e^(-x))};   

\pgfplotsinvokeforeach{1,2,...,5}{
    \pgfmathtruncatemacro\Adv{(1-e^(-#1))*100}%
    \draw [<->] (axis cs:#1,0) -- (axis cs:#1,{5*(1-e^(-#1))})node [midway, right] {$\Adv\%$};
}
\end{axis}
\end{tikzpicture}   

\end{document}

enter image description here.

Fabien
  • 93
  • 1
    Welcome to TeX.SE. Thus is a classic with pgfplots. You can use \edef\tmp{\noexpand\draw [<->] (axis cs:#1,0) -- (axis cs:#1,{5*(1-e^(-#1))})node [midway, right] {$\Adv\%$};} \tmp to replace the end of your \pgfplotsinvokeforeach loop. See for instance here and here. – frougon Apr 27 '20 at 22:28
  • 1
    ... and see p. 545 of the pgfplots manual v1.17 for more explanations. –  Apr 27 '20 at 22:33

0 Answers0