Stack Exchange Network

Stack Exchange network consists of 175 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 [pgfmath]

{pgfmath} concerns the pgfmath library used for internal computations in TikZ-pgf but which is also available for other computations in (La)TeX.

1
vote
1answer
18 views

Precision difference between \pgfmathsetmacro and \pgfplotsretval

I am currently working on some datasets with pgfplots and pgfplotstable. At some point, I need to store some cell values for mutiple uses so I use a \pgfmathsetmacro{\somevar}{\pgfplotsretval} call. ...
7
votes
2answers
229 views

Best practice for printing and evaluating formulas with the minimal coding

Can the following MWE be reduced by creating a command that can accept a formula then print and evaluate it without the need to write it twice in two different forms for both evaluating and printing ...
1
vote
1answer
28 views

How can I use `\pgfmathresult` as x-coordinate?

I need to use \pgfmathparse{floor(\textwidth/2)} as one of x-coordinates of a path but I get an error. \documentclass[margin=5mm,varwidth=100mm]{standalone} \usepackage{tikz} \begin{document} \...
1
vote
1answer
21 views

Tikz error for large values with \pgfmathsetmacro

I have the following MWE \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[{x=(1mm, 0)},{y=(0,1mm)}] %-> DEFINITIONS \def\plthgt{50} % plot ...
0
votes
1answer
22 views

Random compile-time document style

I am trying to create a document class with random style attributes, determined at compilation time. Random attributes would ideally include: Margins Line spacing Font selection For my particular ...
3
votes
1answer
32 views

Problem on coloring nodes with [fill=black!\pgfmathresult] in tikz

I tried to use tikz to fill nodes with colors according to values in an array file, but I failed to fill nodes with right color when fixing node position by [at (a,b)]: \begin{document} The data in ...
3
votes
3answers
45 views

dimension too large in pgfmathsetmacro

This works for \test{500} but not for let say \test{50000} \documentclass[10pt,german]{article} \usepackage[T1]{fontenc} \usepackage[ngerman]{babel} \usepackage[utf8]{inputenc} \...
1
vote
2answers
53 views

foreach / pgfmath: create a list of specific values

I would need a list, possibly an array (for later use in a foreach loop / TikZ graphic), which contains the following values ​​(a_n) in order (n = 1,2,3, ...): 45,135,225,270,315, 45,45,90,135,135,...
2
votes
1answer
28 views

