Tagged Questions
3
votes
1answer
55 views
PGF's \foreach when list requires completion
Please is there anything I am doing wrong that PGF's \foreach is failing here?
\def\alist{}
\foreach\x in {%
2pt_A,4pt_A,...pt_A,10pt_A
}{%
\xdef\alist{\alist\ifx\alist\@empty\else,\fi\x}%
}
...
6
votes
2answers
84 views
Resetting numerical labels in \foreach commands on a numberline
I am looking to create quick number lines. What I have so far is this:
\documentclass[letterpaper,12pt]{book}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes,backgrounds,arrows}
\begin{document}
...
4
votes
2answers
96 views
How to use declared TikZ functions in \foreach condition?
How is it possible to use a declare function in the condition of \foreach? Here's my MWE:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[declare function={a = 0; b = ...
6
votes
1answer
119 views
Tikz: \foreach and axis environment incompatibility
I'm trying to plot a figure with TikZ. I have a few .txt files with the coordinates of the curves that I want to plot, in a list such as
file2.txt,
file4.txt,
...
file30.txt
and I want to add ...
7
votes
1answer
177 views
TikZ \foreach loop evaluate variable using pgfmath function
I have problem with defining a new variable within the \foreach loop using the evaluate option using a pgfmath function:
\documentclass{article}
\usepackage{tikz}
\begin{document}
...
5
votes
1answer
103 views
Determining tikz drawing style, depending on the values of two nested loop iterators
So the question is a tikz one!
Assume that you are drawing things inside two nested foreach loops in tikz, and the iterator variables are \x and \y. What I'd like to obtain is to be able to specify a ...
5
votes
1answer
176 views
Syntax for smoothing a coordinate plot with the foreach command
Currently implementing the solution of
Curve synthesis - Adding two curves to get another one.
I would like to smooth out the resulting curve. The present code:
% red line
\path[red,name path=one] ...
7
votes
2answers
136 views
Using foreach loop in TikZ to plot at non-uniform locations
As a Teaching Assistant for a class, I am trying to draw a seating chart for the professor. The seating chart will have a photo of each student, the student's name, and where the student is sitting in ...
6
votes
1answer
199 views
tikz label coordinates using mathematical expression from foreach variables
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x [count=\xi from 1] in {-3.0,-2.8,...,1.8}
\draw[thin] (0,0) ++(\x,2) rectangle ++(0.2, 0.2) ...
2
votes
2answers
95 views
What is the correct way to generate notation for a finite set using for loop in Latex?
I am trying to create a command that will take an index n as a parameter, and generate the the expanded form of this {a_1, a_2, a_3,...,a_n}.
For my first attempt, I tried to use the syntax suggested ...
4
votes
2answers
118 views
Tikz: Using relative positioning and foreach variables
I want to generate a picture that replicates itself and slowy fades out.
For that i plan to use a foreach statement and redraw the picture to its rigth.
How can i use the foreach variable to position ...
4
votes
0answers
186 views
Drawing a gear with Tikz
I need some help to modify the \gear macro of this answer in order to be able to fill the drawn gear with a solid color.
I've tried to move the \draw command outside the loop, but it does not work as ...
5
votes
2answers
129 views
tikz/foreach: Protect space after “iteration variable”
I try to draw some nodes in tikz, and as they are very simple I wanted to "shorten" this using a \foreach command:
\foreach \xnum in {1,2,3,4,5}
{
\node at (X\xnum center) {$x_\xnum$};
}
You ...
1
vote
0answers
100 views
tikz foreach used for number in filename for addplot [closed]
I have quite a few tables generated which I want to plot in the same TikZ figure (using pgfplots). I am currently trying to use a foreach loop to plot them all, but it is only plotting the last ...
3
votes
1answer
156 views
How to make hyperlinked tabs with specific colors?
I modified this project How to print section titles like tab-list? in the following way:
usletter, 8 tabs on the edge of paper, odd pages only, text within the tab is set by the user (\TabText), ...
5
votes
1answer
90 views
tikz gives null character in \document
Please why does
\begin{document}
\begin{tikzpicture}
\foreach \x [remember=\x as \lastx (initially A)] in {B,...,H}{%
$\overrightarrow{\lastx\x}$,
}
\end{tikzpicture}
\end{document}
give
Missing ...
9
votes
1answer
145 views
\foreach has a problem with ‘initially’ argument in remember part
Is there an error in my code or did I find a bug? It seems like the \foreach statement doesn’t increase \lastn if there is an initally (value) but it works with a manually given initially value ...
11
votes
3answers
238 views
Using \foreach loop in Cubic B-spline curve refinement
This question is only about TikZ (/PGF) implementation. This is a MWE of what I want to ask for:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
...
7
votes
3answers
232 views
How to invert list used for a tikz foreach loop
Given
\def\stuff{a,b,c}
I would like to be able to do
\foreach \x in {c,b,a} {...}
without inverting the list \stuff manually.
For example is there some sort of \invert macro that would allow me ...
5
votes
2answers
142 views
Have \foreach restart or loop
I understand that trying to have a "loop function" like \foreach loop sounds like a paradox but I'll try to explain what I mean. Recently, I've asked a question about automatising the creation of ...
8
votes
2answers
216 views
Draw a path between many nodes using foreach
I'm running into a weird problem here... I have very many nodes defined, and I would like to draw a path from the first to the last using foreach. But, when I try, it just draws edges between p1 and ...
6
votes
2answers
132 views
Using etoolbox macros in tikz foreach loops
I am trying to wrap my head around etoolbox for use with TikZ. In this example (I know there are probably simpler ways to do this), I would like to draw a series of rectangles that are next to each ...
4
votes
1answer
281 views
How to loop through a list of tikzpicture within animateinline?
I have the following code which uses animateinline and several tikzpicture for it's animation effects:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{ifthen}
...
3
votes
2answers
468 views
TikZ: Drawing the same data with scatter plots and parallel coordinates
I am new to TikZ and trying to recreate the following image (which was created in R):
(Translation: correlation = +1, correlation = -1, two clusters, circle, normal distribution)
Each "column" ...
10
votes
4answers
225 views
How to change the item separator in TikZ foreach command
I want to cycle over several sentences using a foreach loop. Now sentences will prpbably contain commas, which are used by foreach as item separators. So I would like to change the item separator to ...
5
votes
2answers
266 views
tikz \foreach dynamic list with environment arguments
I'm making an axis environment that recieves 5 arguments (the first is optional and it's 1 by default). To make the x marks on the x axis I use
\foreach \x in {#2,...,#4}
{\ifthenelse{\x = 0}{}{\draw ...
2
votes
3answers
144 views
Macro to check if an element is a member of a list, and access associative lists
Inspired from Macro to access a specific member of a list.
I want to have a macro implementing the lisp functions (member item list) and (assoc id alist). The first checks if an item is contained in ...
6
votes
1answer
188 views
How to define macros in a foreach loop with effects between iterations and after the loop without using global?
Without using \global, the following code:
\documentclass{minimal}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{etextools}
\newcommand\appendbyforeach[2]{%
...
6
votes
1answer
216 views
How to assign values with foreach?
I have trouble to assign values with \foreach. Can somebody help me? The following code is wrong. The purpose is to asing the values: \lx1=1, \ly1=2, \lz1=3, for example.
\foreach \x/\y in ...
11
votes
1answer
183 views
How to expand a macro used in the range of a foreach loop?
Motivating Example:
Suppose that I want to draw the following tree:
root
/ \
/ \ / \
A B C D
This is easy enough to do by explicitly drawing the two subtrees
as children of ...
7
votes
2answers
204 views
Getting last value in tikz foreach
I tried this, but it doesn't work as intended:
\foreach \x/\index in {4/0,5/1,19/2} {
\ifnum \index > 0
% use lastx
\fi
\pgfmathsetmacro\lastx{\x}
}
How do I set \lastx properly?
3
votes
2answers
177 views
Numbers as markers with \foreach and additional macro based on counter
First issue
I would like to plot several curves using the \foreach command and
have their number in the sequence as markers.
Here is the code I came up with :
\documentclass{article}
...
15
votes
4answers
547 views
Multiple TikZ keys with foreach
Playing around with pgffor, I'm trying to slightly modify an example from the TikZ/pgf manual:
\path \foreach \x/\content/\style in {%
0/a/draw,
1/b/{draw,red},
2/c/{circle,blue},
3/d/draw%
} ...
2
votes
2answers
242 views
Impossible to use the variable set by \foreach as a variable in a function
The latex code below does not compile. This is due to \foreach and the function \getcolor.
Does anybody know, how I can use the variable set by \foreach in a function.
Find below the code
...
6
votes
3answers
837 views
TikZ: Using Loop to Draw Grid of Nodes
I am trying to draw an Ising model (in my case, a grid of nodes with an undirected edge between adjacent nodes on the same row or column) using TikZ. I have the grid of nodes working nicely using a ...
6
votes
3answers
143 views
How to “demux” several aspects from a `\foreach` variable with `\ifstrequal`?
How can I "demux" several features from a mode specification given in a \foreach?
I would like to use a \foreach to draw several nodes in a TikZ picture. The loop will specify a mode for each ...
8
votes
2answers
361 views
Tikz foreach inside matrix
Apparently this question has been asked a hundred times already. But I couldn't get it to work with any of the answers provided.
I want to have nested for loops inside a Tikz matrix. Something like:
...
5
votes
1answer
178 views
Fill Nodes according to table/data file
I have a lattice of nodes generated by two \foreach commands. So each node has two numbers which define its location (essentially x and y coordinates). Is there any way to fill a circle at that node ...
12
votes
5answers
488 views
tikz loops, creating triangle with jagged hypotenuse
I am in dire need of constructing the image below.
In short I am trying to create an exact replica of the image,
and an alternative image, with a much more jagged hypotenuse.
I thought about using ...
8
votes
1answer
380 views
Creating a fraction graph in TikZ
Ok, so I was helping a friend of mine with a fraction problem on how to represent fractions so that they are easy to compare for children. We were thinking of a ruler and separate the ruler into ...
6
votes
1answer
377 views
Sum and Difference on the number line using TikZ
I am trying to replicate the idea of sum and difference of real numbers on the number line and have been successful in some way. For example, the code:
\documentclass[letterpaper]{article}
...
7
votes
1answer
678 views
pgf's \foreach macro
Please is there a way of turning the group scoping of \foreach off? The following problem illustrates my difficulty. Without global assignment the aim is not achieved, but global assignments might ...
4
votes
1answer
219 views
Lengths and for-loops
It seems that lengths are not updated in for loops.
Compiling the code below:
\documentclass{article}
\usepackage{tikz}
\newlength{\test}
\newcommand{\inc}{\addtolength{\test}{1cm}}
...
4
votes
2answers
234 views
How to iteratively draw a path e.g. with foreach
I have a long path and want to draw parts of it in an iterative manner
\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc}
...
3
votes
2answers
202 views
How to cycle colors through the lines of a polygon
I want to shift the lines specification through a polygon.
My current code looks like this (not DRY at all):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{shapes,arrows}
...
14
votes
2answers
333 views
Error with \foreach in TikZ
In the MWE below
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \i in {0, 1, 2, 3}
\draw (\i, 0) rectangle +(0.5, 0.5);
% \draw (\i, 1) rectangle ...
4
votes
1answer
319 views
Using foreach loop variable as node label in pgfplots
I have a (multi)line plot generated from a table in pgfplots:
\begin{document}
\begin{tikzpicture}
\begin{axis}
\pgfplotstableread{table.tsv}\loadedtable
\foreach \metavar in {foo,bar} {
...
3
votes
1answer
622 views
Iterate with `\foreach` over multiple variables and '\remember' one of them does not work as expected
I'm not so new to TikZ but am now trying something a little more advanced and am puzzled by the following problem. From researching solutions, I see that lots of good answers with good explanations ...
5
votes
2answers
283 views
number formatting in foreach statement of tikz
I have the following code:
\begin{tikzpicture}
\foreach \i [evaluate=\i as \ii using \i+5] in {1,2,3,4} {
\node at (\i,0) {\ii};
}
\end{tikzpicture}
I like to print 6 7 8 9, but the above code ...
6
votes
1answer
334 views
Problem setting a flag inside a TikZ `\foreach` loop
I'm pulling my hair out trying to understand why the following doesn't work. The intention is to calculate whether a given number #1 is prime, and to set \isprime to either 1 (true) or 0 (false). The ...
