Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pgffor]

The package pgffor implements the foreach module of tikz-pgf in a standalone package.

8
votes
2answers
429 views

Why does pgffor estimate that 0.1-0=0.100005 in a \foreach loop?

In the manual on page 902, it says that Normally, when a list item ... is encountered, there should already have been two list items before it, which where numbers. Examples of numbers are ...
1
vote
1answer
43 views

\forloop problem(undefined control sequence)

(/usr/local/texlive/2018/texmf-dist/tex/latex/fontspec/fontspec.sty (/usr/local/texlive/2018/texmf-dist/tex/latex/l3packages/xparse/xparse.sty (/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/...
2
votes
1answer
38 views

Dynamic macro definition in a `foreach` loop

I created a command to dynamically define vector macros: \newcommand{\makevec}[1]{\expandafter\def\csname #1\endcsname{\vec{#1}}} which works as I expected. But then I tried to modify this command ...
2
votes
1answer
51 views

Building up and joining “internal” lists

How can I append to a pgfkeys-style comma-separated list? Or, alternatively, how can I define a macro to join an etoolbox list with a delimiter? For an environment I'm designing, I want to accumulate ...
3
votes
1answer
83 views

Alpha counter in a foreach loop

I need an alpha counter in a foreach loop : \documentclass{article} \usepackage{tikz} \makeatletter \newcommand{\TRAA}[1]{% % node/angle list \foreach \x/\y [count=\i from 1] in {#1} {% ...
0
votes
0answers
48 views

\csname problem

I try to pass a list of nodes and angles to a command, and I need to name them for a futur use, but I make a mystake that I don't understand. \documentclass{article} \usepackage{pgffor} \...
2
votes
1answer
51 views

Testing membership in a list

My question is similar to the one asked in ASdeL's question, except I am testing a loop variable against a predefined set. It seems that none of the solutions there are working for me because \imgidx ...
3
votes
2answers
61 views

Math line breaks in user defined macros

I have been defining a mathematic formula using NewDocumentCommand. This works well, but I do manage to get line breaks. A minimal working example can be found below. Part of the construction is ...
2
votes
2answers
310 views

What is wrong with this \foreach statement?

The code below \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} % draw two line segments \draw (0,0) node [below] {$s_i$} -- (2,0) node [...
3
votes
1answer
97 views

loop over list defined with newcommand

I try to automate generating same tables. With a \newcommand a comma separated list of filenames is defined. I want to iterate over these files, import them and concat them to a single table. Sounds ...
0
votes
1answer
75 views

How can I increase or decrease height between of two lines?

I want to draw some lines with dots and line. This is my code. \documentclass{book} \title{Multidotfills} \usepackage{pgffor} \newcommand{\foreachmultidots}[1]{\foreach \n in {1,...,#1}{\par\...
1
vote
2answers
79 views

How to access length of inner list in pgffor

I have a list of lists, and I'm using nested \foreach loops to iterate through them. By using [count=\var], I'm able to use \var to access the length of the outer loop (after I've iterated through). ...
2
votes
1answer
123 views

Accessing a list at a certain index

I want to define the following command, which is to render an arbitrary number of subfigures. The argument is a nested list: \multifig{{{fig_1, T0D0, TODO}, {fig_2, T0D0, TODO}}} Is the following ...
1
vote
1answer
60 views

Commands Macros within tabular environments -Automation

I want to create a table based on a comma separated data as follows: \documentclass{article} \usepackage{pgffor} \usepackage{multirow} \usepackage{float} \newcommand{\cases}{a , b} \newcommand{\...
1
vote
1answer
71 views

\renewcommand inside for cycle won't work

In the following MWE I'll be providing the command \asdasd, and then try to give it the definition "asdasd" through the command \renewcommand inside of a for cycle. I don't know what's going wrong ...
4
votes
2answers
101 views

infinite loop, csname and forloop function

I want to define some commands that finish with "a", "b", "c"... and totalize the number of them, how can I do this?? \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{ifthen} \...
5
votes
2answers
372 views

foreach LaTeX input file, output a PDF file

I have a bunch of tables saved in separate files and folders which I have compiled with a master file, commenting the name of each file in the master file one by one and tediously renaming the ...
3
votes
2answers
87 views

Table gets broken when in a loop

Here is the MWE: \documentclass{article} \usepackage{pgffor, geometry, tabu, booktabs} \geometry{ a4paper, portrait, margin=1in } \begin{document} Here is creating the table using a loop\\[...
2
votes
2answers
150 views

tasks environment vs. pgffor's foreach

I want to \foreach on a list and create task (via package tasks) inside a question. A MWE: \documentclass{article} \usepackage[magyar]{babel} \usepackage[utf8x]{inputenc} \usepackage{t1enc} \...
5
votes
3answers
303 views

Best way to loop over the value of a pgfkey key that is a csv list?

Using pgfkeys, suppose that I have a key whose value is a comma separated list: \pgfkeys{/a list/.initial = {1,2,3}} Question What is the correct way to iterate over this list using \foreach (from ...
5
votes
1answer
81 views

Need a second \end{choices} for exam class with pgf foreach?

I cannot figure out the reason for this weird occurrence. If I declare my exam to print answers, I get an error that ! LaTeX Error: \begin{choices} on input line 21 ended by \end{questions} ! LaTeX ...
1
vote
2answers
73 views

Value of counter from pgffor in a complex example

From this answer I learned how to print rows into 1 column table using pgffor: | 1 | | 2 | | 3 | Code looks like this: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{pgffor} \...
1
vote
1answer
52 views

How to get the value of counter in pgffor while using \expandafter

I looked into this answer and tried to improve it. My goal is to get this table: | 1 | | 2 | | 3 | But instead I get this: | 1 | | 1 | | 1 | Code: \documentclass{article} \usepackage[utf8]{...
2
votes
1answer
407 views

Foreach loop in tabular, missing endgroup inserted

I'm trying to create a table using the foreach loops made available in the pgffor package. Using the following code, I am able to generate the right contents, but not aligned properly. \begin{tabular}...
2
votes
1answer
63 views

\pgfforeachungrouped with three arguments

This is a follow-up to a previous question of mine, with a slight addition. I would like to loop over data in a file and give the plot styles as a list. In the old question I gave only a color and an ...
11
votes
1answer
631 views

foreach with colors leads to “undefined control sequence”

The following MWE works nicely when I remove the optional argument [\forcol] from the \addplotcommand or when I change it to red, for example. Though I would like the curves to have different colors ...
4
votes
2answers
80 views

Loading an array of fontfaces with fontspec and pgffor

I'm trying to produce a document to compare a bunch of fontfaces. I'd like to parse an array to load and try them all. This is what I have done: \documentclass{article} \usepackage{lipsum} \...
2
votes
4answers
160 views

Programming a step function- part2

Based on a macro given by egreg in this question: Programming a step function I obtain a program which tests in which interval is a number \alpha, between the numbers bone, btwo, bthree, bfour. I use ...
2
votes
0answers
236 views

How to use sagesilent (or verbatim) environment in pgffor loops?

I want to create different versions of an exam paper and corresponding sample solutions using sagetex. I need to assign variables for more involved computations, so I am reliant on the sagesilent ...
4
votes
1answer
471 views

How can I use \foreach in math environments?

I'm looking for a way to generate in a loop the rows of an align environment, or IEEEeqnarray or some such thing. I can see that \foreach works in math mode (inside \[ \] e.g.), but something like ...
3
votes
1answer
91 views

Using pgffor and line breaks inside math environments

Today I decided to try to typeset a humorous list enumerating all 7! valid iterated integrals for a 7-dimensional integral (It takes 361 pages in the version that does compile) but I'm running into ...
1
vote
1answer
29 views

error when using expandafter for databib command in indexing command in foreach loop

I'm trying to create an author index using the databib package (datatool) bundle. I can loop over the entries in a BibTeX database and for each entry, loop over the authors using the \foreach command ...
2
votes
1answer
117 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
1answer
260 views

Problem using macro with TikZ foreach

I am using a simple macro adapted from an answer to the following SO question: https://stackoverflow.com/questions/3951392/latex-space-after-every-letter The modified macro simply takes a string and ...
3
votes
1answer
92 views

mdframed gobbles item label from description environement when \foreach is used

The following works: description in mdframed. foreach in description. but there is some strange behavior when using foreach in description in an mdframed environment in that the \item labels after ...
2
votes
1answer
109 views

How do I assess the length of text within a pgffor \foreach loop [duplicate]

I would like to be able to write something like the following: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \newlength\aelengtha \newlength\aelengthb \newlength\aelengthc \begin{...
12
votes
2answers
807 views

\foreach with \newcommand how to use them together?

What I want to do is to shorten this \newcommand with a \foreach since this is just a very little part of what I will use. \newcommand{\CC}{{\mathbb C}} % the set of complex numbers \newcommand{\NN}{...
5
votes
5answers
4k views

How can I multiply two numbers?

I use pgffor package and I have \foreach \n in {1,...,10}{**something I want**} How can I print n*(n+1) for each n? When I write just \n*(\n+1) instead of **something I want**, 1(1+1)2(2+1)3(3+1).....
6
votes
1answer
579 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 loop,...
4
votes
1answer
118 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} \end{...
6
votes
1answer
640 views

Why is the `pgffor` package messing with my scope?

I have a several rather lengthy documents with numbered points (catechism questions) that I would like to be able to selectively include in other documents using a utility function that uses a range ...
4
votes
1answer
348 views

PGF foreach: elegant way to handle empty list

I am writing a simple animation in beamer using tikz. The code is as follows \documentclass{beamer} \usepackage{tikz} \usetikzlibrary{positioning} \begin{document} \begin{frame}[fragile]\relax \...
4
votes
2answers
237 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. \documentclass[...
4
votes
1answer
166 views

Extract from a token containing a list with math content

I have a token which contains a list consisting of: a date in YYYY-MM-DD format, followed by a colon, and some text which may contain math. The text will consist of a sentence or two (i.e., no ...
8
votes
2answers
766 views

Error with chronology and babel packages : “! Paragraph ended before \pgffor@next was complete.” [closed]

I am trying to use the chronology package in a report that includes babel. My distribution : pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) On below my MWE : \documentclass{article} \...
11
votes
1answer
146 views

PGF's `foreach` recognises when there are no list items and doesn't run the code. Is this guaranteed?

The PGF \foreach macro behaves differently when the item list is totally empty than it does when a single item happens to be empty. \documentclass{article} \usepackage{pgffor} \begin{document} \...
3
votes
2answers
197 views

\newcommand for bmatrix of features using pgffor throws missing \endgroup error

There are two parts to this question. Mainly, I'm interested in implementing a \newcommand that can take an arbitrary number of arguments to be set in a single column of a matrix. I tried the ...
6
votes
3answers
243 views

How to escape /None in \foreach iterator?

The last compiler to invoke is ps2pdf -dAutoRotatePages#/None frames.ps for Windows or ps2pdf -dAutoRotatePages=/None frames.ps for non-Windows. The code snippet I want to invoke is as follows. \...
28
votes
2answers
802 views

What's the difference between the various methods for producing for loops?

I've been wondering about the various methods available for looping over a comma separated list and the like. In particular, I was wondering about their various strengths and weaknesses. In other ...
6
votes
1answer
166 views

I'm confused about how expansion is happening here

I was really pleased that I could come up with a means of building the contents of a tabular environment using \foreach \x in {...} {...} structure. But I was curious about what exactly it would take ...