# 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.

347 questions
Filter by
Sorted by
Tagged with
25 views

### Using the maximum value of two equations from a mathematical expression in a pgf plot

Good afternoon everyone, currently, I am making a graph to insert it into another document later on. It is a regression line in a dot cloud. (The dot cloud is represented by four coordinates in the ...
26 views

### Evaluate variables for coordinates in newcommand

I'm trying to plot a graph and put annotation on it, with arrows pointing to the curves. Here is a simplified working code : \documentclass[border=2pt]{standalone} \usepackage[utf8]{inputenc}...
112 views

### pgfmath / gnuplot: How to use gnuplot for complicated calculations?

Is there a way to use gnuplot for complicated calculations? For \pgfmathsetmacro{\x}{0.02} \pgfmathsetmacro{\y}{2*11000*(1 - 1.40576 - cos(\x) + sqrt(1.40576^2 - sin(\x)^2))} for example I get '...
68 views

### How to find the length of a PGF array even if it's in a macro?

One of the answers to a question about how to calculate the length of a PGF array provided a function that increments a counter for each step of the iteration on the array provided as its argument. ...
47 views

### Dynamic bar plot from file

I need to draw a bar chart based on the data from the file. The data looks something like this \begin{filecontents*}{tls.dat} Name Abbreviation percentage Bod-Kin LS1 60 Intraper LS2 40 ...
101 views

### Superlattice in Tikz

I'm trying to work out how to plot two (hexagonal) lattices stacked on top of each other at a relative twist angle on tikz -- see the attached examples. I know how to plot a lattice using a for loop, ...
32 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. ...
243 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 ...
32 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} \...
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 ...
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 ...
42 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 ...
52 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} \...
60 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,...
40 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 ...
49 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 ...
29 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 ...
74 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 ...
24 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.}; } \...
206 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={...
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} \...
51 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 ...
53 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{...
96 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 ...
36 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 ...
122 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 ...
129 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 ...
89 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 ...
73 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): \...
153 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{...
88 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 ...
86 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{\...
56 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 ...
933 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{...
106 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 ...
54 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 ...
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 ...
43 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 ...
189 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 (...
108 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}{\setcounter{Precision}{#1} \$\pgfkeys{/pgf/fpu,/pgf/fpu/output format=sci} }...
196 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{...
331 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}...
93 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{...
87 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 ...
351 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} \...
229 views

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 ...
325 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} \...
190 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 ...