get height on a block of latex output

与世无争的帅哥 提交于 2019-12-03 09:17:30

问题


I am trying to determine how to get the height on a block of latex output (not the whole document, and not the code..but rather a block of output). As an example of what I am trying to accomplish: i were to have the latex code

$\sum_{i=0}^\infty \frac{1}{n}>\infty$ \newline hello world \newline hello universe

The height of the above block of text is dependent on a number of things-font, margin size, and of course what the text is, as changing any of these parameters changes how many inches that output would be, but with default formatting its output would be something like 2 inches high.

I am hoping there is a package that does this! I am appreciative of any pointers in the right direction!

Thanks in advance!

Georg


回答1:


Usually, the trick is to put whatever you want to measure into a box and then simply not typeset the box, but measure it:

\newdimen\height
\setbox0=\hbox{\Huge Hello, World!}
\height=\ht0 \advance\height by \dp0
The height is: \the\height



回答2:


I think this will work:

\newlength{\somenamehere}
\settoheight{\somenamehere}{\hbox{...}}

Where ... is your content you like to measure. And you can then use \somenamehere as the height of that content.


Example:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}

\begin{document}
\newlength{\heightofhw}
\settoheight{\heightofhw}{\hbox{Hello World!}}
Value = \the\heightofhw
\end{document}

Will output:

Value = 6.8872pt


Note:

  • Values of lengths are stored as points, and 1 inch ≈ 72.27 pt
  • This does not require any additional packages.

Update:

Use \hbox to correctly calculate the height of a different sized environment, but it won't work with newlines :-(



来源:https://stackoverflow.com/questions/2939450/get-height-on-a-block-of-latex-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!