# Tagged Questions

{calculations} is about calculations in (La)TeX documents. A popular package is calc although may other also exist (fp, pgf, and LaTeX3 packages).

230 views

### How to add numbers occuring in a text?

How make LaTeX to remember some numbers and output the total sum by calling another command? Consider this example: \documentclass{article} \usepackage{lipsum} \begin{document} The price of the ...
23 views

### How can I achieve textpos relative positioning in a document set to absolute positioning?

This is as close as I've got, but I can't work out how to do the calculation so that textblock accepts it: \documentclass[11pt]{article} \usepackage[paperheight=93.884mm,paperwidth=68.992mm,margin=...
30 views

### Calculations in TikZ [duplicate]

I need to draw two tangent circles with their common tangent. I drew the first circle centered at C radius CA, the tangent AB. Now I need to find the position of the center for the second circle on ...
84 views

### How to calculate a square root of the area?

I am trying to tikz-euclide the following picture (it is made in Geogebra). Two solid circles are equal. To guarantee that, the length of the red segment should be \sqrt{S}, where S is the area of ...
190 views

### Sort Numbers After Their Values

Consider the numbers 2^4, 4^2, 3^2, and 5^2 Is it possible to make LaTeX calculate the values of these numbers and then arrange then automatically according to the values? That is, in this ...
71 views

I come from this question: How can I automatically calculate sums in a LaTeX table? I want to do the same but with "timing" calculations. So my example would look like this: \documentclass{article} \...
59 views

### How to convert \textwidth to mm and use the number as a command?

I am trying to convert \textwidth to other units I want and do calculations with the number (without the unit). How does one do this?
143 views

### Tikz and variables

I have defined two variables \def\aa{3} \def\bb{1} \def\qq{\multiply\aa by \bb} but when I try to use \qq in a \matrix command like \matrix[matrix of math nodes]{12 & \qq\\}; ktikz says: ...
83 views

### How to create a table with fixed-width cells and use cellcolor and multicolumn to create time bars? Or: How to substitute ganttbar with tabular?

Failing to combine a gantt chart with a table I now try to avoid the gantt chart by just using a tabular environment. However I like to keep some neat features of the pgfgantt-package and I'm facing ...
39 views

### Convert count into length

I want to decrease a length by a number (count). I tried some variations with \newlength{\temp} and \addtolength but I got problems there with the minus. I also tried variants with \dimexpr. The ...
41 views

### Output age on Birthday with Calendar \usepackage{montly}

I want to display the age of multiple people on my calendar. I can get the current year to come through with \the\year, but I can't figure out how to solve an equation in the option below (part of ...
277 views

### Multiply a label by 3 and print result

I would like to create a quiz for my students where the more parts I add to the question the more points it is worth. For each extra part, I want it to be 3 more points. In the following example, I ...
55 views

### Number formatting, addtocounter and calc package

I have been having troubles with the following issue: I am making an invoice template in LaTeX. I use \addtocounter to calculate values like subtotal, tax and total. This works fine, until the value ...
74 views

### In-place calculation of color with tikz and calc

Is it possible to calculate a color value like this in-place with tikz and its calc library? \filldraw[fill=black!{50-95.7/2},draw=black] (1,0) rectangle (2,1); %Gives a 'Missing number, treated as ...
37 views

### Mysterious summing: when calculator 's \ADD macro adds too much inside a table

Background: In my previous question, Robert Fuster taught me how to define a global variable using calculator package. I want to define a "counter" that also works with non-integers. I thus defined ...
50 views

### Using locally defined calculator commands inside tables (tabularx)

Inside a table, I want to draw rules. Their length equals the cell length times a predefined ratio (i.e. \rule{\ratio\linewidth}{1ex}). I use the \DIVIDE{A}{B}{\ratio} function of the calculator-...
53 views

### Positioning with current axis depending on limits?

I try to specify the x axis label position below the x axis arrow at the same baseline like the xticklabels. It works fine for most plots. However, when modifying the range of the y axis with ymin=...,...
37 views

### Show calculations to table cells

I have a table with a lot of financial data. I need to show the calculations behind each financial figure. I have considered to just use footnotes for each table cell, but I guess it's quite ugly to ...
59 views

### pfg conditional addition of a number

I have coordinates stored in \xCoor and \yCoor, and and converting these into polar coordinates to express on paper. I'm wanting this done automatically, and have been able to define: \...
84 views

### Draw path if distance is below threshold

I want to draw an intersection graph and for this purpose I have an array with coordinates. Now I loop through them and calculate the distance between the coordinates and if it below the radius of ...
2k views

### Simplifying square roots

I want to create a command that, for a given integer n, type sets a simplified square root of n. For example, the output of \rsqrt{4} \rsqrt{8} \rsqrt{18} \rsqrt{7} would be the same as that of 2 ...
38 views

### How can I calculate the correct offset for fancyhdr when using geometry to change layout?

I have a document with the following configuration: a custom layout is defined using geometry in the preamble; custom headers/footers are defined using fancyhdr in the preamble; an alternative ...
57 views

### Tikz macro with calculation error

I'm very new to this so bare with me. To get the hang of macros I wanted to write a simple command to draw a square in tikz. Now I know there are a lot of ways to do this, but I want to be able to ...
159 views

### Writing sequence terms

What would be the best way to write out the terms of a sequence, somehow like this, but preferably aligned? Is there a way to automatically generate the terms from an equation i.e. with n² for ...
41 views

### calc package and global lengths problem in tabularx

The output of the following code is affected whether calc package is included or not: \documentclass{article} \usepackage{tabularx} % \usepackage{calc} \newsavebox{\testbox} \newlength{\testlen} \...
51 views

### Use numbers stored in a command by spreadtab

My aim is to create a command to store numbers and calculated in the table. \begin{table}[h] \npthousandsep{,} \STautoround*{0} \begin{spreadtab}{{tabular}{| l | r | r | r |}} \hline ...
91 views

### A problem drawing arcs associated to angles

I need to draw arcs to denote angles inside an equilateral triangle. To do this, I am using the arc function in tikz with the help of the calc package. However, if I use an automatic solution which ...
260 views

### How do I draw on images embedded with \includeimage in TikZ with pixel accuracy?

I want to draw on an image which I embedded using \includeimage: \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture} \node[anchor=south west,inner sep=0] (image) at (0,0) {\...
59 views

### Sort array of words by length

I have a long array of words which I need to show in increasing order of length. I have tried to use the package arraysort and customize a comparator. My simplified code is: \documentclass{article} ...
184 views

### serious scientific calculating with small numbers, using different methods

I got stuck in a problem with pgfmath module. When trying to calculate the following functions values the result that gets printed out is always zero. I guess the problem is an underflow of pgfmaths ...
105 views

### Creating a heatmap using calculations and tabular environment

I know there exists pgf, and many people uses this to create heatmaps. I however am not allowed to use this package. I therefore want to create a command that enables me to color the different cells. ...
48 views

### Checking a number with calculator package [duplicate]

I have a problem about calculator package, I need check if #1 is a number or not, could I use conditional command? ex: \def\CHECK#1{ % if #1 a number \if...? #1 is a number \else #1 is not a ...
153 views

### create node of own macro with tikz

i would like to draw a network of multiple queues. To build one node i would like to make a node out of this macro (DrawStation) and give it a name. \usepackage{tikz} \usetikzlibrary{positioning} % ...
40 views

### Perform math operation with values of \labels

I use \label to index the number of items in several environments. I wish to perform the sum of the quantities reported by those labels. Here is a working example: \documentclass{article} \usepackage{...
56 views

### Creating a Test-Template

after hours of searching and trying i want to ask my special question. I'am a teacher and want to create a template for my test-document. Therefore i need to add points in every task. To control the ...
131 views

### Automated Creation of Questions and Solutions for a Worksheet/Exam

Overview My title is the not the best, and I will edit it if there are any better suggestions! In a nutshell, what I am trying to achieve is to randomly change numbers in a maths question and have a ...
167 views

### Understanding etoolbox macro \deflength

The etoolbox package documentation says about \deflength: This command may be used as a drop-in replacement for \setlength. I am having trouble getting it to work with the \minof macro from the ...
127 views

### Use floating point with calc

I wanted to use a pie chart in my document and tried this code example: http://www.texample.net/tikz/examples/pie-chart/ Now this seems to work perfectly with integer values but as for floating point ...
60 views

I have a document with several commands that store numeric variables inside an extra macro. This extra macro will highlight that text so I can track them in the printed document. Like so: \...
310 views

### Delete commas within numbers

To use package{calc} for calculation, number should not include any commas. So I tried to use \def\commatonone #1,#2.00 {#1#2} to get the number without commas. \documentclass{article} \usepackage{...
142 views

### How to increment a variable in beamer slide?

I have this code: \documentclass{beamer} \mode<presentation> { \usetheme{Warsaw} } \usepackage{tikz} \AtBeginSection[] { \begin{frame} \tableofcontents[currentsection] \end{frame} } \begin{...
181 views

### Evaluate binomial coefficient with \pgfmathtruncatemacro

How is it possible to evaluate complex formulas like \binom{2^{4}-3}{2^3} with \pgfmathtruncatemacro ? I want this to evaluate to 1287. What already works: \begin{tikzpicture} \foreach \l ...
112 views

### Date Calculations (output should be the fixed day of the month)

I'm building a LaTeX document that already got the date from other files. The date showed as 23 November 2015 as the example (by \today). Then I need to output another date related to this original ...
94 views

### Getting the \pageref out from under hyperref

I thought I was pretty cool when I modified \ref to also print a page number when the referenced float was more than a few pages back. But I really want it to be a nice link using the hyperref package ...
132 views

### Struggle with floor- and ceiling-functions in pgfplots

Could anyone help me with this struggle? I don't get, why the floor- and ceil-functions in the axis-environment of pgfplots and in floating text differ from each other. Aren't they both processed by ...
158 views

### Calculation of an angle in tikz (fraction of light) including sin^-1

I want to calculate the deviation angle \beta with the law of Snellius in a tikzpicture. My code is \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{array} \...
36 views

### How to do math on overlay arguments using pgfkeys (handle numbers and ranges)

Context I'm trying to do some basic operations on arguments on pgfkeys, and got stuck while trying to do simple arithmetic on them. Thankfully, egreg gave a nice solution for handling the arithmetic ...
35 views

### How to do math on pgfkeys arguments and asign them to other keys

I'm trying to reduce the work load of applying some overlays over and over with different numbers. However, I need to compute for a given frame the next or previous one, thus needing to do simple ...