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
20 views

Using foreach to add variable number of rows to a bytefield inside a TikZ node? (part 2)

I am trying to add a variable number of fields to a bytefield, inside a TikZ Node. An earlier question (Using foreach to add variable number of rows to a bytefield inside a TikZ node?) gave helpful ...
0 votes
0 answers
17 views

Fill a database using datatool with index in first column, twice the index in second column, and incrementing the index in each iteration of a loop

I would like to fill a database using datatool with an index in the first column, twice the index in the second column, and incrementing the index in the first column in each iteration of a loop. The ...
1 vote
2 answers
60 views

How to define a column vector command using foreach and bmatrix?

I am trying to do something like this, \DeclareRobustCommand{\col}[1]{ \begin{bmatrix} \foreach \i in {#1} {\i \\} \end{bmatrix} } Which unfortunately does not work, while this works, \...
  • 227
1 vote
1 answer
40 views

Using \foreach to make a network graph?

I am tying to make this hand drawn network: In the process of making this graph, I am also trying to learn loops. I am trying to use \foreach here. This is the code I have managed so far: \...
2 votes
0 answers
20 views

Error with TikZ foreach iteration on changing tthe position [closed]

I want to draw a series of shapes (circle in the example) and change the color and text to be inscribed. I can get that with the following code: \documentclass[x11names,svgnames]{standalone} ...
  • 1,216
4 votes
1 answer
98 views

Generate simple table (with foreach?)

I'm trying to generate a simple empty table with \foreach but somehow it doesn't work due to the following error: ! Missing \endgroup inserted. \endgroup l.13 ^^I^^I^^I} I've inserted something that ...
0 votes
1 answer
39 views

TikZ - foreach substitution inside coordinate name not working [closed]

I have coordinates named a1 to a9. They were defined by \coordinate (a1) at (0,0); etc. They all have valid x and y coordinates. I need to create 9 circles whose centers are each of the 9 coordinates ...
2 votes
1 answer
60 views

Drawing loops around an ellipse in Tikz

I am trying to show the loops of magnetic field flow around a circular current in tikz. I'd like to end with a central ellipse, something like \draw (0, 0) ellipse (3 and 1), that has eight 'equally' ...
  • 23
7 votes
3 answers
533 views

How to loop through every character of an argument in TeX

I'd like to implement an easy foreach-loop, which takes two arguments — a string and an expected formatting for every character (optionally except last), as follows: \spell{example}{\x-}, which ...
  • 73
3 votes
1 answer
111 views

Foreach with different label

Is there a simple way to have display my coordinate system? \begin{tikzpicture} \draw [-latex,thick] (0,0)--(12.5,0); \draw [-latex,thick] (0,0)--(0,10.5); \foreach \y in{2,...
1 vote
0 answers
24 views

How can i use corretly Latex notation via forEach function in vanilla JS? [closed]

I have array examples where i have example (ax^2 + 5x +1 = 0), example (ax^2 + 9x +9 = 0) etc. I have following logic const container = document.querySelector("#examples-container"); ...
1 vote
1 answer
61 views

Connecting elements in list

How to connect these elements so i can get linked list, foreach needs to stay because its required in my project if someone could help?? \documentclass{article} \usepackage{pgffor} \usepackage{tikz} \...
1 vote
1 answer
46 views

Edge endpoints when automating node connections with Tikz/automata

I'm trying to draw a Markov chain. As I have 11 states, I tried to automate the declaration of states as well as the edges in a for loop. Here is my MWE: \documentclass{standalone} \usepackage{tikz} \...
0 votes
1 answer
36 views

Allow special character (underscore) in loop (using pgffor)

I would like to allow special characters (in my case, an underscore) to be displayed in a loop. Say I have this MWE: \documentclass[12pt]{article} \usepackage{pgffor} \begin{document} \foreach \g in {...
  • 413
0 votes
0 answers
12 views

typeset cont. on next page if foreach reaches in the next page

I have the following code defined: \newcommand{\mynotes}[1]{\par \noindent \underline {\bfseries Your Answer:}\vspace{10pt}\\ \foreach \n in {1,...,#1}{% \rule{\textwidth}{0.5pt}\...
1 vote
1 answer
40 views

Using a foreach loop in LaTeX glossary to create a list of acronyms

I would like to use a foreach loop to create a list of acronyms in a LaTeX document. I expect the code should look something like this but it does not work (it nearly works): \documentclass{article} \...
0 votes
1 answer
41 views

Multiple pgfplots addplot commands in foreach loop

I am trying to build upon the answer of Christian Feuersänger here: https://tex.stackexchange.com/a/17817/193625 Instead of just on \addplot I want to have multiple in the body of my loop. However ...
  • 153
2 votes
1 answer
77 views

Tikz creating and array of images with a box around some [closed]

I'm trying to create a collection of images that look like this: I would love to use some code so I can specify the image, the array size and also the box location, say: \FracObj{object}{number of ...
0 votes
1 answer
61 views

Using \xdef in \foreach errors when using another \foreach inside the \xdef

I'm using TeXShop 5.0.4 and encountering a cryptic error ! Incomplete \iffalse; all text was ignored after line 15. <inserted text> \fi where my code contains no explicit "...
0 votes
2 answers
65 views

foreach inside tcbitemize

I'd like to use a foreach loop inside the tcbitemize environment. MWE: \documentclass[11pt]{article} \usepackage[utf8]{inputenc} \usepackage[many]{tcolorbox} \begin{document} \begin{tcbitemize}[...
  • 355
0 votes
0 answers
30 views

PGF Groupplots and For loop. Split filename in \edef

I am creating an image grid with many images using pgf groupplots library and a for each loop \pgfplotsforeachungrouped. The filenames are structured as follows: preamble_title_percent.jpg. I want to ...
  • 1
0 votes
2 answers
83 views

Labelling the points in the grid

I am trying to construct a grid using tikzpicture, but with labels at (0,0), (0,1), (0,2) etc, something like this \begin{tikzpicture}[scale=1] \draw[step=1cm,lightgray,very thin] (0,0) grid (5,5); \...
  • 367
0 votes
0 answers
63 views

Tikz: Problem with foreach loop and math in list

I copied the following tikz code (indicating a magnetic field) from the source code of a document I created some years ago (and which compiled at that time). Now it doesn't compile anymore. Here is a ...
  • 1,604
0 votes
0 answers
27 views

\foreach \i in {1,...,\pgfmathresult} not working

After calculating \pgfmathresult and turning the output as an integer: \pgfmathprintnumber{\pgfmathresult} Which for example is 10, I want to iterate instead of \foreach \i in {1,...,10}{% some ...
2 votes
3 answers
96 views

Using TikZ's foreach loop to write a square of numbers

I would like to draw the following square of numbers: 6 7 8 3 4 5 0 1 2 For this purpose I wrote the following LaTeX code, and saved it in the file ~\test.tex: \documentclass[tikz,border=1cm]{...
  • 10.7k
1 vote
1 answer
46 views

TikZ foreach loop fails when the list doesn't end with a comma (Part II)

The following question is closely related to this one, however the solution given in the answer to that question does not work for the LaTeX document to be presented below, and therefore I've had to ...
  • 10.7k
4 votes
1 answer
79 views

TikZ foreach loop fails when the list doesn't end with a comma

The following LaTeX document is saved in a file whose path is ~/test.tex. \documentclass[border=1cm,tikz]{standalone} \tikzset{ square/.pic={\draw (0,0) rectangle (1,1);} } \begin{document} \begin{...
  • 10.7k
0 votes
1 answer
68 views

Using tikz foreach (in axis environment) and addplot to graph functions with changing/varying colors and linewidth

I want to make a tikzpicture displaying a function shifted multiple times, each time having a lighter color and line width. Using How to make Loop? and Changing color in foreach as references, I ...
  • 701
0 votes
0 answers
16 views

Beamer slide for skip counting objects

I have created some beamer code to support students with skip counting objects. \begin{frame} Count the critters. \vspace{1cm} \newline \tikzset{every node/.style={font=\scriptsize}} \begin{...
2 votes
2 answers
61 views

How can foreach be used to create synonymous macros?

I need many synonyms of many macros with key figure references? How do I use the \foreach token as a \newcommand name? I look to replace the ACTUAL output with the MOCKUP output by generating and ...
  • 307
3 votes
3 answers
251 views

Unable to shorten foreach statement

The following code is a simple double foreach statement that generates a staircase of coordinates. \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{tikz} \begin{document} \begin{...
1 vote
1 answer
28 views

foreach loop print PGF parsed math

Desired output: a table with row number and a function of that (say, row number plus one). 1 2 2 3 ... ... 10 11 Attempt: Here's my MWE adapted from Foreach inside a TikZ matrix. \documentclass[...
3 votes
2 answers
164 views

Creating a newcommand to draw base ten blocks

Ignasi made some great code for base ten blocks and I've been trying to use it to automatically generate representations of 2-digit numbers. %%Base 10 Blocks \tikzset { node distance=.1cm, ...
1 vote
2 answers
68 views

Creating newcommand for a tens frame grid using tikz

I'm trying to create tens frames to model addition of numbers. I'd love it if \tensframe{#1}{#2} would show #1 green circles starting on the left and growing up, then #2 blue circles continuing from ...
1 vote
1 answer
92 views

Parsing of comma-separated list for \foreach

I am using PGF's \foreach on comma-separated list where the items may contain spaces; each item can be enclosed in {...} if it contains space, that works fine. Now, what happens when there is only a ...
  • 2,933
1 vote
3 answers
91 views

How to make a board with coordinates

I made a board with coordinates. But I want it at the beginning (0,0) instead of (3,0) with this code below: \begin{tikzpicture}[scale=1.25] \foreach \y in {0,1,...,3} \foreach \x in {0,1,...,3} { %\...
0 votes
1 answer
80 views

Making a beamer file with a tikz skip counting grid

I'm trying to make a table from 1-120 where I can identify each cell and colour it to show skip counting. Here are the first few slides of what I am trying to achieve for skip counting from 30-75 by ...
2 votes
1 answer
40 views

pst-electricfield: How to use multido for placing multiple charges

So I tried to place multiple charges via the pst-electricfield package. Doing so manually works fine, but I'm trying to mimic a capacitor by placing many charges along a line. Is there a way to ...
  • 405
1 vote
1 answer
48 views

pgfplots: Interaction of "fill between" with scope and foreach loop

I intend to create several plots in different places, each with fill between areas, using the foreach loop. While all other plot lines do appear as expected for every iteration of the loop, the areas ...
  • 1,619
0 votes
0 answers
37 views

How to Create an Array of Numbers Within a Given Range and Shuffle Them?

Is there a way I can create an array of integers, say between 1 and 10, and then shuffle that array? I would like it to work with tikz/pgf \foreach. I imagine it would work something like this. \...
  • 133
2 votes
2 answers
284 views

Problem with foreach- loop

I would like to draw some circles and some squares and I would like to put in into a loop. But that does not seem to work. Any help would be great. \documentclass[tikz]{standalone} \usepackage{xfp} % ...
  • 25
2 votes
1 answer
60 views

tikzkeys not working inside foreach statement

As an attempt to solve my Define a 2D canvas using preexisting points, I came across the idea of @andrew swann's answer to Pass a 3d coordinate via pgfkeys and tried to adapt it. This is how the 3d ...
  • 155
5 votes
2 answers
168 views

def in foreach Tikz

I am a beginner in foreach command ! \begin{tikzpicture} \foreach \i in {0,1}{% \def\n{23} \node at (0, -\i) {\n} ; \def\n{24} } \end{tikzpicture} Is it possible ...
  • 353
0 votes
1 answer
46 views

Strange characters added when using 'xstring' functions in 'foreach'

I'm trying to create a macro which display a list of string and if a string start with '*', it apply specific style (like bold). So I'm using a foreach and xstring macros but something goes wrong with ...
3 votes
1 answer
40 views

Using \foreach to add rows containing references to pgfplots objects in a matrix of nodes

This is a follow-up question to Using \pgfplotsinvokeforeach to create rows in a matrix of nodes. Consider the minimal working example below: \documentclass{standalone} \usepackage{pgfplots} \...
1 vote
2 answers
99 views

Is there a way to automatically generate a label and caption for a series of figures?

I have a list of figures which I insert into my document using a "foreach" loop. Is there a way to also generate labels for each of these figures from within the foreach loop? I have the ...
  • 163
1 vote
1 answer
108 views

Help with looping through a folder to insert all images within

I have a folder within overleaf of images, which I'd like to include as figures in the document. However, I'm having some trouble with calling the "for" loop. May I ask for some assistance ...
  • 163
2 votes
1 answer
33 views

Nodes anchors in foreach loop

I need to change the anchor of a node depending on the sign. For example, if the sign is "-", then the anchor is "north", otherwise "south". To do this, I implemented the ...
  • 5,296
1 vote
1 answer
46 views

Arbitrarily change axis properties in pgfplots within a foreach loop

I have a bunch of plots which I want to insert as subfigures within a larger figure. Because they share the same y-axes, I don't want to waste space repeating the same axis and tick labels for each ...
0 votes
1 answer
65 views

How to create an empty mxn table in latex using \foreach?

I want to create an mxn table using pgffor. The following code is my try and gives the following error: ! Undefined control sequence. \pgffor@endgroup ...d {\pgffor@remember@once@code ...
  • 1,914

1
2 3 4 5
16