{calculations} is about calculations in (La)TeX documents. A popular package is calc.
25
votes
5answers
7k views
How can I automatically calculate sums in a LaTeX table?
Sometimes I would like LaTeX to automatically calculate sums (or other simple arithmetic) for me, eg. in a table. I would like to ensure that when I update the table, I don't accidentally forget to ...
12
votes
2answers
2k views
Is plotting exponential graphs a known source of bugs in TikZ?
I want to plot $y = 2^x$ over a small domain. Unfortunately, even though tikz (v 2.1) seems to be able to calculate 2^{negative numbers} it is not plotting them correctly.
My minimal example is:
...
17
votes
2answers
2k views
Problems with TikZ calculations
When can I use functions and do calculations in TikZ?
How do I make this work:
\draw (0,0) arc(0:90:sqrt(15)); %not ok
why is this working:
\draw (0,0) arc(0:asin(1):5); %ok
with ...
22
votes
5answers
2k views
How to use \pageref{foo} as a number?
What I want to do is to show a "progress bar" in the header to show how far you are in the document, by making a rule with width pagenumber divided by total pages times the paper width.
This is what ...
26
votes
3answers
5k views
Get width of a given text as length
Is there a TeX command that returns the width of a given text as length value, so that I can use the result directly as a length argument of another command?
I mean, I would like to have a command ...
14
votes
3answers
1k views
Doing maths with distance values in LaTeX source code
I have a sty file with the command
\newcommand{\foo}[1]{\noindent\kern#1}
but I'd actually like to have something like
\newcommand{\foo}[1]{\noindent\kern{#1 *0.5}}
meaning that I'd like to have ...
9
votes
1answer
183 views
How to fit ellipse into another object - using intersections and calc library
I would like to ask, how to place ellipse into any object, so that the length of the main arm is defined by line1 (point A, B) in my code:
calculate the coordinates of the ellipse midpoint
rotation ...
8
votes
2answers
407 views
Compute the x distance between two nodes
Is there a way to define a macro which would evaluate to the x part of the distance between two nodes? I know there are the point registers \p and the correspoding \x commands, but I find them rather ...
7
votes
1answer
735 views
Shrinking text to the width of a node within a tikzpicture
I would like to be able to scale text to the width of a TikZ node.
Using \widthof within tikzpicture as a starting point, I've arrived at somewhat of a solution, except it has incorrect spacing, and ...
34
votes
3answers
1k views
Can LaTeX perform calculation like Excel formula table?
I wonder if this feature is available in TeX system? For example, given a formula within a table, it can apply the formula and display data after the calculation.
10
votes
2answers
10k views
How to fit a large figure to page [duplicate]
Possible Duplicate:
Best figure size adjustment when dealing with different image sizes
Given: a large figure, whose height:width ratio is unknown.
Todo: Include this fig in LaTeX, such ...
10
votes
4answers
3k views
Why is this let expression not working in TikZ (calculating a midpoint)?
I have a rectangle in TikZ and the top left and bottom right corners are called (topleft) and (bottomright) respectively. I wanted to have a label midway down the left hand side of the rectangle, so I ...
8
votes
2answers
2k views
How can I compute the distance between two coordinates in TikZ?
Given two points (defined, for instance using nodes), I want to compute the distance between them.
Is there some build in functionality in tikz to do this?
If not, how can it be done using the ...
8
votes
4answers
274 views
Calculating the the exact width of the text and a lettrine
This is one question which technically could be broken into two minor questions.
I am using a lettrine and some verse text, but the calculation to determine how much to indent the text does not ...
20
votes
4answers
775 views
Get derivative of a function
I want to write a macro, which takes a mathematical function as argument and returns a plot using pgfplots of the function and of its derivative.
I guess that this isn't possible using just LaTeX; ...
15
votes
6answers
5k views
How can I sum two values and store the result in other variable?
In LaTeX2e,how can I sum two values and assign them to other variable?
I want to compute something like:
var=\textwidth - 1cm
And if both were constants:
var=1+1
15
votes
4answers
2k views
Floating point calculations in LaTeX?
I am looking for a method to do minimal floating point / integer calculations in LaTeX, not for the purpose of package writing, but for the production of actual text.
Here is an example to ...
17
votes
6answers
1k views
Checking if a number is a multiple of 4
Using etoolbox, ifthen, or another form of conditional checking, how can I check if a value is a multiple of 4? E.g. if the number is 4, 8, 12, 16, etc., then it returns "true".
12
votes
2answers
591 views
Where is the left-hand margin?
I'm working on the TikZ-from-TeX-SX package, specifically developing the code for putting equation numbering at places within a tikzpicture environment. To do this, I need to know where the text ...
2
votes
1answer
374 views
How to pass in a ratio in fraction form (as opposed to decimal form) to table column definition?
My scenario is to pass in a ratio (in fractional form as opposed to decimal form) to each table column definition.
The following code cannot be compiled.
\documentclass{article}
\usepackage{pgf}
...
12
votes
3answers
1k views
Why doesn't \settoheight of \parbox work?
Consider the following code:
\documentclass[a4paper]{letter}
\usepackage{calc}
\usepackage{printlen}
\newsavebox{\foobox}
\newlength{\fooboxheight}
\savebox{\foobox}{
...
6
votes
1answer
395 views
Extract coordinates from 3D point
How do I extract coordinates from a three-dimensional point defined when using tikz-3dplot? I would like to perform some calculations on these (more specifically a cross-product of two vectors), but ...
4
votes
2answers
698 views
\widthof within tikzpicture
In this minimal example
\documentclass{scrartcl}
\usepackage{calc}
\usepackage{tikz}
\newlength{\TestLength}
\begin{document}
\setlength{\TestLength}{\widthof{\tikz \node {bla};}}
...
15
votes
3answers
847 views
Extract first & last characters of macro argument?
In LaTeX, how do I extract/isolate/determine the first and last characters of a macro argument?
Specifically, in the case I'm dealing with, the argument happens to be a base-10 integer (call itĀ N). ...
8
votes
1answer
1k views
Determine height and depth of letters relative to the font size
I would like to scale graphical elements (like images, tikz and tikz-timing diagrams) relative to the font size, so that they have the same height as an normal uppercase letter (i.e. X or M; I noticed ...
6
votes
4answers
1k views
How to find the ratio of a length command (e.g., \textwidth) to a reference value (e.g., 6cm) ?
How to find the ratio of a length command (e.g., \textwidth) to a reference value (e.g., 6cm) ? Actually I want to use the ratio for the \scalebox argument, e.g., \scalebox{<ratio>}.
...
5
votes
3answers
108 views
How to subtract both very large numbers and numbers smaller than one?
In the context of Scientific Notation Only For Large Numbers have we been looking for a way to handle large numbers, as pgfmathparse can't cope with these. The only package we could find was ...
4
votes
2answers
143 views
divide table cells by a certain amount
I made a mistake in the values that i put in the table. I need to divide all the values by 105. Is there a method where i can do it without having to replace this with a completely new table ?
% ...
7
votes
2answers
593 views
Create a table with calculations of binomial and poisson distribution
Well, I was looking for some tables on the internet about the binomial and poisson distribution (not the cumulative ones) in LaTeX format. But I've only found the code of the cumulative distributions, ...
23
votes
2answers
865 views
Date calculations
I'm building a LaTeX document that helps me to formulate quotations for my customers.
Since I decided to offer monthly recurring payments I'd like to have payment dates calculated automatically ...
20
votes
3answers
402 views
duodecimal page number
I would like to have page numbers in my document written in base 12. Here's an MWE
\documentclass[12pt]{article}
\usepackage[paperheight=1.8in, textheight=0.8in]{geometry}
...
14
votes
2answers
282 views
square root of number in counter
I would like to get the square root of a number which I have stored into a counter. I have been using the calc package for summation and multiplication operations, but I cannot find anything like
...
13
votes
6answers
1k views
Calculating right angle triangle side inside LaTeX
I'd like compute the width of a screen from it's diagonal and its aspect ratio inside a LaTeX document. The formula is easy to get from the Pythagorean theorem, but needs square roots.
I currently ...
17
votes
2answers
567 views
Handling different time zones
I'm looking for a way to handle date/times with different time zones. For example in svn-multi and filemod a date and time with a timezone is returned. I like to be able to compare times in different ...
11
votes
3answers
387 views
How to do simple calculation in Latex?
Consider the following macro:
\newcommand{\sxfigure}[4]{
\includegraphics[width=#1*#3 cm, height=#2*#3 cm]{#4}
}
#1 and #2 is some value to determine the width and height of the figure, #3 is to ...
11
votes
2answers
1k views
How to use \widthof as parameter to \kern
I sometimes encounter a problem when I attempt to use \widthof from the calc package, and don't know why. In the past I have just worked around it using a two step process of defining a \newdimen{} ...
5
votes
1answer
122 views
Automatic calculation of error in pgfplots
When taking in data through a file (such as table[x index=0, y index=1, y error index=2]{plots/mydata.table};) is it possible to automatically calculate the error bars (instead of putting them in ...
5
votes
2answers
914 views
How to use pgf-math inside an argument?
I response to xport's recent questions, I tried to do the following
\usepackage{pgf}
[...]
\rule{\pgfmathdivide{4}{3}\pgfmathresult mm}{5mm}
Unfortunately, this fails with the following error ...
4
votes
2answers
811 views
Coordinates A, B: compute |B-A| and angle between +x and (B-A)
This question has two parts:
why is the angle computed always 0 (should be 45)
what is a straightforward way to compute distance between coordinates (there is How can I compute the distance between ...
3
votes
1answer
1k views
Measuring height of fixed-width text box
Suppose some text is put inside a fixed width box. The text will then continue in vertical direction. How can you measure the total height of that text?
Original text:
text text text text text
...
2
votes
1answer
814 views
Calculating position in tikz
I'm trying to do calculation to be used in tikz. Here is my current code:
\def\monthtabpos#1%
{\ifthenelse{#1<7}
{\dimexpr \numexpr -3*#1 \relax cm}
{\dimexpr \numexpr -3*(#1-6) \relax ...
1
vote
4answers
440 views
Is there a simpler way to do arithmetic in PSTricks?
I want to animate PSTricks diagram, so looping is intensively used. I have 3 global variables \START, \STOP, \DELTA that should be declared in the preamble. The remaining variables in the body will ...
8
votes
6answers
525 views
Parse simple arithmetics and return the result
I want a command \ca which takes a simple arithmetic calculation as an argument and returns the result with proper decimal places. Additionally I want an boolean argument which decides if only the ...
8
votes
2answers
683 views
How to enable use of minus and plus in tex documents?
I see many cls files using plus and minus operators to set lengths. How can I use these operators (or some equivalent macro(s)) to do something like the following?
\setlength{\lengtha}{.5\textwidth}
...
7
votes
2answers
231 views
Multiplication with dimexpr?
(This post bases on: lstaddons: Dynamic linewidth calculation)
Hey everyone,
is there a way to do this with a multiplication instead of two additions?
...
7
votes
2answers
1k views
Multiply the value by decimal number in latex?
I used the following construct quite often:
\includegraphics[width=\textwidth/2]{pic.png}
But when I try to adjust the size a small bit, like this:
\includegraphics[width=\textwidth*0.45]{pic.png}
...
6
votes
2answers
535 views
“Pretty-printing” numbers with significant figures
I like to use LaTeX to display data in figures and tables. I've used arrayjobx.sty and fp.sty to extremely good effect to handle data that comes out of, e.g., Excel or other Windoze-world data ...
5
votes
1answer
109 views
How to calculate with metadata in footer
I have footer that draws on a svn version data field (package: svn-multi). I would like to perform a simple calculation that subtracts a number from the reported version.
The footer code is
...
4
votes
2answers
78 views
settototalheight issue with empty lines
I am using \settototalheight to calculate the height of the text in order to use needspace correctly.
This is the code i am using :
\documentclass[12pt]{article}
\usepackage{graphicx}
...
4
votes
1answer
94 views
How to get vertical size of table captions?
I found that the tabularht package, which allows to give a fixed vertical size for a tabular, does not take into account the vertical space taken up by a table's caption.
It stands to reason, the ...