get height on a block of latex output

后端 未结 2 2056
孤独总比滥情好
孤独总比滥情好 2021-02-04 09:07

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

2条回答
  •  死守一世寂寞
    2021-02-04 09:21

    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 :-(

提交回复
热议问题