[Tex/LaTex] How to enable use of minus and plus in tex documents

calculationslengths

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}
\setlength{\lengthb}{.5\textwidth}
\begin{tabular*}{\lengtha plus \lengthb}{cc}
a & b \\
\end{tabular*}

Best Answer

Use the calc package. Package description:

Adds infix expressions to perform arithmetic on the arguments of the LaTeX commands \setcounter, \addtocounter, \setlength, and \addtolength.

\documentclass{article}

\usepackage{calc}

\newlength{\lengtha}
\setlength{\lengtha}{.5\textwidth}
\newlength{\lengthb}
\setlength{\lengthb}{.5\textwidth}

\begin{document}

\begin{tabular*}{\lengtha + \lengthb}{cc}
\hline
a & b \\
\hline
\end{tabular*}

\end{document}
Related Question