2

Here is a simple equation $$ \int_a^b f(x) \, dx $$ how do I calculate the box height? How do I round to the nearest multiple of 12pt ?

4

You could use the \settoheight and \settodepth macros, which take two arguments, to measure the height above and depth below the baseline. For Computer Modern fonts and a basic document font size of 10pt, the total heights of the integral formulas work out to be 25.1pt and 14.0pt for display style and text style, respectively.

To force the heights of the formulas to either 24pt (in the display style case) or 12pt (in the text style case), you could use a \resizebox* directive. Note: don't use \resizebox, use \resizebox*.

enter image description here

\documentclass[10pt]{article}
\newlength\bxheight
\newlength\bxdepth
\newlength\bxtot
\newcommand\myint{\int_a^b f(x)\,dx} % store the formula (it gets used a lot)
\usepackage{graphicx} % for \resizebox macro
\usepackage{amsmath}  % for \text macro
\usepackage{booktabs}
\begin{document}

\settoheight{\bxheight}{$\displaystyle\myint$}
\settodepth{\bxdepth}{$\displaystyle\myint$}
\setlength\bxtot{\dimexpr\bxheight+\bxdepth\relax}
$\displaystyle\myint$ has height \the\bxheight, depth \the\bxdepth, and total height \the\bxtot.

\medskip
\settoheight{\bxheight}{$\myint$}
\settodepth{\bxdepth}{$\myint$}
\setlength\bxtot{\dimexpr\bxheight+\bxdepth\relax}
$\myint$ has height \the\bxheight, depth \the\bxdepth, and total height \the\bxtot.

\[
\begin{array}{@{}lcc@{}}
& \text{natural size} & \text{rounded to nearest } \\
& & \text{multiple of 12pt} \\
\midrule
\text{display style} & \displaystyle\myint & \resizebox*{!}{24pt}{$\displaystyle\myint$} \\[3ex]
\text{text style}    & \myint              & \resizebox*{!}{12pt}{$\myint$}
\end{array}
\]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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