Questions tagged [loops]

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

Filter by
Sorted by
Tagged with
2 votes
4 answers
83 views

Loop to input content into tabular

I'm trying to input files that represent rows of a table into a tabular environment using a loop, but I'm having trouble using input. Here is a MWE of my code without using loops. I have files with ...
Nicolas Suarez's user avatar
2 votes
1 answer
28 views

Iterating over a list and conditionals in tabular environment not working. Incomplete \ifnum; all text was ignored after line 72

i work on a project with a lot of people and there are many who are not really familiar with LaTeX. Therefore, I have to define a command (\timeplan{}), which simplifies coloring tablecells (each ...
Viggo's user avatar
  • 23
5 votes
6 answers
368 views

Partition string in substrings of equal length and iterate through them

To avoid the XY problem, I'll describe what I am looking for (the X) and the issue that I found while attempting X (the Y). To be clear: I'm not trying to troubleshoot Y, I'd be grateful if only X is ...
rdrg109's user avatar
  • 575
3 votes
3 answers
146 views

Define a new command as a loop of existing Latex commands

I want to define a new command, which is a composition of commands already defined within the \csvsimple package. Therefore I've written the following code, which correctly works for my purpose: \...
MattiaP's user avatar
  • 43
1 vote
2 answers
50 views

Table csvreader: loop over columns

I have a csv file called "data.csv" containing the following data: 1,2,3 4,5,6 I am writing the following table in Latex by using \csvreader: \begin{table} \centering \begin{tabular}{|c|c|c|}...
MattiaP's user avatar
  • 43
1 vote
1 answer
38 views

Doubt about \pgfplotsinvokeforeach

I was using tikz and I had a problem using \draw[] inside a \foreach loop, so I found \pgfplotsinvokeforeach and I have doubts about how it works. This is an example \documentclass{article} \...
Michael Rosales Vilca's user avatar
0 votes
3 answers
79 views

Creating newcommands using a loop

I am currently writing a reader and have to write a lot of sub & superscripts so I have written a function % Define the electric field vector \NewDocumentCommand{\vE}{O{#1} O{#2}}{ ...
DTM's user avatar
  • 3
4 votes
2 answers
212 views

Repeat the same TikZ graphic to fill the entire page

What I'm trying to do I am creating some handwriting drill sheets. In these sheets, the exact same pattern is repeated horizontally and vertically over the entire page. The following 3 images were ...
rdrg109's user avatar
  • 575
0 votes
0 answers
24 views

Repeat characters n times to fill the current line [duplicate]

In this answer, someone provides a macro for repeating a string a given number of times. Here's a minimal working example of that macro: \documentclass{article} \makeatletter \newcount\my@repeat@...
rdrg109's user avatar
  • 575
2 votes
1 answer
54 views

How to concatenate a variable with string in tikz for loop?

Is it possible to concatenate a TikZ loop variable with a string? For example, consider the following tikzpicture \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \...
jII's user avatar
  • 497
1 vote
1 answer
67 views

getting automatically the initials of names

This sounds like some basic stuff, and yet I cannot manage to find a solution, packaged or native. I have documents with people who have from 2 to 4 names (typical Danish name could be Søren Jens ...
22decembre's user avatar
3 votes
2 answers
87 views

passing argument to \includegraphics inside \foreach loop

I am trying to define a loop to create 4 of my slides in a Beamer presentation. Each slide will have a figure. A minimal example is below: \documentclass{beamer} \usepackage[utf8]{inputenc} \...
Rigel F. do C.'s user avatar
2 votes
1 answer
55 views

Name \pic object using loop variable

What is the good way to name \pic object when \foreach variable is used? I use the variable in \foreach as part of the node name. If I do not using local bounding box, then there is no shape name ...
CNDominic's user avatar
1 vote
1 answer
107 views

How to make a loop-generated table depending on the outcome of a calculation?

As a Dutch teacher my grading scale goes from 1,0 to 10,0. The calculation of the grade depends on three variables: the N-term; the score of the student; the total number of points for the exam. I ...
KenAdams's user avatar
  • 139
0 votes
1 answer
38 views

simplest way to access element of list inside loop

I would like to access the elements of a list inside a loop. Here is a minimum example: \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage{multicol} \usepackage{pgffor} \begin{document} \...
Rigel F. do C.'s user avatar
1 vote
0 answers
46 views

How to graph a series defined function like $\sigma_{n=0}^\infty (-1)^nx^n$? [closed]

I want to graph, for example, this function: $\sigma_{n=0}^\infty (-1)^nx^n$.
amanullah nabavi's user avatar
0 votes
1 answer
53 views

loop in tabular environment

I am trying to create a table depending on the size automatically. There is kind of a proliferation of loop commands in LaTeX, which makes it hard to figure out which one is suitable. I tried plain ...
Nathanael Skrepek's user avatar
3 votes
4 answers
563 views

How can I write a LaTex command with 'if'-'then'-'else'?

I read LaTeX \if condition and How to write if and then in algorithm?, but so far it did not ring a bell for me. I am trying to create a command named dottedSkill like below. The logic behind it is: ...
Daniel Ferreira Castro's user avatar
2 votes
1 answer
60 views

Draw a circle with arrow on it to indicate loop

As shown in the pic, I already have three nodes and arrows connecting each other. The arrows form a loop and I want to add a circle with arrow on it(perhaps with text in it) inside the triangle area ...
River's user avatar
  • 23
1 vote
0 answers
51 views

Setting and displaying date ranges extracted from filenames in the header

I already asked a related question about this topic some months ago. However, I have a project with this structure: Project: |- main.tex | |- pages |- 20230101.tex |- 20230102.tex |- ...
Lorenzo's user avatar
  • 77
4 votes
3 answers
185 views

Expl3 to simplify expansion issues with loop-built Tabularray content

A follow-on from my previous question answered thanks to @egreg. (Perhaps Prof. Gregorio would be able to help me here too.) Situation I am creating a Table of Questions (ToQ) macro for creating ...
Timtro's user avatar
  • 1,430
1 vote
1 answer
47 views

Missing number, treated as zero error when using for loops and conditionals in tikz

I would be nice to be able to have a code that, by modifying certian parameters like height and width and cells to be colored red or green, generates a table for me. The code I have is already a ...
Ben Thomas's user avatar
0 votes
2 answers
74 views

Iterate with forloop instead of foreach [closed]

I have this {C/4/a/n,D/4/b/n,E/4/c/n} This is how I iterate it with foreach: \foreach \x\y\w\z in {C/4/a/n,D/4/b/n,E/4/c/n} { \x - \y - \w - \z } But I need to do it with forloop. It is ...
Arturo Rodas's user avatar
3 votes
3 answers
577 views

Repeat a pattern until the page is filled

General overview I make Chinese grids for handwriting exercice. The goal is to use the maximum space given in A4 page (with 1cm margin). MWE For the moment here is my code: \documentclass[a4paper]{...
fauve's user avatar
  • 2,511
4 votes
3 answers
187 views

Fill in the table automatically with numbers with a certain step

Let me give you an example of how I started to solve this problem (but without success): \documentclass[a4paper,12pt]{article} \usepackage{caption} \usepackage{colortbl} \usepackage{ifthen} \begin{...
Антон's user avatar
2 votes
2 answers
73 views

LaTeX does not finish compiling (infinite loop, maybe) when I place multiple \tl_use commands inside the \bool_until_do loop

I am trying to retrieve data from a .aux file using expl3. I want to ignore the first line because it serves a different purpose (hence the \ior_str_get:NN \l_seccion_lista_ior \l_tmpa_tl). The ...
Jonatán O. Perren's user avatar
2 votes
3 answers
214 views

How to set up a sequence of clips in TiKZ with a loop?

Here's the simplest file I can think of which demonstrates my problem: I simply want to draw two circles, half filled: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} ...
Alasdair's user avatar
  • 5,257
1 vote
3 answers
101 views

Why doesn's naming coordinate with \foreach iterator work inside axis environment?

Without the axis environment, we can write something like this \documentclass[beamer,crop]{standalone} \usepackage{pgfplots} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \foreach \...
Rubem Pacelli's user avatar
0 votes
0 answers
60 views

Unknown function `corner' in for-loops

I would like to draw this graph: each side of the regular pentagon is replaced by five circular dots. \documentclass[border=1mm]{standalone} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \...
licheng's user avatar
  • 773
4 votes
3 answers
86 views

Changing value of an array inside foreach doesn't effect the array outside of foreach

Editor: TexMaker Tex distribution: Latex I have a foreach statement, and I'm changing some of array cell's values inside of the foreach block. But it seems that the changes have not applied on the ...
z.ghane's user avatar
  • 51
0 votes
2 answers
48 views

Algpseudocode, for-next loop: control variable in next line

In this pseudo-code excerpt, is it feasible to add a new argument for the variable v with a syntax like \ForAll {$v$}{$v \in V(G)$} to get the output next v? \documentclass{article} \usepackage{...
Jh0an1 Uzca73gu1's user avatar
1 vote
3 answers
132 views

Storing a series of tokens for later evaluation

Is it possible to expand the tokens in a string as though they were typed at that point in the source file? I'm trying to do something like this: \begin{vmatrix} \@for\tmpone:=a,b,c\do{% \def\...
karlh's user avatar
  • 640
0 votes
0 answers
20 views

Problem with Multiple Dotted Lines using Loop Repeats

I am trying to use the "loop repeat" to write multiple dotted lines as follows. \documentclass{article} \usepackage{amsmath} \usepackage{arydshln} \setlength\dashlinedash{0.3pt} \setlength\...
Howardli621's user avatar
2 votes
2 answers
86 views

Conditionals in \foreach loops

I drew a ruler using the MWE below then I realized that It draws each medium (5 mm step) vertical line over the small ones (1 mm step) and each large (numbered) vertical bar over both medium and small ...
Brasil's user avatar
  • 1,286
2 votes
0 answers
45 views

Automatic distribution of data onto groupplots with violinplots

I am rather new to latex and pgfplots, but have to plot a rather complicated plot. I need a set of (120+) violinplots and it would be great if I could provide the data from a file (in any format, ...
LocalHorst's user avatar
6 votes
1 answer
115 views

How to use for loops in a custom command?

I have this nice code snippet to generate a DI table for integration by parts: \documentclass{article} \usepackage{xparse} \usepackage{amsmath} \usepackage{tikz} \usepackage{pgffor} \usepackage{...
Shai Avr's user avatar
  • 715
1 vote
2 answers
61 views

Iterate over list with xparse

I have this code with xparse package \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\addexercise}{m m m} { \prop_gput:Nnn \g_exercise{ #1 } { {#2} {#3} } } \...
user69507's user avatar
2 votes
2 answers
189 views

How to use loop for creating defined number of newcommands counting authors

For my template I want to create possibility to define a number of authors and automatically create a respective number of variables/commands which save the name of any author and make it able to ...
lukeflo's user avatar
  • 1,555
0 votes
0 answers
51 views

Alternatives to Pattern Fill with Alignment Function

It is well documented that the origin position of a TikZ pattern cannot easily be changed as the pattern is essentially drawn on an invisible canvas behind all the elements so that it aligns within ...
Harry's user avatar
  • 938
0 votes
1 answer
99 views

Reset tikzmath variable in for loop

I want to draw multiple curves (each with a different slope) using tikzmath coordinates: \begin{tikzpicture} \begin{axis}[ xmin=0, xmax=1, ymin=0, ymax=1, width=\textwidth, ...
segfault's user avatar
  • 103
1 vote
2 answers
67 views

Better way to subfile multiple files with similar titles?

I have a set of lecture notes and each lecture is contained within a subfile, and the main file contains a list of all the lectures like so: \subfile{lec-1} \subfile{lec-2} % more files labeled lec-X \...
Revise's user avatar
  • 365
1 vote
1 answer
69 views

While loop leads to `Missing number, treated to zero` with latex3

I am trying to learn latex3 to write more powerful LaTeX functions. For that I am implementing a timesum variable that contains the time in minutes. You can add to that sum either hours days or ...
mrCarnivore's user avatar
  • 1,505
2 votes
1 answer
74 views

Writing a for loop that iterates through filenames in a text file

I would like to create beamer slides where each slide contains an image. I have a file that contains a list of all the image locations. This is my code: \documentclass{beamer} % Import necessary ...
Michal's user avatar
  • 123
5 votes
2 answers
223 views

It is possible to make point as one variable?

I trying to run this code: \begin{tikzpicture} \foreach \n/\p in {b/(1,1),c/(2,1)} \node[draw,circle] (\n) at (\p) {}; \end{tikzpicture} % This is *not* working And I got error. I'm ...
heblyx's user avatar
  • 2,591
1 vote
2 answers
37 views

Unable to generate and align looped boxes in an axis co-ordinate system

I am trying to generate set of boxes (using loops) inside a coordinate system. Here are my MWEe: MWE1 \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \...
Ginko-Mitten's user avatar
0 votes
1 answer
68 views

Grouping mismatch if loop is dissolved

I am sure that I overlooked something very obvious. Still, why does the example in this nice answer work, but if I remove the loop, I get an error about a grouping mismatch? Consider the following ...
Jasper Habicht's user avatar
41 votes
9 answers
2k views

How to make an \egreg command?

I would like a command \egreg which produces “egreg”. However, there is no reason to limit yourself to one “reg”. Who knows, maybe one day you just feel like writing “egregregregreg" for some ...
Gaussler's user avatar
  • 12.8k
3 votes
4 answers
485 views

Drawing a train of arrows with tikz and foreach loops

I am trying to draw a series of random arrows, each starting where the prior one ended, using tikz. I use polar coordinates and remember. From a logical standpoint, I feel like the following code ...
manuel459's user avatar
  • 319
1 vote
1 answer
122 views

How to loop calendar files for my filofax organizer

Sometime ago I've found a really nice snippet for creating Filofax (tm) organizer A5 calendar pages -- sadly I could not find the original source anymore. Subsequently I've modified it and now I'm ...
alex's user avatar
  • 985
1 vote
1 answer
43 views

@for loop variable name printed instead of contents in tabbing environment

I'm trying to automatically generate some indented lines using the tabbing environment and a @for loop. For some reason, this results in the for loop printing the name of the iteration variable over ...
Svalorzen's user avatar
  • 296

1
2 3 4 5
16