{loops} is about looping constructs which allow a programmer to apply the same operation multiple times, each time with possibly different parameters.

learn more… | top users | synonyms (1)

2
votes
1answer
47 views

How to iterate a list of colors with two additional counters more elegantly?

A part of my code (especially iterating a list of colors with 2 additional counters) below does not seem straightforward. \documentclass[pstricks,border=12pt,dvipsnames]{standalone} ...
3
votes
1answer
43 views

conditional loop printing text and icon

I'm new in the Latex world. I'm writing a little guide and I've choose Latex, in particular Texmaker for writing it. I'm trying to do a loop for printing some instruction as File -> Save as -> Ok. ...
13
votes
4answers
542 views

Foreach loop between two lists

\documentclass{article} \usepackage{tikz} \def\firstlist{0,1,2} \def\secondlist{0,1,2} \newcommand{\testa}{ \foreach \x/\y in {\firstlist/\secondlist} { \draw(0,\x)--(1,\y); } } ...
2
votes
1answer
64 views

Iterate over pages and set variable

I am looking for a way to take the output of a pageref, iterating through, and assigning a property to each of those pages. Specifically, I want to take this: \documentclass{article} ...
0
votes
1answer
24 views

Strange extra line after forloop in a tabular table

I'm trying to generate table lines (tabular environment) with forloop macro. I've got strange extra line after forloop. \documentclass {article} \usepackage [utf8] {inputenc} \usepackage [english] ...
3
votes
1answer
50 views

Package to run multiple iterations of a variable, with compilation?

I guess this is somewhat similar to Animations in LaTeX, except what I would want is something like this: Say you have a .tex document, which uses some macro \tester as parameter. I'd like to load a ...
1
vote
1answer
46 views

Loop through table for boxplot prepared

I am trying to produce figure with 2 boxplot prepared plots from an inline data file. I grabbed this code from here to use as a starting point. Given that the wrapper code allows the boxplot data to ...
10
votes
7answers
1k views

Iterating through two lists

I have two comma delimited lists: ListA(a,b,c,d,e,f,g) and ListB(name1,name2,name3,name4,name5) I would like to iterate through both lists at the same time, something like: loop readvalue ...
6
votes
0answers
51 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, ...
3
votes
2answers
124 views

Pascal's triangle in tikz with row headers

I am interested in creating Pascal's triangle with Tikz and LaTeX. I would like to add a column of text on the left of the triangle, with header "Row Number" and then the entries of each row. I am new ...
4
votes
1answer
66 views

loop macro fails if wrapped in conditional

The following code is a subset of the answer in this question. The code provided in the answer works fine, but fails if I add a conditional \IfPackageLoaded. I post this error as a new question, ...
2
votes
2answers
36 views

Undefined Control Sequence \For, \state, or \EndFor

I want to write this algorithm but the error Undefined Control Sequence \For, \state, or \EndFor pops up. \documentclass[titlepage,oneside,12pt]{article} \usepackage[]{algorithm2e,algpseudocode} ...
1
vote
1answer
54 views

\pgfdeclareshape: how to define anchors in a loop?

I think my question is quite similar to this and this, however I didn't manage to modify the provided solutions to fit my problem. In the following MWE I am trying to define 8 pin anchors in a ...
6
votes
1answer
175 views

How do I implement a string buffer in TeX?

