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

learn more… | top users | synonyms

5
votes
1answer
66 views

Use \foreach in non-Tikz context

I want to create my own footnote-command for floating environments: %begin figure bla\myFootnote{XXX} blabla\myFootnote{YYY} blabla\myFootnote{ZZZ} %end figure some text \printSavedFootnotes The ...
1
vote
1answer
45 views

adding labels after the arcs with a foreach loop

I have this code that generates a cycle graph with labels in the arcs (reference here): \documentclass[border=2pt,tikz]{standalone} \usepackage{wasysym} ...
3
votes
2answers
97 views

leading zero in \foreach of a TikZ calendar

The calendar TikZ library creates for each day a node called (<name>-<year>-<month>-<day>). But there is a leading zero for <day> from 1 to 9, that is, to use the node of ...
5
votes
3answers
95 views

foreach loop for adding arcs using commands path and edge

i want to know how to use the foreach loop for adding arcs using commands \path and edge. For instance, the following code generates a cycle and the task is to add the arcs not manually: ...
5
votes
1answer
115 views

tikz: help with this foreach loop

i'm getting an error in this code, can someone help me. I'm trying to create two concentric cycles, but it doesn't seems to work. \def\n{10} \defn\radio{3.00cm} \begin{tikzpicture} \foreach \x in ...
2
votes
3answers
123 views

Drawing an array of nodes using the foreach-construct

I sometimes need to visualize an array-like structure with tikz. I use nodes for array elements and position the next node right of the previous one, i.e., like this: \node[draw,rectangle] (n0) ...
5
votes
1answer
134 views

Changing color in foreach

I'm trying to create a picture like this: where I have a grid and I depict the boxes shifting by colors changing. I was hoping I could achieve this effect easily in Tikz with a foreach (I am very ...
4
votes
0answers
55 views

Using dynamic bounds in a tikz \foreach [duplicate]

I'm trying to draw something like an inner box integral approximation but with dynamic upper bound, lower bound, and stepsize. Unfortunately the \foreach command of tikz is not cooperating. ...
2
votes
1answer
115 views

One coordinate a function, the other a Brownian Motion

I am new with Tikz and I have a question which I did not manage to solve looking at other posts. I was wondering how to draw a figure in 2D, in which the first component (the x) is a function of x ...
5
votes
1answer
100 views

Why is my minipage in beamer foreach environment moving horizontally?

I am preparing a presentation with several very similar slides so I would like to use a \foreach loop with \only to generate them. The frames also contains minipages and these minipages seem to cause ...
2
votes
1answer
22 views

pgffor `foreach` loop over databib macro-generated list

The databib package from the datatool bundle allows one to import BibTeX databases and work with them from within LaTeX. The author field can be accessed as \DTLbibfield{Author}, which returns data ...
3
votes
0answers
59 views

How to use \foreach and \input inside the body of \longtable?

I want to use % option 1 \foreach \x in {1,2,3}{\input{chapter-\x}} instead of % option 2 \input{chapter-1} \input{chapter-2} \input{chapter-3} to make my code much easier to read. :-) Shortly ...
2
votes
1answer
101 views

Tikz coordinate calculations inside foreach

As part of a drawing that will go with an explanation of diffraction, I want to draw the "outer rays" of a beam of light and draw several rays in between. An MWE of how I'm going about this is shown ...
4
votes
2answers
90 views

Problem with tikz foreach

