Questions tagged [foreach]

{foreach} is for questions regarding the TikZ/PGF module of the same name which can also be used as a standalone package pgffor.

Filter by
Sorted by
Tagged with
2
votes
1answer
16 views

ForArray not working inside newcommand

I try to use the forarray package but the output is different when used inside a custom \newcommand: \documentclass{scrartcl} \usepackage{forarray} \begin{document} \newcommand{\printforarray}{% ...
0
votes
0answers
32 views

How to draw this sine function with TikZ axis [duplicate]

ok, I have a problem with drawing this, can anyone help me, I need a full code for identical graph.Thanks in advance. :(
2
votes
1answer
36 views

weird output using foreach command

So I am trying to familiarize myself with tikz \foreach command through this link Yet something strange happened. According the the linke, if I am trying to iterize two variable at the same time ...
0
votes
0answers
53 views

\foreach and \def problems

I've been trying to make a tikzpicture in 3d, using tikz-3dplot, that consists of a set of nested circular cones around the \pm z axis. There is one parameter that should control the whole thing, ...
1
vote
1answer
33 views

Phase plot better coding

So I managed to get the magnitude and phase plot as shown below: \documentclass[12pt]{article} \usepackage{tikz} \usepackage{amsmath} \usepackage{amssymb} \usepackage{pgfplots} \usepackage{float} \...
3
votes
1answer
50 views

how to generate beamer frames in a foreach loop

I need to generate several frames which each contain an image. I was thinking of looping with \ foreach but it doesn't work \foreach \nn in{1,2,...,5}{ \begin{frame}[fragile]{} \includegraphics[width=...
1
vote
1answer
28 views

Tikz setcounter not working

I have tried to emulate other code using letters instead of numbers in the foreach in tikz, so here is my code: \documentclass[12pt]{article} \usepackage{tikz} \usetikzlibrary{shapes,arrows,automata, ...
1
vote
1answer
20 views

For loop not running properly in pgfplots

In this picture, I am trying to get the dashed plots done via a loop (I managed to do so without a loop): Code: \documentclass[12pt]{article} \usepackage{pgfplots} \pgfplotsset{compat=1.16} \...
1
vote
2answers
26 views

Arrows drawn with \foreach point to wrong side of \node

I noticed that arrows in the below MWE point to the wrong side of the nodes if I draw them with a foreach statement, but not if I write the same drawing command manually. What is wrong? \...
0
votes
0answers
19 views

pgfplots foreach, node name is the same [duplicate]

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} \...
5
votes
2answers
196 views

Strange behaviour of foreach

I am totally dumbfounded. Consider the following code: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \a / \b in { (20:1) / (90:1) ,(-20:1) / (-90:2) ...
2
votes
8answers
96 views

defining a new command with variable name in a loop

I was trying to not write 26 redundant lines; \magic works on its own; but the loop breaks it \usepackage{pgffor,amsfonts} \newcommand{\magic}[1]{ \expandafter\newcommand\csname b#1\endcsname{\...
4
votes
2answers
114 views

I would like to create a macro to fill in a percent grid automatically in the most efficient manner

I would like to create a macro that fills in the percent grid if I call \mypercent{43}, it will fill in 43 squares. I'm doing it manually but would like help in automating the process. Here is my ...
4
votes
1answer
84 views

Create an animation of a 2D convolution in tikz and the animate package

I was trying to create an animation to illustrate a simple 2D convolution using tikz and the animate package. I tried the code below but I am getting the following errors: Package animate Error: ...
0
votes
1answer
43 views

im know on my thesis and i m looking to draw a graphic with tikz as you see in this Picture can anyone please help [closed]

im know on my thesis and i m looking to draw a graphic with tikz as you see in this Picture can anyone please help. i know i need to use the foreach to draw this kind of Bullet but i dont know how ...
3
votes
1answer
63 views

Coloured prism with TikZ

all. I've drawn a pentagonal prism using TikZ's 3d library. Here's the code: \documentclass[tikz,border=1cm]{standalone} \colorlet{blu}{blue!10} \usetikzlibrary{3d, % arrows } \begin{document} \...
1
vote
1answer
41 views

Failed to use the local bounding box produced by \foreach and \pic

I was confronted with a problem of \pic and \foreach in Tikz. Below is an MWE: \documentclass[tikz]{standalone} \tikzset{% pics/abc/.style={% code={ \node {this is some path}; } } } \begin{...
1
vote
1answer
45 views

tikz-picture: for-loop over array

I want to plot a piecewise constant function like that minimal example: Hello, I want to plot a piecewise constant function like that minimal example: \documentclass[tikz]{standalone} \usepackage[...
4
votes
3answers
200 views

parallel iteration over elements of separate lists

I guess this is a simple problem, but I don't know how to do it in TeX/LaTeX/tikz. What I'd like to do is to iterate over several lists in parallel, and do something with the respective values. One of ...
2
votes
2answers
95 views

Connecting points in a for loop with tikz

\documentclass{article} \usepackage{tikz} \begin{document} \begin{center} \begin{tikzpicture}[line width=0.5pt] \filldraw [fill=white] (0,0) circle [radius=3cm] \foreach \...
3
votes
3answers
86 views

set global variable command for foreach loop

How can I set variable definition as a global variable to use it outside the eachfor loop? \newcommand\Var[3]{ \expandafter\edef\csname #1\Roman{#2}\endcsname{#3} } \newcounter{count} \foreach \i ...
2
votes
2answers
54 views

\foreach, the last iteration is not executed

I have two nested \foreach loops. The inner loop works fine, but the outer loop does not. There are two commands which should be executed during each iteration. Both commands change during each ...
1
vote
1answer
38 views

Circle helper lines for Spirograph aligning purposes

I use the following code, inspired by Dario Orescanin, to draw a circle with helper lines, for Spirograph aligning purposes. \documentclass{beamer} \beamertemplatenavigationsymbolsempty \usepackage{...
1
vote
1answer
66 views

\tableheadline within foreach

I want to generate a list of column headings in a tabularx automatically. Here is a MWE: \documentclass{memoir} \usepackage{tabularx} \usepackage{pgffor} %Adopted from classicthesis-config.tex \...
3
votes
1answer
93 views

Plot a Taylor series using \foreach

I have a little question: I need to create the Taylor series of funtion f(x) = 1/(1-x). I am trying to use the command \foreach to create the Taylor series 1+x+x^2+x^3+... inside the environment ...
0
votes
1answer
38 views

pgfplots: How to overwrite macros in a loop for calculating domain-values

I want to draw several arcs (from percentages) in a loop. The following arc should connect to the previous one: 50% (Start=0, End=180°), then 25% (Start=180°, End=180°+90°),.... How do I do it ...
2
votes
0answers
49 views

Combining several Spirograph codes into a one unified code

From the answers to these questions 1, 2, and 3: Is it possible to combine the 3 versions of the Spirograph codes: the simple one including controlling nRotations, colours, and scales; the one ...
1
vote
2answers
28 views

Using surrounding list items in inner loops to input composite filenames (forarray package)

I am trying to compile a document where a section is made up of various subsections (one for each topic I want to report), each of them made up of a different number of subsubsections (varying ...
6
votes
1answer
270 views

Drawing Spirograph patterns using \foreach loops

I used the following code from the answer to this question, to draw a Spirograph pattern \documentclass{beamer} \beamertemplatenavigationsymbolsempty \usepackage{tikz} \begin{document} \tikzset{pics/...
4
votes
1answer
112 views

Dynamic filling the writable textheight by horizontal rules page-by-page

For the following, how to calculate the number of horizontal rules (i.e. 19 and 11) based on the remaining writable textheight for each page? \documentclass{exam} \usepackage[ a4paper, left = 10 mm, ...
2
votes
1answer
70 views

Combining Spirograph code with nested multiple \foreach loop

I used the following code from the answer to this question to combine scale with colour and rotate changes \documentclass{beamer} \beamertemplatenavigationsymbolsempty \usepackage{tikz} \begin{...
2
votes
1answer
67 views

Combining Spirograph code with \foreach loop

I used the following code (which did not work) \begin{frame}[t] \frametitle{not working} \begin{center} \vskip -.8cm \begin{tikzpicture} \draw[line width=.04cm,looseness=1] \foreach \i/\clr in {3/...
12
votes
2answers
476 views

Graphing Trigonometric Functions

In my attempt to graph the transformation of a trigonometric function, I found myself having to work section by section. I researched the \foreach function to shorten the code and make it more robust ...
1
vote
2answers
59 views

Modifying \foreach loop to include a nested drawing

Using the following code from the answer to this question; how can circles be nested on each spike with colours match those of the individual drawings. \documentclass{beamer} \...
0
votes
1answer
50 views

newcommand, pgfplotsinvokeforeach, expl3: How to handle with several arguments of the kind '#…'

I have #1 for my newcommand. I have ##1 for my pgfplotsinvokeforeach-loop. Now I would need something like ###1 for my comparing-method "\fpcompareTF{##1<0}{333}{##1}". What is the right way ...
2
votes
1answer
82 views

LaTeX counters in TikZ foreach-loop with beamer

I want to draw a complete graph with tikZ. At first the nodes, then the lines of the first node to the others, then the lines of the second node to the remaining and so forth. All these steps work ...
1
vote
1answer
38 views

pgfplotstable: How to handle correctly with pgfplotsinvokeforeach at pgfplotstablecreatecol

I get only the last value (that is '0') expanded in the following pgfplotsinvokeforeach-loop. What have I to do? BTW: I would like to keep create col/set list. I hope it is possible. \documentclass[...
2
votes
1answer
55 views

Piecewise function for points

How to construct points by condition avoiding the repetition of \addplot. \documentclass[tikz, border=1cm]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} ...
2
votes
2answers
57 views

Strange \foreach[evaluate] behavior

I'm getting strange behavior when using TikZ's evaluate syntax. See how the bottom diagonal line is shorter than the other three? This is not the desired behavior. The code for the above image is ...
3
votes
1answer
65 views

pgfplotstable: How to create rows with a loop

I want to create several table-rows with calculated data inside. So I think, I have to use \pgfplotstablevertcat{<1>}{<2>} But something like this (example!) does not work: \foreach \...
4
votes
2answers
59 views

How to apply \ifthenelse check on list member accessed via macro?

Hi and many thanks in advance! I'm trying to perfom an \ifthenelse check on an element, which was extracted out of a list using a macro found here. Unfortunately I cannot figure out how to do it: ...
4
votes
2answers
233 views

Undefined control sequence when using \edef with \foreach

I’m attempting to define a command to build several similar tikz nodes. These nodes differ only by one parameter (#2 below). Here are the main questions I’ve referenced so far: Foreach inside a TikZ ...
1
vote
1answer
30 views

Print each item of foreach array on its own line

I'm somewhat new to package pgffor. Is it only for drawing, or can it be used to iterate through a list of text? I'm trying to use it to output a simple list of items, vertically, but I'm having ...
3
votes
2answers
42 views

Is it possible to create a command with another command, passing code as a string?

I want to loop through a list and print some text. The placement of that text is inside a table, inside a \makecell command. I could hard-code the items from the list I want, including some \\ ...
2
votes
1answer
107 views

tikz/foreach - strange behavior in combination with variables

I have made a command \tl{x} to "turn left x degrees". Because this is arc and coordinate juggling I have written some test code. Attached is the MWE: \documentclass[x11names]{article} \usepackage{...
6
votes
3answers
155 views

Define macros by using TikZ's \foreach

I would like to factorize a little the code below. \documentclass[12pt]{article} \usepackage{tikz} \newcommand\testabove[1]{above #1} \newcommand\testbelow[1]{below #1} \newcommand\testright[1]{...
0
votes
0answers
13 views

How to use macro as a `foreach` range? [duplicate]

These two loops do not produce the same result: \documentclass{article} \usepackage{tikz} \begin{document} \foreach \i in {a,b,c} {% \i+ } \def\Index{a,b,c} \foreach \i in {\Index} {% \i+ ...
8
votes
1answer
182 views

Plotting curves within a foreach loop and attributing colors from a colormap

I'm trying to plot curves inside a \foreach loop and at the same time define their color through a colormap. The color is given accordingly to a parameter of the curve:(\T/\Tmax*1000), where \T is the ...
0
votes
1answer
58 views

Use \foreach within animate inline in Beamer class throws error

I encounter an issue with the following code and must admit that I was able to find trick on the forum for now. \begin{frame}{Title} \begin{figure}[htbp] \begin{center} \begin{animateinline}[loop,...
2
votes
3answers
43 views

smallcaps in a matrix, \\ coupled with foreach loop

I wanted to make a command which would put all of my text in smallcaps and in a matrix. This is \fmold below. This gave me an error, prompting me to make a foreach loop as seen in \smallcapsify and \...

1
2 3 4 5
13