{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

3
votes
0answers
35 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
143 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 ...
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
98 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: ...
6
votes
2answers
347 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
116 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
126 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
135 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
116 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 ...
2
votes
1answer
103 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
91 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
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
48 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
37 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
106 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
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 ...
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
75 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
405 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
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
84 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
122 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
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
333 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
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: ...
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
143 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
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} ...
2
votes
1answer
485 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
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
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 ...
11
votes
3answers
255 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
127 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 ...
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} % ...
6
votes
4answers
181 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 ...
8
votes
3answers
399 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
267 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
170 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 ...
3
votes
2answers
210 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
116 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. ...