Use \ifthenelse{\equal{ on a number called from reference

I want to store an answer key for an exam and then automatically move the multiple choice answer choices around for each question match its predetermined answer. (I need to conform my multiple choice ...
3
votes
0answers
41 views

Using conditionals inside mcexam

I want to write exams where the questions and answers are randomized, and mcexam lets me do almost everything I want. However, I would also like each question to be picked randomly from a group of ...
1
vote
1answer
25 views

Problem with using rnd function in Tikz polar coordinates

I am trying to draw lines with a different, random length but the same direction. This is what I thought should work, but if I put in any other angle than 90 degrees (for example 30 degrees in this ...
2
votes
1answer
67 views

Define a new math function

I want to use an angle (say a) in tikzpicture, which is calculated from other parameters: \def\d{1} \def\D{2} \def\H{5} a=90+0.5*asin(2(\D-\d)/\H) This angle a I then use in a tikzpicture ...
2
votes
0answers
20 views

In tikzmath the “random” puts “.0.0” if want negative random number [duplicate]

Here is a MWE: \documentclass{article} \usepackage{pgf} \usepackage{pgfplots} \usetikzlibrary{math} \begin{document} \tikzmath{ int \foo; \foo = random(-16,10); print {Foo value: \foo.}; } \...
1
vote
2answers
181 views

variant of scientific notation on pgf

I use scientific notation on pgf to display numbers. My present code as follows: \documentclass{article} \usepackage{pgf} \begin{document} \pgfkeys{ /pgf/number format/.cd, sci, sci generic={...
1
vote
1answer
20 views

How can I manipulate a part of a text depending of the sign of a parameter or the parameter itself (automated calculation solution quadratic function)

I want to make a complete solution sheet with the whole context for my students. My code is this (with the answer I changed my problem) to this: \documentclass{article} \usepackage{pgfplots} \...
2
votes
1answer
49 views

pgfplotstable: highlight entire rows and columns

This is a follow-up on this question. With pgfplotstable, I would like to create a style to highlight an entire row and/or column. Zarko's answer at the linked question shows how to bolden an entire ...
2
votes
3answers
52 views

How to prepend extra 0s unto calculated binary digits

So I'm suppose to make an omega network that connects 0010 to 1000 and I have pretty much done it, however I would like to display my binary with extra zeros. \documentclass{standalone} \usepackage{...
2
votes
1answer
63 views

How do I display only certain rows in a table using pgfplotstable?

I have a table, read from a file, and I would like to display only rows which have a specific value in a given column. The specific value is a string (e.g. Agricultural). I am able to do it using the ...
0
votes
0answers
34 views

How to define an arbitrary math function that works in `tikz` environments? [duplicate]

Using this post: Package or command for inverse hyperbolic trig functions? it is easy to write (inverse) hyperbolic Secant function in documents. But the main problem is it doesn't works on tikz ...
1
vote
1answer
113 views

Include negative value in sum/total value in stacked bar chart

I have a stacked bar chart that looks like this. However, I'm trying to include the negative values (ninth column in the datatable) into the total value on the stacked bar chart so that in the end ...
1
vote
1answer
99 views

Stacked bar chart, nodes near coords remove small values and show sum

I know it is possible to have only the sum shown on top of the bar chart and remove the other values in the stacked bar chart (as shown in picture attached), but I can't figure out what went wrong in ...
3
votes
3answers
81 views

Check whether String represents valid number for PGF

I am searching for a reliable way to determine whether a String can be fed into \pgfmathprintnumber. I used to use the \IfDecimal from the xstring package which works fine for things like 3.14 and ...
3
votes
1answer
61 views

\pgfmathprintnumber label of bar values exceeding axis values

I'm trying to only have the y-value exceeding the axis to be labelled and not the rest (as shown in the picture below). Is there any suggestion how this can be made? my MWE (thanks to @Jake): \...
3
votes
1answer
117 views

Assigning a numerical variable with Tikz pgfmathtruncatemacro

I am struggling with some basic computations with Tikz and I have a problem assigning a value to a variable inside a local scope. Consider the following MVCE: \documentclass{article} \usepackage{...
1
vote
1answer
69 views

Weird error when including tikz in a figure

I am trying to include a tikzpicture inside a figure. It had worked for other tikzpicture, but now I have a complicated 3D one here, that I have trouble integrating. Here is the overleaf MWE where ...
1
vote
2answers
78 views

pgfmath: Function for strings and numbers?

Is there a pgfmath-function for something like ? \documentclass[]{article} \usepackage{tikz} \usepackage{array} \begin{document} \def\myarray{{1,0,"-1","a"}} \foreach \i in {0,...,3}{\pgfmathparse{\...
2
votes
1answer
55 views

Scaling an image to make math text smaller

Since you cant set the size of math notation I was wondering if we can scale the image to be larger so that math appears smaller? Also I`d like to be able to change the x-axis and y-axis of the ...
7
votes
2answers
928 views

Bamboozling Arithmetic!

While creating some pgfmathsetmacro arithmetic macros, I stumbled upon a very perplexing result. Take the following example: \documentclass{article} \usepackage{tikz} \usepackage{xstring} \begin{...
3
votes
1answer
90 views

String operation creates error in pgfmathsetmacro

I am trying to reference the first character of a string within a pgfmathsetmacro, however, the macro \StrLeft from xstring, I believe, is not playing well with pgfmathsetmacro. Take the following ...
2
votes
1answer
43 views

\pgfmathsetmacro creates “Dimensions too large” for t distribution

I am trying to plot 't' distribution with area of interest shaded. I have done both plotting and sharing area. Next tried to draw vertical lines closing the shaded area on both sides. For this, I need ...
1
vote
1answer
68 views

Show x-labels as time every two hours with pgfplots{dateplot}

I'm trying to plot a simple graph from .csv. I'm using the answer of https://tex.stackexchange.com/a/83929/164280 as basis. I get a could not parse input '00:00:00' as floating point error. I do want ...
1
vote
1answer
40 views

Wrongly calculated (or displayed) x-coordinate in tikz

I would like to plot the following figure: but only that in the nodes x_1,x_2,x_3 the right coordinates of the points displayed. The corresponding MWE is the following - I have included the entire ...
5
votes
2answers
177 views

Coordinate calculation with TikZ

I need to draw some plots with vertical lines from the x axis to the function. For example, I defined the gauss(x) function for the normal distribution and I drew this plot, with a vertical line from (...
2
votes
1answer
96 views

change “output format” of pgfkeys sci or fixed

I have defined an environment that is used for calculation as shown below \newcounter{Precision} \newenvironment{calc}[1][1]{\setcounter{Precision}{#1} $\pgfkeys{/pgf/fpu,/pgf/fpu/output format=sci} }...
3
votes
3answers
163 views

How to store an array of values?

I need to calculate the mean of a bunch of values generated by a function inside a loop. Is it possible? \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{...
4
votes
3answers
328 views

Why does “\x-1” not work in node name?

How to fix the error in referring to a node using \x-1? It works in [below left = \x-1] but does not work in \draw[->] (\x-1) to (\x). \documentclass[tikz]{standalone} \usepackage{pgffor,pgfmath}...
2
votes
1answer
84 views

pgf-pie : Dimension too large

I used the package pgf-pie to generate pie chart. The option sum=auto compute automatically the sum of all value. The following MWE give Dimension too large because this reason. \documentclass{...
5
votes
1answer
85 views

Why do we need extra braces in ellipse when using a constant?

What is the best way to declare a constant to be used within TikZ? I am using \pgfmathsetmacro because I have seen others do it on this site. A constant should be a simple thing, so I am bit confused ...
4
votes
1answer
293 views

Graph of Triangle wave

I am trying to graph the following: Using the following function: And using this code: \documentclass[14pt]{extarticle} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{amsmath} \...
6
votes
2answers
205 views

Sum inside addplot call

While responding to this post I was wondering if it was possible write for loops inside addplot calls. I really mean for loops inside addplot and not addplot inside for loop (just to make myself ...
4
votes
1answer
305 views

latex pgfmath precision

What's the correct way to use pgfmath function? See below simple example: \documentclass[border=1pt]{standalone} \usepackage{tikz} \begin{document} \pgfmathsetmacro{\x}{3} \pgfmathsetmacro{\y}{10} \...
3
votes
1answer
172 views

PGF math broken in \foreach loop

Following my previous question I've tried to make my example a bit more general as well as complex. (Note: I don't want this more complex, but this is what I want my graphics to do.) When I have the ...
3
votes
2answers
72 views

Using a string as a coordinate fails

When I use \pgfresult to get a node label in a \foreach, I have no problem. However, I can't seem to get the syntax right to create a coordinate with the same method. \documentclass{article} \...
5
votes
1answer
237 views

How to do a non-linear transformation with tikz-pgf?

Consider the following plot of the (-2, -1) -- (3, 9) line segment: I want to apply a transformation so that the horizontal axis is the polar angle of a point, and the vertical axis is the distance ...
4
votes
1answer
121 views

A question on pgfmath, variables, conditionals and scope

First, I would like to apologize for the vague title of my question, somehow I didn't manage to come up with something more precise. Based on an answer to this question, I wanted to create a function ...
4
votes
1answer
176 views

Flattening a square impulse

I'm interested in creating a plot using TikZ or pgfplots together with the animate package. The plot should consist of a square impulse that is moving along the z axis. As it moves it should lose its ...
0
votes
2answers
57 views

Error trying to parse with \pgfmathparse

I'm trying to evaluate the following expression with \pgfmathparse, but I get error messages: \pgfmathparse{\sqrt{{5.8186/{\pi}}}}\pgfmathresult\ Any idea why?
10
votes
2answers
281 views

Contingency table with pgfplotstable: dealing with large integers

This is a direct follow-up of https://tex.stackexchange.com/questions/62409. Jake showed how to create a contingency table with the pgfplotstable package (and booktabs). Integer size limitations hit ...
1
vote
1answer
99 views

Calling a math library function from \addplot [duplicate]

I am interested in plotting my own function with pgfplots in combination with the math library from TikZ&PGF. This function is something I would use many times in my document. Something like this:...
7
votes
4answers
162 views

Is there a limit for the seed value in pgfmathsetseed

I am using pgf to create some random exams. To set the seed, I am using pgfmathsetseed. This system uses very different values for the seed, whose range could go to the thousands. The pgf manual says ...