I am using a foreach loop to add plots to an axis environment and want each plot to have its own color. To achieve this I tried the following: \foreach \x/\barcolor in {1/red, 2/green, 3/blue, ...
2
votes
0answers
46 views

Putting repeated symbols along a path with decorations?

I have a drawing of a curved-plate capacitor: \documentclass[]{standalone} \usepackage{tikz} \usetikzlibrary{arrows} \usetikzlibrary{intersections} \begin{document} \begin{tikzpicture}[ ...
11
votes
3answers
261 views

3n arguments in a macro (n is an even number) for curves whose thicknesses increase or decrease

For some mathematical figures it's nice to be able to vary curve thickness smoothly along a path, to reproduce hand drawn mathematical figures made with inking liners for instance. One way to do it ...
2
votes
0answers
32 views

Count the number of items in a TikZ foreach statement [duplicate]

One sometimes defines macro's for TikZ as: \newcommand{\foo}[1]{ \foreach \x in {#1} { %do something } } Thus where the argument given to \foo is used in a \foreach loop. ...
0
votes
0answers
36 views

Take input from csv file and use it to create a custom-made table in tikz

I have a csv file that looks like this: Scott, William, Todd,Esben, Martin, Jesper, Alexander W.L Right now, the names are written this line \aebuildtable{20}{Scott,William,Todd,Esben, Martin, ...
1
vote
0answers
26 views

Use pi in x labels with pgfplots [duplicate]

With \documentclass{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[samples=10, domain=0:pi] \addplot {x-sin(x)}; \end{axis} \end{tikzpicture} \end{document} ...
4
votes
1answer
105 views

Escaping special characters for use as a URL

If a url contain special characters (~ and #) using it as \href{http://people.brunel.ac.uk/~mastmmg/ssguide/set_work.html#4_32}{people.brunel.ac.uk} works just fine. But, I would like to have macro ...
5
votes
2answers
127 views

Use \foreach loop to execute macro with parameters of macro provided in a list

I have to execute a macro a number of times, and would like to provide a list of the parameters to be executed. So, instead of \FormatLinks*[Main Search Site]{Google}{http://www.google.com} ...
4
votes
1answer
72 views

Change colors of several pgfplots functions plotted in foreach gradually

In answering this question I actually caught myself unknowing how to solve the following issue. In the code below I'm dealing with many graphs, which I intend to gradually change in color based on ...
3
votes
1answer
60 views

Dynamically open and close environments for foreach construction

I am trying to iterate through a list of data. The data has sections mixed between the items. When a section appears, I need to typeset it with \section, then I need to create a itemize environment ...
1
vote
0answers
55 views

Ending a tikzpicture environment in conditional causes “Missing } inserted”

I want to create a number of tikzpictures. I have a number of items I want to draw. Each tikzpicture takes up a whole page and may contain up to 4 items. (It is not good enough to to have each item in ...
7
votes
3answers
81 views

putting figures in tabular with foreach (or an alternative)

I have a number of figures coming from experiments; they are indexed with an integer number, and they are not always consecutive. Given a list of the indexes, I need to put them in a tabular of, say, ...
4
votes
1answer
121 views

Repeating the same column type

I'm using package numprint to create a table which automatically formats its columns. However, the table has many columns. Right now, my table definition looks like this: \begin{tabular}{l n{2}{3} ...
2
votes
2answers
81 views

Include chapters using foreach

I have seperate .tex files in a directory named chapters in the main directory. I would like to include/input those. After some research a solution like the one below could be possible. Unfortunately ...
1
vote
3answers
142 views

TiKZ: place shortened arrow between every pair of points in a draw statement?

What is the simplest and most direct way of creating a sequence of arrows, like \begin{tikzpicture} \draw[->] (0,0) -- (1,0) -- (2,0) -- (2,1) -- (1,1) -- (0,1) -- cycle; \end{tikzpicture} so ...
3
votes
2answers
98 views

Tikz: foreach loop ignores part of the edges

I would like to draw some more or less advanced grid, using three consecutive (non-nested) foreach loops. For unknown reasons, the third loop seems to be ignored... Here is the code: ...
4
votes
1answer
36 views

Create commands for displaying pictures from a list of files

I have a lot of pictures to show in my document. My idea is to create one command per picture. So I try to use foreach command (maybe not the best for this...). I store the filenames and the names I ...
4
votes
0answers
71 views

TikZ: \foreach loop not executing expected number of iterations [duplicate]

I am trying to draw a Bézier curve defined by five control points following the algorithm discussed here. I generate the points of the curve with a \foreach loop: one point per iteration (also, from ...
1
vote
2answers
53 views

tikz foreach loop alignment failure

\documentclass[tikz]{standalone} \usepackage{pgf,tikz} \usetikzlibrary{positioning} \begin{document} \begin{figure}[t] \begin{tikzpicture}[node distance=0.2em] \node (T0) at (0,0) {$T_{0}$}; ...
5
votes
2answers
146 views

macro with \newcommand using foreach to create tree in tikZ

In the two examples below I use the same code in two different ways. Why is it that TikZ gets confused about who the parent node is when using the macro \department{name dept}{list of subdepts} ...
1
vote
0answers
35 views

why tikz will generate a series of .0.0.0.0? [duplicate]

I want to generate several point on a line, and this is the command: \documentclass{article} \usepackage{tikz,pgf} \usetikzlibrary{calc} \begin{document} \begin{figure} \begin{tikzpicture} % ...
8
votes
3answers
391 views

pgf plot and foreach loop

I have this function y=a*x^2 where a changes (-2.4,-2.1,-1.8,....,2.1,2.4) and i want to draw it with pgf plots. Problem is i dont know how to implement this i think i'll need foreach loop or ...
4
votes
2answers
265 views

How to include multiple pdf pages using \foreach as tikzpicture?

I know how to include pdf pages using package pdfpages and do it all the time, but always had problem with getting the page centered and scaling. I am now trying to learn how to use tikzpicture to ...
2
votes
1answer
168 views

tikz: How to pass a list as a parameter of a tikz macro and use it in a foreach inside the macro

I am trying to write a macro for drawing some graph, but since the content of each node is specific it has somehow to be passed as a list to the macro. Here is an example of an ad-hoc code of what I ...
6
votes
4answers
179 views

Incomprehensible behaviour of calc library with a “foreach variable”

If I compile the following code : \documentclass[12pt]{article} \usepackage[french]{babel} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \foreach \i in ...
3
votes
2answers
209 views

How to cut the upper part of the plot?

\begin{tikzpicture} \draw[->] (-1,0) -- (5,0) node[right] {$x$}; \draw[->] (0,-1) -- (0,8) node[left] {$y$}; \foreach \a in {0,...,5} \draw[scale=1,domain=1:3,smooth,variable=\x,purple] ...
4
votes
1answer
114 views

TikZ: How can I use \foreach variable to reference intersections?

Using the \foreach statement, I generate a set of lines that form a grid. I want to use the loop variables to name the individual paths to later draw something at their intersections. ...
3
votes
1answer
112 views

Making a random number

I have a problem. I have a graph, and I must paste a random number in every vertex of this graph. Vertices have coordinates. A part of code : \foreach \pos/\name in {{(0,0)/a}, {(1,-1)/b}, ...
7
votes
3answers
246 views

cannot combine \foreach and \draw

I just cannot debug this code. After typesetting it keeps on giving the error of: "Undefined Control Sequence" When individually coding rectangles for each set of coordinates the code works though, ...
2
votes
1answer
69 views

escape special characters in `\foreach` loop

Is there a way to escape underscores (or other special characters) in variable names in a \foreach loop when calling file names? E.g., \foreach \x in {file\_1, name\_2}{Here is \x.} gives correct ...
3
votes
1answer
99 views

How to append colored text to a macro in a loop?

I'm trying to append a couple of colored numbers to a macro in a loop. That is, I'm hoping to achieve the following but with a loop: \documentclass{article} \usepackage{tikz} \colorlet{color1}{red} ...
5
votes
3answers
151 views

Setting \tikzstyle inside \foreach

I am building a tree structure in tikz and am following this texample, which suggests adding styles for the children according to their depth in the tree (first, second and so on). The purpose is that ...
5
votes
1answer
167 views

Name pgfplotstable Column within foreach loop

I recently stumbled over pgfplotstable and its ability to process table information and create new columns. To hone my skills, I tried to create a script that would calculate an exponential smoothing ...
4
votes
2answers
333 views

TikZ: incrementing a foreach loop

I am working on plotting a random vector (X, Y) in the plane where X and Y are defined as a roll of the die and X is die1 plus die2 and Y is die1 minus die2. I am having trouble setting up a foreach ...
6
votes
1answer
402 views

Feature (bug?) of dots notation in foreach-statement

I want to draw something in tikz where the range of an inner loop depends on an outer loop (by construction of the math involved). I need to differentiate between even and odd number in the inner ...
2
votes
1answer
126 views

“indirect” variables in foreach

I'm trying to draw three "graphs" which are rectangles situated side-by-side. Each has four points to be placed on them. These four points are the "scores". Using a foreach loop is a natural for the ...
3
votes
1answer
67 views

Make catchfile work with pgffor's foreach

Consider the following MWE, extracted from my solution to this question: \begin{filecontents*}{demolist1.dat} 1,2,3 \end{filecontents*} \begin{filecontents*}{demolist2.dat} {1,0,2},{0,3},{1,1} ...