{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
56 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
14 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
39 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
52 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
70 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
31 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
244 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
31 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
22 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
22 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
87 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
104 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
53 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
53 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
44 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 ...
6
votes
3answers
72 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
91 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
71 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
115 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
90 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
35 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
63 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
42 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
130 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
322 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
211 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
138 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
150 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
191 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
102 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
108 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
238 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
53 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
90 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
139 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 ...
4
votes
1answer
133 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
304 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
393 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
114 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
64 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} ...
4
votes
3answers
297 views

TikZ picture error: No node named n1 is known, inside a \foreach loop

I get the following error: ! Package pgf Error: No shape named n1 is known. when I try to compile this code. \documentclass[border=1mm]{standalone} \usepackage{tikz,pgfplots} ...
5
votes
3answers
79 views

How can I get pgf's foreach to iterate over the contents of an input file

I would like to write something like: \foreach \myline in {\input{filehandle}} {\dosomethingwith\myline} If I have an outside_file.tex: this, is, the content, of, a file and then try to pass it ...
0
votes
0answers
22 views

Insert all the files in a directory [duplicate]

I try to import automatically in my tex file all tex files contained in a directory. The file name is arbitrary (no number) for now, I get a list of files that I put in a foreach loop, as shown in ...
7
votes
1answer
553 views

Tikz binomial distribution

I'm trying to plot the pmf of the binomial distribution for particular values of N and p. For example, when N=10 and p=0.5: \documentclass{article} \usepackage{amsmath} \usepackage{pgfplots} ...
3
votes
1answer
192 views

two variables foreach loop problem

I want to draw a pulse train on which I write some information like the corresponding angle, etc... But I think I've got a problem with the two variables foreach loop because I can't even compile ...
3
votes
0answers
93 views

Variable in \foreach,

I would like to show you my problem. Here you have the script to generate a picture.Now I need to generate a second picture in which the arrows are not equally spaced any more. ...
8
votes
1answer
138 views

drawing path in foreach loop with pgfsetmacro

I have N points on a circle, I want to draw the intersection of the convex hulls of all sets of N-k consecutive points. The points are not evenly spaced. The values of N and k (and the actual angles ...
5
votes
2answers
234 views

How to use \x from \foreach loop in the parameters of \draw in tikz

In order to make it simple, I want to draw concentric circles fading out with something like \foreach \x in {1,1.5,...,4} \draw[color=black!{100-10*\x}!white] (0,0) circle (\x); The problem is I ...
2
votes
1answer
124 views

Calculate label angle from a value list

As a beginner of tex and tikz i stuck on array handling together with foreach. I would like to draw two circle with text along its circumference. \documentclass[tikz]{standalone} ...