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
3 votes
1 answer
95 views

Non-trivial usages of tikz foreach with a list of coordinates

I'm struggling to make the following code work: \documentclass{minimal} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \foreach \point in {(0,0),(0,2),(2,0),(2,2)} { ...
  • 387
1 vote
1 answer
66 views

How do I use foreach in a tikzpicture environment with a macro input?

I am drawing a picture in my document using a foreach loop in a tikzpicture environment, like this stripped-down example: \documentclass{standalone} \usepackage{tikz} \newcommand{\drawBoxes}[1]{ \...
0 votes
1 answer
48 views

How to use math operation in an array index created by the package arrayjob

I want to put each number in the array on a grid by TikZ. \documentclass[tikz]{standalone} \usepackage{pgffor} \usepackage{multido} \usetikzlibrary{calc} \usepackage{arrayjob} \newarray\Values \...
0 votes
1 answer
60 views

Functions defines with a loop (\foreach) makes the tikz picture go far away

In the following MWE, the tikz picture is outside of the paper. When I replace 10 by a bigger number, the pictures goes even further to the right. Any idea ? \documentclass{article} \usepackage{tikz} ...
  • 165
4 votes
4 answers
386 views

Get value from \foreach

I build a macro named \fromlist to get value from a list. The value can be typeset, but can not be invoked directly, why and how to deal with it? Code: \documentclass[a4paper]{article} \usepackage{...
  • 2,657
12 votes
6 answers
1k views

How can I create a comma-separated list of characters from a text string?

How can I split the string Hello World! - stored into a macro \def\mystring{Hello Word!} - into a comma-separated list of characters (including spaces) which can be used as argument of a \foreach loop ...
2 votes
1 answer
137 views

Include \hrule within tabular rows generated using \foreach

This question extends the solution from Generate rows in table using \multido (or something similar). Based on the solution to the linked question, I understand how to use a \foreach loop to build ...
4 votes
1 answer
69 views

Loop variable in node anchor specification

Given a loop variable \x, I would like to use it as (foo.\x west), for example, where \x could be north. My attempt: \documentclass[tikz,border=1mm]{standalone} \begin{document} \begin{tikzpicture} ...
  • 595
0 votes
0 answers
31 views

Index variable appears to escape the \foreach loop and then wrecks stuff [duplicate]

I'm using pgfplotstable to create standalone graphs of test data. I've included pgffor and I'm trying to use a \foreach loop to iterate over the three output channels for a given unit under test ...
10 votes
3 answers
1k views

Labeling axis in π increments

i would like to lable my x-axis on a tikz-picture in π/4 increments, like in the wikipedia sin and cos graphic 1. This is my code (but it doesnt work): \documentclass{scrartcl} \usepackage{lmodern} % ...
  • 103
4 votes
3 answers
259 views

How to create numbered-named saveboxes in a foreach-loop?

Is there a principally way to create numbered saveboxes? For a usage like: \usebox{box-1}, \usebox{box-2}, \usebox{box-3} The follwing MWE gives no error, but no output. PS: It seems to be clear why ...
  • 6,461
1 vote
1 answer
39 views

foreach: print a polynomial using its terms

How to make the following work to have the output 5 x V^3 + 7 x V + 9 \documentclass{article} \usepackage{tikz} \begin{document} \newcommand{\mypower}{3, 2, 1, 0} \newcommand{\mycoeff}{5, 0, 7,...
  • 8,879
2 votes
1 answer
309 views

Use a variable in foreach

I am trying to use a variable in my foreach loop. It would make things a lot easier, because i only need to change one value and multiple loops are affected. Something like this: \begin{tikzpicture}[y=...
1 vote
2 answers
56 views

Use of \xappto, \noexpand and (for example) \emph

I'd like to accumulate some text from a macro and place it in a multipart TikZ node. Works as expected until there is a macro in the text being accumulated, at which point TeX fails. It would, as ...
  • 8,026
2 votes
1 answer
72 views

Create table with for loop (\Numpoint loops) and formula

Im trying to get a table added to my exam tex file that shows the grade earned based on all possible amounts of scorable points. I am running intwo two issues: The amount of \numpoints of the {exam} ...
1 vote
2 answers
111 views

How can I create a time chart with a non-uniform row height within TikZ loop?

The code below produces the given chart. (Thanks Sandy G! - see How do I create a timeline charts similar to this style? Suggestions ) I have made many modifications to this, even with additional ...
  • 161
4 votes
2 answers
380 views

Use a 'foreach' loop for drawing a staircase in TikZ

I’m trying to draw a staircase where I can set the number of stairs, i.e., \renewcommand{/stairs}{5} and it will create the stairs. I believe a for each loop can accomplish this. How can I simplify my ...
  • 337
1 vote
1 answer
248 views

How to procedually set column type in pgfplotstable for each column individually?

For a project I am working on, I would like to write a wrapper macro \fancyTable, which communicates with pgfplotstable in the background. The user should be able to specify the column alignment as a ...
  • 95
0 votes
2 answers
210 views

'Missing \endcsname inserted' error from a for loop of images

I have a for loop that goes over a list of defined names associated with images: \def \names{{3088452\_cutouts.png},{3088553\_cutouts.png},{3089892\_cutouts.png},{3090579\_cutouts.png},{3090786\...
0 votes
1 answer
62 views

Can I collect all the code in one code?

I want to write a single code for many polygons using foreach. How can I plot each one with the same code by using n variables and writing n values? I am repeating a few steps in the same way as below....
  • 33
2 votes
1 answer
108 views

Latex3 and \foreach: Do common operation over list of clist variables

I am trying to learn LaTeX3. In writing one of my projects I faced a situation in which is usefull working with short comma-separated lists, testing whether they are empty, have only one item, etc ... ...
0 votes
1 answer
56 views

How to do math with coordinate labels in tikz?

I have a set of TikZ pics defined as \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calc,positioning} \tikzset{ shape/.pic = { \node [draw] (xx) {}; ...
  • 258
0 votes
0 answers
87 views

Problem with \foreach and \input

I am having a problem using \foreach to import a variable amount of files into my latex template. This is the code I am using for this particular part: \documentclass[8pt,handout,t]{beamer} \...
1 vote
1 answer
68 views

Iterating through two lists with different lengths

I'm trying to draw a calendar type thing in TikZ, and need to place the days of the week around a circle. I can't see how I can repeat the 7 day pattern over a range of 365 positions. This works: \...
  • 1,173
1 vote
0 answers
40 views

Avoiding vertical shift when using \foreach to display a series of images [duplicate]

I'm trying to show a sequence of almost identical images in a beamer frame, to be able to step back and forth and compare the differences. The images are numbered as image1.pdf, image2.pdf etc., and ...
  • 167
1 vote
1 answer
61 views

Tikz foreach draws lines from edge of nodes unexpectedly [duplicate]

Consider the following figure: \begin{tikzpicture}[ selected/.style={circle, draw=black, fill=yellow!60, very thick}, unselected/.style={circle, draw=black, very thick} ] \node[selected] ...
  • 111
4 votes
3 answers
207 views

Connect points in array with \foreach

How can I get the next element in array that's being looped with \foreach? Here is an example what I'd like to achieve, but it obviously doesn't work \documentclass{article} \usepackage{tikz} \begin{...
  • 3,927
3 votes
1 answer
287 views

How to fading color the curve grid

I want to draw the curve grid as bellow picture. Please help me control the grid with the belly and fade the color. MWE \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture} \...
2 votes
1 answer
62 views

Issue label point with tkz-euclide within foreach loop

I wish to display some numbered balls, but somehow, whether it's from my missuse of tkz-euclide or foreach, I failed to label the balls correctly. Here is a MWE. \documentclass{article} \usepackage{...
  • 75
2 votes
1 answer
47 views

Can't get foreach to work with ifinlistcs

Could anyone kindly explain why the \ifinlistcs is always false when I try to use \foreach to provide each test element? Of course, I can use \dolistcsloop as it is the recommended way to process the ...
  • 23
1 vote
1 answer
134 views

Draw points in tikz with foreach

I have the following code: \documentclass{standalone} \usepackage[portuguese, shorthands=off]{babel} \usepackage[utf8]{inputenc} \usepackage{tikz} \usepackage{xfp} \usepackage{pgfplots} \usepackage{...
3 votes
1 answer
125 views

tikz: Clipping everything outside the axis

Clipping everything outside the axis is doable in pgfplots, but drawing lattices has not been great for me there because \foreach doesn't quite work inside axis environment. The code I came up with is ...
5 votes
1 answer
118 views

`\foreach` does not understand constants in `declare function`: a bug?

In relation with an answer, I see that \foreach does not understand a constant (n) in declare function. Is it a bug? or there is another proper way of code for this situation? \documentclass[border=...
  • 15.8k
3 votes
2 answers
205 views

datatool creating a matrix with 3x3 data \ DTLforeach

I am using datatool package. Several csv files with data are generated in my project and I create index.csv to use Nested \ DTLforeach. I do not understand how I can assemble a 3x3 / 3x4 or 3x5 matrix ...
1 vote
1 answer
18 views

foreach syntax missing endcs.., tex cap exceeded

I want to draw points in a loop. x and y coordinates are given ( two variables). I think it is syntactically right, but tikz dont. Can anyone help? mwe: \documentclass[]{article} \usepackage{tikz} \...
  • 579
6 votes
2 answers
176 views

Coordinate [turn] option in foreach

I am trying to recreate a triangle spiral(red) with a foreach -but the turn option does not behave nicely - it seems to turn less and less each time. Is there an explanation? What am I doing wrong? ...
1 vote
1 answer
99 views

\foreach loop to draw lines

i was trying to use \foreach to read a specific column out of a file. If a value out of this column is lower than e.g. 55 a line should be drawn. I am using a groupplot and the line should be in both ...
0 votes
2 answers
61 views

Use pgffor to define a new command?

I'm trying to use pgffor to define a new command for \boldsymbol\mathsf like the following. \documentclass{article} \usepackage{pgffor,amsmath} \newcommand\makemathsfbf[1]{ \foreach\a\b\c in{#1}{ ...
  • 127
13 votes
3 answers
413 views

I encountered the following problems when using foreach:

\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \x in{0,0.1,...,0.5}{ \node[] at (20*\x,0) {\x}; } \end{tikzpicture} \end{document} ...
4 votes
3 answers
345 views

When and how to use foreach in a path command? TikZ

Why does my code fail? Without the foreach my code works correctly. Generally, when and how can I use foreach within a path command? Is this a bad practice? If so what should be the alternative? \...
  • 383
2 votes
2 answers
56 views

Confused with updating a newcommand constant inside a foreach loop

I am confused on how to update a "constant" construct inside a \foreach loop, the similar questions on here don't directly address the issue I am facing and I'm not experimented enough (yet! ...
0 votes
1 answer
50 views

Define newcommand inside a loop

In my latex document I have defined an array of element and I am making a loop within this array. I would like to define newcommand inside this loop. The idea is to make \newcommand{\name1}{ \begin{...
2 votes
2 answers
65 views

drawing curved connectors within \foreach loop in a graph

I am trying to draw a graph on 216 vertices - 215 vertices distributed on a wheel around a fulcrum. Then I want to connect all the peripheral vertices to the fulcrum and join the vertices on the wheel ...
1 vote
3 answers
124 views

Apply operations to iterator \x in \foreach loop in Tikz

I am trying to draw a graph comprised of 13 triangles joined at the centre (i.e. a wheel graph with some edges missing from the outer cycle). I managed to connect the outer vertices to the central one ...
4 votes
2 answers
230 views

\foreach loop doesn't work with \input

The result of this: \foreach \x in {1,2,3}{% \x } and this one are the same: \newcommand{\mycommand}{% 1,2,3% } \foreach \x in \mycommand{% \x } However if i make a "example.tex" file ...
1 vote
1 answer
36 views

Create columns in beamer with foreach

I cannot manage to create columns with \foreach in beamer, the following code: \documentclass{beamer} \usepackage{pgffor} \begin{document} \def\a {0.2, 0.2, 0.2} \begin{frame} \begin{columns} ...
0 votes
2 answers
107 views

\foreach coordinate names in PGFPlots

I have some points defined via \coordinate (A1) at (-4,0); \coordinate (B1) at (-2,1); \coordinate (C1) at (0,0); ... And I want to place a little dash at their location. I tied two approaches, but ...
  • 3,927
1 vote
2 answers
101 views

Tikz-matrix by loop, calculations inside

I looked here and tried to use \expandonce{\pgfmathprint{\n+1}} \expandonce{\&} Text inside the matrixcontent-loop. But this does not work. What do I have to do? \documentclass[margin=5mm, ...
  • 6,461
0 votes
1 answer
26 views

Multiple thmboxes with for each loop

I want to get rid of a lot of redundant code while defining thmxboxes. I tried to use for-each loops, but it does not work. The following code (that does not work) should give you an idea of what I'm ...
  • 408
0 votes
1 answer
116 views

Even odd slideshow with foreach loop in TikZ

I am trying to prepare a slideshow to illustrate the countability of the set of all integers. Here is what I have done so far: \documentclass[aspectratio=169]{beamer} \usetheme{CambridgeUS} \...

1
2
3 4 5
16