| Kann man dieses Beispiel so umgestalten, dass auch die Laufvariable  Etwa 
 funktioniert nicht. Oder geht das nur mit größeren Maßnahmen wie z.B. etoolbox? Öffne in Overleaf \documentclass[margin=2mm]{standalone} \usepackage{tikz} \newcommand{\test}[1]{% \def\temp{}% \foreach \i in {1,...,#1} {% \expandafter\gdef\expandafter\temp\expandafter{\temp t\i \\}% }% \temp} \begin{document} IST: \begin{tabular}{c} \test{3} \end{tabular} SOLL: \begin{tabular}{c} t1 \\ t2 \\ t3 \\ \end{tabular} \end{document} | 
| Während Murmeltier's Antwort bereits eine pragmatische Lösung zeigt, sei im folgenden noch ein wenig erklärt, was die Problematik ist und wie man diese möglichst allgemein lösen kann. Das Problem mit dem gezeigten Code ist, dass zwar die Definition von  Öffne in Overleaf \documentclass[margin=2mm]{standalone} \usepackage{tikz} \newcommand{\test}[1]{% \def\temp{}% \foreach \i in {1,...,#1} {% \expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\temp\expandafter\expandafter\expandafter{\expandafter\temp \expandafter t\i \\}% }% \temp} \begin{document} IST: \begin{tabular}{c} \test{3} \end{tabular} SOLL: \begin{tabular}{c} t1 \\ t2 \\ t3 \\ \end{tabular} \end{document} Hier wird durch die zusätzlichen  Öffne in Overleaf \documentclass[margin=2mm]{standalone} \usepackage{tikz} \newcommand{\test}[1]{% \def\temp{}% \foreach \i in {1,...,#1} {% \xdef\temp{\unexpanded\expandafter{\temp t}\i\unexpanded{\\}}% }% \temp} \begin{document} IST: \begin{tabular}{c} \test{3} \end{tabular} SOLL: \begin{tabular}{c} t1 \\ t2 \\ t3 \\ \end{tabular} \end{document} greifen.  Öffne in Overleaf \documentclass[margin=2mm]{standalone} \usepackage{tikz} \makeatletter \newcommand{\test}[1]{% \def\temp{}% \foreach \i in {1,...,#1} {% \protected@xdef\temp{\temp t\i\protect\\}% }% \temp} \makeatother \begin{document} IST: \begin{tabular}{c} \test{3} \end{tabular} SOLL: \begin{tabular}{c} t1 \\ t2 \\ t3 \\ \end{tabular} \end{document} Hier wird das  Besser wäre übrigens,  Öffne in Overleaf \documentclass[margin=2mm]{standalone} \usepackage{tikz} \newcommand{\test}[1]{% \def\temp{\begin{tabular}{c}}% \foreach \i in {1,...,#1} {% \xdef\temp{\unexpanded\expandafter{\temp t}\i\unexpanded{\\}}% }% \expandafter\def\expandafter\temp\expandafter{\temp\end{tabular}}% \temp} \begin{document} IST: \test{3} SOLL: \begin{tabular}{c} t1 \\ t2 \\ t3 \\ \end{tabular} \end{document} vorschlagen. Wenn Du sehen willst, was Stück für Stück innerhalb von  Öffne in Overleaf \documentclass[margin=2mm]{standalone} \usepackage{tikz} \newcommand{\test}[1]{% \def\temp{\begin{tabular}{c}}% \show\temp \foreach \i in {1,...,#1} {% \xdef\temp{\unexpanded\expandafter{\temp t}\i\unexpanded{\\}}% \show\temp }% \expandafter\def\expandafter\temp\expandafter{\temp\end{tabular}}% \show\temp \temp} \begin{document} IST: \test{3} SOLL: \begin{tabular}{c} t1 \\ t2 \\ t3 \\ \end{tabular} \end{document} verwenden, um in der  Öffne in Overleaf > \temp=macro: ->\begin {tabular}{c}. \test ...f \temp {\begin {tabular}{c}}\show \temp \foreach \i in {1,...,#1} ... l.17 IST: \test{3} > \temp=macro: ->\begin {tabular}{c}t1\\. \pgffor@body ...t}\i \unexpanded {\\}}\show \temp l.17 IST: \test{3} > \temp=macro: ->\begin {tabular}{c}t1\\t2\\. \pgffor@body ...t}\i \unexpanded {\\}}\show \temp l.17 IST: \test{3} > \temp=macro: ->\begin {tabular}{c}t1\\t2\\t3\\. \pgffor@body ...t}\i \unexpanded {\\}}\show \temp l.17 IST: \test{3} > \temp=macro: ->\begin {tabular}{c}t1\\t2\\t3\\\end {tabular}. \test ...dafter {\temp \end {tabular}}\show \temp \temp l.17 IST: \test{3} zu erhalten. Achtung: Im Online-Editor Overleaf funktioniert das so nicht, da  Danke für die ausführliche Abhandlung. 
                
                
                
                
                
                (05 Jun '18, 22:54)
                cis
                
             | 
| Öffne in Overleaf \documentclass[margin=2mm]{standalone} \usepackage{tikz} \newcommand{\test}[1]{% \xdef\temp{}% \foreach \i in {1,...,#1} {% \xdef\temp{\temp t\i \cr}% }% \temp} \begin{document} IST: \begin{tabular}{c} \test{3} \end{tabular} SOLL: \begin{tabular}{c} t1 \\ t2 \\ t3 \\ \end{tabular} \end{document} 1 Hinweis: Das funktioniert so natürlich nur, solange wirklich komplett expandiert werden soll! In LaTeX ist es meist besser,  
                
                
                
                
                
                (04 Jun '18, 08:31)
                saputello
                
             | 
| Meine obligatorische Lua-Lösung darf natürlich nicht fehlen. :) Öffne in Overleaf \documentclass{article} \usepackage{tikz} \newcommand{\test}[1]{% \directlua{ for i = 1,#1 do tex.sprint("t" .. i .. [[\noexpand\\]]) end }% } \begin{document} IST: \begin{tabular}{c} \test{3} \end{tabular} SOLL: \begin{tabular}{c} t1 \\ t2 \\ t3 \\ \end{tabular} \end{document} | 
 
			