I've recently learned how to create a macro to iterate over a token sequence using \afterassignment and \let in TeX. Currently, I'm trying to apply this to a tokenization macro (where "tokenization" ...
6
votes
1answer
87 views

PGF loop - how to use an array inside pgfmathdeclare function?

I'd like to pick a number from my array inside a loop. The first argument is a "starting" value which increments by 1 for each iteration based on the second and third argument (\qa). The maximum ...
2
votes
1answer
72 views

Use array in loop in tikz

In general: I need to retrieve values from an array to submit those values as indices to a function. More specific: I want to create figures, which contain subfigures. These subfigures are loaded ...
7
votes
1answer
64 views

Generate automatic revision's numbering tabular

Situation I have to make a cover template for a document. At the end of the page, I have to add the revision number with other useful info like this example: \begin{tabular}{lccl} Revision 0 ...
7
votes
1answer
75 views

Passing values to a command

I am new to Tikz and have been largely following the PGFManual to learn about how to use it correctly. The PGFManual shows examples of using foreach but they do not show how to pass it to a command. ...
4
votes
2answers
46 views

Print all elements of a working array created with etoolbox package

I am trying to define an array to contain elements and stumbled across the following code and it works. The question is how I can define a command which will print all elements at once without ...
2
votes
2answers
92 views

Insert loop inside table?

1- I want to make a table with n number of rows ? my wrong code \newcommand{\xx}{ \begin{tabular}{|c|c|c|} \hline \newcount\fooo \fooo=10 \loop 11 & 12 & 13\\ \hline \advance \fooo ...
2
votes
0answers
57 views

Passing an array type argument for new command

I've looked around and can't seem to find anywhere, but I was wondering if there is somewhere you can do something like the following: \newcommand{\loopy}[1]{ \begin{tikzpicture} \foreach ...
2
votes
1answer
50 views

Does \foreach \x in {1,2,3…} have a limit for the {1,2…} number of elements?

I have the following code which prints some images labelled by _{1,3,5...,37}.png. The following code works just fine. \usepackage{tikz} \foreach \x in {1,3,5,7,9,11,13,15,17,19,21,23,25} { ...
3
votes
1answer
38 views

Using \pgfplotsinvokeforeach in foreach loop

I am trying to run a \pgfplotsinvokeforeach loop in a \foreach loop to plot the variables var1_roll1 - var1_roll10 in one plot and var2_roll1 - var2_roll10 in another. Both loops work fine ...
3
votes
1answer
56 views

making multiple tables with for loop

I have a following problem: I need to create a multipage document, containing single table on each page. The table is same for all pages, pages differ from each other by page number only. To make the ...
3
votes
3answers
96 views

Declaring variables and writing loops

My exam template includes a table listing the point values for each problem in the exam. Is there a way to declare the point values of each problem as variables within latex and write code to ...
4
votes
1answer
93 views

Using knitr, beamer, and /foreach to produce unique section titles in pdf from R string variable

Using R, knitr, and beamer, I have created a pdf that contains a graph for each school in our district. I read in each graph using the \includegraphics command within a /foreach loop. I want to ...
8
votes
2answers
52 views

“Extra \else” and inserted “\inaccessible” when using textbf with pgffor

I'm getting errors whenever I try to make \textbf interact with pgffor and xparse. Here's an MWE that gives ERROR: Extra \else and ERROR: Missing control sequence inserted at the end of the \coljoin ...
1
vote
1answer
46 views

Centering a table of images

I'm trying to center a table of images; 2 images per table row. Right now the code I have is ugly, and doesn't center on the document. I've tried using \begin{center} and \centering without any luck. ...
3
votes
1answer
50 views

makeidx, xstring, forloop and utf8 conflict

I'm using Danish characters in strings that I split with \StrCut from the Ă—string package and use within a \forLoop from the forloop package. The result is not good. Consider this small example: ...
6
votes
2answers
340 views

Problems using \addlegendentry in a loop with pgfplots

I have some spectra to plot, which I exported from the Siemens Xray toolbox, which works nicely with pgfplots. Since these are multiple files that look the same I think I can do it with a for loop, ...
3
votes
2answers
115 views

Loop with tikz index problem

I need a loop that ends with a test, why this one doesn't work and how use an index in this kind of loop ? \documentclass[tikz]{standalone} \usepackage{} \usetikzlibrary{} \begin{document} ...
3
votes
2answers
61 views

Typeset R character vectors

I have two vectors in R that I want to typeset. The first vector includes the titles and the second the body texts. Please consider the following MWE \documentclass{article} \begin{document} ...
3
votes
1answer
70 views

Build tabular content via \foreach

I am trying to build up tabular data using the solution at How do I use the ampersand (&) inside a foreach or conditional (or other group/environment) when building tables?, but not having any ...
8
votes
2answers
266 views

Preparing macro content in a loop (calling \foreach from \edef)

I need to do something like \def\MyArray{{1, 2, 3, 4}} but with a dynamical number of elements. The following command makes the string: \newcommand{\MakeArray}[1]{\{ 1 \foreach \x in {2, ..., #1}{ , ...
8
votes
2answers
168 views

How does expansion matter?

\newcount\@repeat% \def\repeat#1#2{% \@repeat#1\relax% \ifnum#1>\z@\relax% \advance\@repeat by -1\relax% \repeat{\@repeat}{#2}#2% \fi}% \repeat{2}{1}\\% \repeat{11}{f}\\% ...
4
votes
1answer
58 views

TikZ: issue with lines in foreach loop

\documentclass[tikz]{standalone} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \coordinate (h) at (0, 3); \coordinate (O) at (0, 0); \draw (O) -- +(-3, 0); \draw[-latex] (O) -- ...
5
votes
1answer
76 views

\foreach not behaving in axis environment

Am hesitant to ask yet one more embarrassing question, but I can't seem to see the problem with the \foreach in the MWE. It should produce several horizontal lines but only produces the one with the ...
3
votes
1answer
53 views

Beamer and a for each loop

I'm using the beamer presentation package and trying to combine the examples from this post How to iterate over a comma separated list? with the beamer package. In modifying the top example, chaning ...
3
votes
1answer
72 views

Latex - figures side by side using loop

I am trying to put 6 figures in 3rows & 2 columns: \foreach \x in {1,2,3,4,5,6,7,8,9,10,11,12} { \begin{figure}[h] \caption{This is the caption.} \vspace{0.0cm} \centering \includegraphics[height ...
0
votes
0answers
17 views

Figures in latex using loop [duplicate]

To put maximum of 6 figures in 3 rows & 2 columns in a A4 page using loop, I tried like: \foreach \x in {1,2,3,4,5,6,7,8,9,10,11,12} { \begin{figure}[h] \caption{This is the caption.} ...
6
votes
4answers
224 views

How to fill a dynamically generated table with dynamic content?

how do I generate a tabular dynamically while filling it with dynamic data? Example: Let's say I have \def\N{10} and I want to generate a table with \N columns, where the top cell of each column ...
7
votes
1answer
66 views

How to add a \global before \pgfmathsetmacro?

It seems that one can't add \global before a \pgfmathsetmacro as that yields: You can't use a prefix with `\begingroup'. But that is the functionality I need here. I am trying to compute the ...
34
votes
10answers
2k views

How to iterate over a comma separated list?

How can I iterate, loop, process, or otherwise do something, with each element from a comma separated list of things? This question has been asked perhaps many many times, and the are already lots of ...
5
votes
1answer
155 views

Three loop diagram

I want to make a three loop diagram such as the one on the left. I use the following script \fmfleft{i}\fmfright{o} \fmf{boson}{i,v1}\fmf{boson}{v2,o} ...
4
votes
3answers
163 views

Creating commands with a TeX `for` loop

I am trying to create many different commands based on a single command (essentially a custom header) in a predictable way. Is there a way to do this in TeX/LaTeX? My specific example: I'm writing a ...
7
votes
2answers
110 views

\foreach from 1 to 1 [duplicate]

How to make a command (without testing) that contains a foreach loop that may count from 1 to 1 if necessary ? \documentclass{minimal} \usepackage{tikz} \newcommand{\boucle}[1]{% \foreach \x in ...
8
votes
2answers
190 views

How to make a portion of curve red using TikZ?

I want to make the the closed loop part of the figure by "ultra red" color only and the other part by blue. (from (2,0) .. (0,0.93) .. (-0.93,0) .. (0,-0.93) .. (2,0)) \documentclass{standalone} ...
5
votes
1answer
233 views

Plotting loops: trajectories and directions

Plotting loops: trajectories have directions. How to plot the following figures using tikz 1st I start to plot the 2nd fig using the code \begin{tikzpicture} \draw (3,2) ellipse (.5cm and ...
2
votes
1answer
170 views

Dynamic table column generation

I'm trying hard in finding a way to streamline my table generation. As you can see in the attached code, the problem is related with the code "\@for \el:=#1\do{\textbf{\el} &}", where "&" ...
0
votes
1answer
31 views

Forloop macro does not work with other macro in condtion

This is my primative code: \documentclass{article} \usepackage{xstring} \usepackage{ifthen} \usepackage{pgfkeys} \newcommand{\setvalue}[1]{\pgfkeys{/variables, #1}} ...