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
0 votes
1 answer
31 views

foreach command no working

I want to replicate this figure using tikz. Right now I am stuck with the lower part of the figure, the ground. I tried using foreach \x command, but for some reason I do not understand, it is no ...
user avatar
1 vote
1 answer
38 views

How to Produce a Circular Display of Images

I have an image (in this case, a colorized predefined one) that I would like to display in a circular fashion about a fixed point and specified radius. Consider the minimal (nonworking) example which ...
user avatar
  • 4,907
3 votes
2 answers
66 views

Can xparse distinguish arguments inside braces and single-token arguments without braces?

The \foreach command from pgffor package has a good feature that it can distinguish arguments inside braces and single-token arguments without braces: \foreach \i in {1,2,3} {do some thing} \def\...
user avatar
  • 7,704
1 vote
0 answers
47 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)} { ...
user avatar
  • 367
1 vote
1 answer
32 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]{ \...
user avatar
0 votes
1 answer
16 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 \...
user avatar
0 votes
1 answer
39 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} ...
user avatar
  • 165
4 votes
4 answers
328 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{...
user avatar
  • 2,213
11 votes
5 answers
898 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 ...
user avatar
2 votes
1 answer
56 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 ...
user avatar
4 votes
1 answer
62 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} ...
user avatar
  • 585
0 votes
0 answers
26 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 ...
user avatar
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} % ...
user avatar
  • 103
4 votes
3 answers
239 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 ...
user avatar
  • 6,217
1 vote
1 answer
34 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,...
user avatar
  • 8,759
2 votes
1 answer
62 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=...
user avatar
1 vote
2 answers
48 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 ...
user avatar
  • 7,683
2 votes
1 answer
62 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} ...
user avatar
1 vote
2 answers
92 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 ...
user avatar
  • 161
4 votes
2 answers
330 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 ...
user avatar
  • 195
1 vote
1 answer
143 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 ...
user avatar
  • 95
0 votes
2 answers
52 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\...
user avatar
0 votes
1 answer
60 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....
user avatar
  • 33
2 votes
1 answer
74 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 ... ...
user avatar
0 votes
1 answer
27 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) {}; ...
user avatar
  • 216
0 votes
0 answers
60 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} \...
user avatar
1 vote
1 answer
39 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: \...
user avatar
  • 1,163
1 vote
0 answers
31 views

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

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 ...
user avatar
  • 167
1 vote
1 answer
55 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] ...
user avatar
  • 111
4 votes
3 answers
150 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{...
user avatar
  • 1,861
3 votes
1 answer
264 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} \...
user avatar
0 votes
0 answers
28 views

Custom TABLE of abbreviations

I'm using the acronyms package, to manage the acronyms in my report. I have a separate file in which all the acronyms are defined using: \begin{acronym} \acro{DC}{Direct Current} \end{acronym} I don'...
user avatar
2 votes
1 answer
47 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{...
user avatar
  • 75
2 votes
1 answer
37 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 ...
user avatar
  • 23
1 vote
1 answer
76 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{...
user avatar
3 votes
1 answer
66 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 ...
user avatar
5 votes
1 answer
99 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=...
user avatar
  • 13.6k
3 votes
2 answers
165 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 ...
user avatar
1 vote
1 answer
17 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} \...
user avatar
  • 579
6 votes
2 answers
162 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? ...
user avatar
1 vote
1 answer
87 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 ...
user avatar
0 votes
2 answers
46 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}{ ...
user avatar
  • 127
13 votes
3 answers
408 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} ...
user avatar
4 votes
3 answers
295 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? \...
user avatar
  • 383
2 votes
2 answers
48 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! ...
user avatar
0 votes
1 answer
48 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{...
user avatar
2 votes
2 answers
57 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 ...
user avatar
1 vote
3 answers
83 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 ...
user avatar
4 votes
2 answers
151 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 ...
user avatar
1 vote
0 answers
20 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} ...
user avatar

1
2 3 4 5
15