如何取得段落中最後一個框的自然寬度?

如何取得段落中最後一個框的自然寬度?

我想獲得段落中最後一行的自然寬度。例如下面一段的最後一行

格奧爾格·弗里德里希·伯恩哈德·黎曼(Georg Friedrich Bernhard Riemann,1826 年9 月17 日-1866 年7 月20 日)是一位有影響力的德國數學家,他對分析、數論和微分幾何做出了持久的貢獻,其中一些貢獻促進了廣義相對論的後來發展。

可能是從somerelativity(即some of them enabling the later development of general relativity.)發生斷行時,最後一行會被放入一個 hbox 中,那麼,如何取得這個 hbox 呢?

答案1

在此輸入影像描述

\documentclass{article}

\begin{document}

Georg Friedrich Bernhard Riemann (September 17, 1826 -- July 20, 1866) was an
influential German mathematician who made lasting contributions to analysis, number
theory, and differential geometry, some of them enabling the later development of
general relativity.
$$\mbox{the last line had length \the\predisplaysize}$$

\end{document}

實際上\predisplaysize設定為比自然尺寸多 2em,因此您可能需要減去 2em,具體取決於..


要取得值而不留下可見的顯示數學,您可以執行類似的操作(從 複製afterpage

\makeatletter
Georg Friedrich Bernhard Riemann (September 17, 1826 -- July 20, 1866) was an influential German mathematician who made lasting contributions to analysis, number theory, and differential geometry, some of them enabling the later development of general relativity.
{\abovedisplayshortskip\z@\abovedisplayskip\z@
    \belowdisplayshortskip\z@\belowdisplayskip\z@
$$\global\dimen\@ne\predisplaysize
 \xdef\tmp{%
      \predisplaysize\the\predisplaysize
      \prevgraf\the\prevgraf\relax}%
$$\vskip\dimexpr-\parskip-\baselineskip\relax}\tmp

new para in which we can use \the\dimen\@ne


and another new para

相關內容