{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

52
votes
3answers
13k 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 ...
9
votes
1answer
4k views

simple arithmetic on index of foreach statement in tikz

Is foreach really a tikz statement or is derived from some other package? I would like to draw a horizontal axis with 7 ticks spaced 1 cm apart. I'd like to place a label under each tick that is the ...
2
votes
1answer
4k views

TikZ Coordinate calculation - calculate coordinates separately

I'm trying to calculate coordinates based on existing coordinates but each coordinate individually. The first thing which is unclear to me is how to define scalar variables. I can define coordinates ...
12
votes
2answers
989 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 ...
6
votes
2answers
777 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 ...
2
votes
1answer
1k 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 ...
19
votes
4answers
4k 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 ...
9
votes
1answer
1k 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 ...
14
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 ...
5
votes
2answers
1k views

How can I nest coordinate calculations in TikZ?

Why does this not work? I'm not using LaTeX and TikZ very much; I don't see it. \begin{tikzpicture} \coordinate (Zero) at (0,0); \coordinate[label=below:cell a] (vertexA) at (0, 10); ...
12
votes
1answer
819 views

Difference between two dates

Is there a macro that calculates the year and months from a given start date and the current date. So let's say I have 05/02/2010 (the start date), then it should do the following: Today - ...
17
votes
2answers
674 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 ...
5
votes
2answers
624 views

Adding numerical values in a LaTeX tabular column [duplicate]

Possible Duplicate: How can I automatically calculate sums in a LaTeX table? Does anyone know if the is a TeX/LaTeX package which will make an ordinary tabular environment work as a simple ...
4
votes
2answers
1k views

Calculate maximum of lengths

How can I calculate a maximum of lengths? I am aware of pgfmath's function max(x_1,x_2,...) \documentclass[a4paper,draft]{article} \usepackage{tikz} \pgfmathparse{max(3,4)} \begin{document} ...
4
votes
1answer
2k 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 ...
15
votes
3answers
2k 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}{ ...
18
votes
2answers
843 views

Automated age calculation

How can I calculate my age at compile-time in LaTeX? Something like: I'm \myage{day}{month}{year} years old. would be most awesome.
17
votes
3answers
2k 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 ...
4
votes
3answers
2k views

Can LaTeX perform simple math operations? [duplicate]

Possible Duplicate: How can I automatically calculate sums in a LaTeX table? Can LaTeX do simple math? I have a table with two columns and want to automatically add a third column which ...
6
votes
2answers
1k views

\widthof within tikzpicture

In this minimal example \documentclass{scrartcl} \usepackage{calc} \usepackage{tikz} \newlength{\TestLength} \begin{document} \setlength{\TestLength}{\widthof{\tikz \node {bla};}} ...
5
votes
2answers
1k 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 ...
2
votes
1answer
448 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} ...
2
votes
3answers
923 views

How to pass in a ratio in fractional form?

How to pass in a ratio of 4/15 (instead of its approximated decimal form of 0.266) to table definition. Final solution can be seen here. I need one more vote to close this topic.
0
votes
1answer
175 views

Why did my exact calculation still produce small gaps on the most left and right table rules?

I have specified each tabular cell width exactly using formula ##1\linewidth-2\tabcolsep-1.5\arrayrulewidth as shown in the following code snippet: \documentclass[dvips,dvipsnames,rgb]{book} ...
7
votes
5answers
2k 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>}. ...
8
votes
5answers
733 views

ConTeXt / e-TeX Real Numbers?

I've been using LaTeX for about 6 years and the calc package for a long time. Therefore, not being able to use real / floating point numbers was never really a problem. Thanks, \real! I've been ...
25
votes
2answers
2k 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 ...
29
votes
6answers
3k 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 ...
34
votes
5answers
11k 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 ...
11
votes
2answers
5k views

Performing basic arithmetic in custom commands

One thing annoying in sparklines is its verbosity and dependence on external arithmetics. For example, to depict a three bar graph of 16%, 53%, 31%, one has to write: \begin{sparkline}{4} ...
9
votes
1answer
444 views

Resources For Calculating Average Sentence Length

I'm writing my masters thesis and my supervisor has picked up my sentence structure, in that they are too long. She commented that Microsoft Word has a feature to investigate 'large' sentences. How ...
12
votes
4answers
4k 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 ...