Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\end{document}

But what if I have lengths instead of numbers?

\documentclass[a4paper,draft]{article}

\usepackage{tikz}
\newlength{\foo}
\setlength{\foo}{1cm}

\newlength{\baz}
\setlength{\baz}{1cm}

\pgfmathparse{max(\foo,\baz)}

\newlength{\qux}
\setlength{\qux}{\pgfmathresult}

\pgfmathresult doesn't have a unit of measurement.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

The result is actually a length in points (pt) without the unit. You can simply add this unit again:

\setlength{\qux}{\pgfmathresult pt}

There is also the \pgfmathsetlength macro:

\pgfmathsetlength{\qux}{max(\foo,\baz)}
share|improve this answer
    
That's great, thanks! –  ipavlic Feb 25 '11 at 14:09
add comment

I also found a solution with calc package:

\usepackage{calc}

\setlength{\qux}{\maxof{\foo}{\baz}}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.