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

learn more… | top users | synonyms

5
votes
2answers
261 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 ...
2
votes
1answer
30 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 ...
4
votes
1answer
55 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 ...
1
vote
1answer
36 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 ...
1
vote
2answers
48 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 ...
3
votes
1answer
39 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 ...
0
votes
0answers
33 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 ...
2
votes
2answers
54 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: ...
2
votes
2answers
77 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 ...
23
votes
5answers
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 ...
3
votes
1answer
28 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 ...
2
votes
2answers
39 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 ...
6
votes
3answers
143 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 ...
3
votes
2answers
31 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} ...
1
vote
2answers
40 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 ...
1
vote
2answers
84 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 ...
8
votes
2answers
212 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) ...
4
votes
2answers
52 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} ...
5
votes
3answers
178 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 ...
2
votes
1answer
93 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. ...
1
vote
1answer
42 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 ...
3
votes
2answers
114 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} % ...
3
votes
1answer
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} ...
2
votes
1answer
50 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 ...
3
votes
2answers
124 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 ...
12
votes
1answer
152 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 ...
6
votes
1answer
82 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 ...
3
votes
2answers
53 views

overloading functions of the fp package

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: ...
12
votes
2answers
307 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} ...
3
votes
2answers
114 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} } ...
2
votes
3answers
133 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 ...
2
votes
2answers
98 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 ...
3
votes
3answers
80 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 ...
8
votes
1answer
107 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 ...
4
votes
2answers
133 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} ...
3
votes
0answers
34 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 ...
4
votes
1answer
34 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 ...
4
votes
1answer
107 views

Problem with calculutor, calculus

MWE \documentclass[a4paper,11pt]{report} \usepackage[turkish]{babel} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage{calculator} % 2014/02/20 v.2.0 ...
3
votes
1answer
121 views

Using a macro inside a Tikz coordinate calculation

I am trying to create a general macro that prints a particular custom character, based on an answer to a previous question of mine. Here is a minimal (non-)working example: %!TEX encoding = UTF-8 ...
2
votes
3answers
62 views

How can one number be divided by another number to give a real number result (not an integer)? [duplicate]

How could a function a bit like basiceval be written to give a real number result as opposed to an integer, making the third calculation here more accurate? \documentclass[american, a4paper]{report} ...
0
votes
2answers
101 views

Numerical calculations inside table environment

I am doing a coursework in mechanics and would like to write both the theory and calculations in LaTeX. However, as design is iterative process, I would like to escape the tedious cycle of: Select ...
4
votes
2answers
170 views

Tikz: Math with coordinates

I need to extract the coordinates of a node into a variable. I've tried \pgfextractx \documentclass[11pt]{article} \usepackage{fp} \usepackage{tikz} \usetikzlibrary{calc} ...
6
votes
1answer
88 views

calc breaks assoccnt? [closed]

I want to use totcount to get the number of parts and chapters in my document. To get the correct number of chapters in the presence of appendices, I use assoccnt (see totcount gives wrong chapter ...
3
votes
2answers
76 views

Show variable name, measurement unit and value in a single command invocation

I am using the fp package to write a coursework in mechanics and calculate the numerical values on the fly. Here is some example code: \documentclass{article} \usepackage[nomessages]{fp} % ...
2
votes
1answer
71 views

Calculation in a TeX function. How to do it?

I don't know anything of TeX but would like to improve a function. Here is the initial function: \newcommand{\setnewvsize}[1]{% \global\paperheight\dimexpr#1+\initialVerticalInset\relax% ...
3
votes
1answer
108 views

Determine width of a milticolumn cell

I am attempting to draw a rectangle within a multicolumn, and would like it to span the width of the cell and be consistant with a similar rectangle drawn in a standard cell. I am struggling to ...
7
votes
4answers
335 views

Error using \widthof inside tikzpicture

\documentclass{article} \usepackage{tikz} \usepackage{calc} \begin{document} \begin{tikzpicture} \newlength{\TextWidth} \setlength{\TextWidth}{\widthof{Text}} %\node[draw,text ...
5
votes
2answers
282 views

Enumerate every third item

Is there a way to have a enumerate environment that increment the counter every three item? I already see this question: Enumerate pattern: 1, 1, 2, 2, 3, 3, ... , etc but I'm looking for something ...
1
vote
0answers
119 views

Insert negative of \widthof into \hspace without defining a newlength

Following MWE does not work: \documentclass{article} \usepackage{calc} \newlength{\charwidth} \setlength{\charwidth}{\widthof{$-$}} \begin{document} \centering $\infty$ \centering ...
4
votes
1answer
62 views

Calculator package and Math Times Pro 2

When I try to use the calculator the mtpro2 package at the same time I get an error message. Recently I found out that this issue has something to do with the \SQRT command. ...