{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

2
votes
1answer
68 views

Print iteration counter in for loop

I am new using for loops in latex, and not sure if the following is possible. This is basically what I am trying to achieve: \documentclass{article} \begin{document} \foreach \x in {a,b,c} { ...
5
votes
3answers
88 views

pgfplots: use foreach inside addplot

I want to add a bunch of evenly spaced vertical lines to a plot using \foreach. I can do it like this: \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.10} ...
1
vote
1answer
32 views

How can I use \foreach to place nodes in a pgfplots axis?

I am trying to foreach over some coordinates to place nodes at whilst inside an axis environment. I followed the advice here, but I am getting nowhere; the following fails with error ! Argument of ...
0
votes
1answer
40 views

Insert pdf pages side by side

I have two versions (A4 size) of a document: new.pdf and old.pdf. I'd like to share with co-authors a pdf with pages side by side, so should be easy to compare the changes in the output. Here ...
1
vote
1answer
54 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} ...
6
votes
5answers
300 views

How can I draw several polygons on the same base line using TikZ?

I want to construct a figure that will be symmetrical polygons on the same base. So, there is an equilateral triangle, a square, a pentagon, a hexagon, etc. one side of all these is the same ...
0
votes
1answer
65 views

How to color multiple plots in rainbow colors?

I´m trying to color multiple curves of a line in rainbow colors wiht tikz. I´ve found the [wave] option for color from the xcolor pagacke, but I can't get it to work inside tikz's draw command. ...
3
votes
1answer
98 views

tikz foreach calculations

I am trying to do a simple calculation with the tikz foreach, but it does something very suprising: \documentclass{article} \usepackage{tikz} \usepackage[active,tightpage]{preview} ...
3
votes
0answers
46 views

trying to load images with foreach

Im trying to load images from a directory but I cant because I dont know why \i does not indicates the number, code searches the directory and the files were not found.. \documentclass{beamer} ...
2
votes
2answers
150 views

Accessing value in forloop

This code is not compiling and creates an error "Missing number, treated as zero". \newcounter{x} \forloop{x}{0}{\value{x} < 5}{ value is \value{x} \\ } How can the value of x be printed ...
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 ...
14
votes
2answers
6k views

simple arithmetic on index of foreach statement in tikz

Is foreach really a tikz statement or is derived from some other package? I would like to draw a horizontal axis with 7 ticks spaced 1 cm apart. I'd like to place a label under each tick that is the ...
3
votes
2answers
104 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
101 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: ...
6
votes
2answers
358 views

Complex Count in \foreach for number line

I am looking to create simple number lines. I have asked a similar question: Resetting numerical labels in \foreach commands on a numberline. But now I am in a different situation. I know how to ...
5
votes
1answer
128 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
142 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
152 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
118 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
114 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
24 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 ...
2
votes
1answer
127 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
96 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, ...
11
votes
3answers
262 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
53 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}[ ...
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
47 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
115 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 ...
3
votes
1answer
64 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 ...
5
votes
2answers
139 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
89 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 ...
9
votes
2answers
421 views

An application of \foreach command in TikZ to generate labels

I would like ask you to help me solve the following application of \foreach of the TikZ package. By means of the following code: \documentclass{article} \usepackage{tikz} \begin{document} ...
1
vote
0answers
59 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
88 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, ...
5
votes
1answer
141 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
1answer
76 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
350 views

pgfplotsforeachungrouped in groupplot

I want to create a grid of plots with groupplots, where every plot is taken from an external file and included via pgfplots. Due to the fact, that foreach doesn't work nicely in a axis environment, ...
3
votes
2answers
102 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: ...
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
153 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 ...
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 ...
5
votes
2answers
153 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} ...
2
votes
1answer
519 views

Generate table using the foreach command from pgffor [duplicate]

I want to generate a table from a list. However for some reason it fails to work. I searched: PGFplots foreach equivalent to TikZ's with multiple variables separated by a slash Copy table row n ...
4
votes
0answers
72 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
54 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
3answers
155 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 ...
11
votes
3answers
268 views

tikz foreach loops: is there an equivalent of metapost's step?

I apologise if I'm using and searching with incorrect terminology. This seems an obvious question (to me) so I'm surprised I've not found anything (and so assume I'm missing something). In metapost, ...
2
votes
1answer
131 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 ...