{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)

3
votes
2answers
49 views

Loops and Tables

I'm trying to use LaTex to produce our family diary for next year. It's a page per week with a column for each person. I have the basic layout working: \documentclass[10pt]{article} ...
4
votes
1answer
59 views

incomplete ifnum

I am using a loop to define keys with the xkeyval package, as well as to actually read out the keys inside some self-defined command. Everything works perfectly - but for some reason, as soon as I ...
2
votes
3answers
54 views

Concatenating commands with arguments in a macro?

I want to read some lines from a text file, wrap a "style" which in this case is \texttt around each line, and as such concatenate it to a macro that I can use in the document. I came up with this ...
4
votes
1answer
29 views

Defining xkeyval keys within a loop

I have a project for which I make extensive use of the great xkeyval package. However, I'm still struggling with some more extravagant things. For example, I want to use enumerated keys (key1 to keyN, ...
3
votes
1answer
77 views

tabular environment: incrementing the headings

Is it possible to let LaTeX increment the headings in a table environment? If so, how could I do this? For example, I would like to have 7 columns and 7 rows where the columns except the first are ...
0
votes
0answers
39 views

`pdfpages` `\includepdf`'s page list input options

I'd like to use pdfpages to make a print layout of my documents, in order to print them in A4 paper, but with 2 pages per page. The problem is setting the page order in a way I can cut the printed A4 ...
5
votes
1answer
104 views

Creating procedurally generated nodes in TikZ

I am relatively new to TikZ, and have been hacking together figures as I need them for uni assignments from various examples on the internet. Now I am moving into research, I am having to write a lot ...
5
votes
3answers
185 views

Defining a command with variable number of primes

I want to construct a new command which allows me to write somthing like: \env{3} Which would then expand to: σ''' I.e. a sigma with the specified number of primes. I however have not been able ...
8
votes
5answers
392 views

A command which concatenates a string an arbitrary number of times

I'm trying to define a command \repeatstring{#1}{#2} which repeats the string #2 #1 times. Here is what I tried: (it is based on what I found in How to concatenate strings into a single command?) ...
9
votes
1answer
164 views

Cover whole page with squares arranged in a “spiral”

I'm trying to cover a whole landscape A4 paper with small squares – drawn in TikZ – starting from the bottom left corner of the page and moving towards to the center of the page in a ...
3
votes
1answer
64 views

Loops in dot2tex. Or easely draw complex graphs

My original question : Is it possible to use loops in dot2tex? I would like to type something like: \documentclass[]{article} \usepackage{tikz} ...
9
votes
3answers
223 views

Completely expandable loop macro that also works in tabular

Since I normally use tikz in my documents, I mostly use the \foreach \x in \list loop to repeat things. However, this famously fails in tabular environments and also everywhere where things must be ...
4
votes
1answer
989 views

Simple if statement latex

Having difficulties understanding basic latex operations I want to use: if not (number between x and y): next iteration in loop Can anyone help me with a simple if statement for this? \newread\reader ...
2
votes
1answer
67 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
65 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. ...
16
votes
4answers
634 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
2answers
57 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] ...
2
votes
1answer
97 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} ...
6
votes
0answers
79 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, ...
5
votes
2answers
342 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
76 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
82 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
82 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
187 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" ...
4
votes
1answer
90 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
99 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 ...
2
votes
1answer
123 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
80 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 ...
6
votes
1answer
117 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 ...
7
votes
1answer
93 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
61 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
151 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
98 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
56 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
89 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
78 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 ...
8
votes
2answers
66 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 ...
4
votes
1answer
228 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 ...
1
vote
1answer
54 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
67 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: ...
3
votes
2answers
142 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
90 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} ...
4
votes
1answer
99 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 ...
3
votes
3answers
124 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 ...
8
votes
2answers
169 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
79 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
116 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
57 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
107 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 ...
6
votes
4answers
359 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 ...