帶有“textpos”的意外框尺寸

帶有“textpos”的意外框尺寸

更新我已經根據以下發現發布了 LaTeX 樣式文件, CXLTX 絕對位置,(初期)的一部分CXLTX 風格系列,這使得在頁面上精確定位單行文字變得更加容易。拉取請求:太棒了!

我試著用 CSS 定位文字position: absolute並發現文字位置基本上效果很好的包。在文件中,他們說(p4)“由環境定位的盒子\textblock與其內部的文本塊(或其他材料)緊密配合”,但是當我嘗試

\documentclass[a5paper]{memoir}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setlength{\parskip}{\baselineskip}
\setlength{\parindent}{0pt}

\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{0.1mm}
\setlength{\TPVertModule}{0.1mm}
\textblockorigin{0mm}{0mm}

% not needed, but makes for easier measuring:
\usepackage[top-left]{pagegrid}

\begin{document}

\TPshowboxestrue
\begin{textblock}{150}[1,0](500,000)\flushright helo\end{textblock}
\begin{textblock}{150}[1,0](500,200)\flushright world\end{textblock}
\begin{textblock}{150}[1,0](500,400)\flushright gX\end{textblock}
\begin{textblock}{150}[1,0](700,400)\flushright .\end{textblock}

\end{document}


\setlength{\parskip}{0pt}

\setlength{\parskip}{-\baselineskip}

我得到的是

在此輸入影像描述

因此,雖然盒子的右邊緣正確定位在 500(十分之一毫米),頂部邊緣分別正確定位在 0、200 和 400,並且盒子的下緣確實如廣告中那樣緊緊包裹在下降部分上,盒子仍然是8 毫米高– 我怎樣才能像廣告上那樣包裝它們?

答案1

現在這很簡單......有時寫下一個問題可以讓你解決一個問題。作為記錄:

我錯誤地認為將某些內容放入 an 中的textpos textblock行為有點像將內容放入頁面或 a 中minipage,即段落“跳過”將被默默地刪除。

不是這樣的。

首先,設定

\setlength{\parskip}{0pt}

降低了盒子的高度;然後,

\setlength{\parskip}{-\baselineskip}

產生了這個:

在此輸入影像描述

這有點違反直覺——我的意思是,段落之間的空間應該等於“段落上方零空白”,不是嗎?

筆記在現實世界中,您不想將\parskip其全域設定為此處顯示的令人驚訝的值,而是使其在本地textblock環境中出現(並且可能將其轉換為新的巨集)。

更新作為後續工作,我定義了一個方便的巨集來簡化文字的絕對定位。這裡是:

\newdimen\textposstrutheight
\newdimen\textposstrutwidth
\newdimen\textposstrutdepth
\newdimen\textposstrutlength
\textposstrutwidth=0.5mm
\textposstrutheight=2.7mm
\textposstrutdepth=2.8mm
\textposstrutlength=\dimexpr\textposstrutheight+\textposstrutdepth
\newcommand{\textposstrut}{{\color{blue}\vrule height\textposstrutheight width\textposstrutwidth depth\textposstrutdepth}}

\newcommand{\placeflushright}[4]{%
  \begin{textblock}{#1}[1,0.5](#2,#3)\flushright{\textposstrut}#4\end{textblock}%
  }

現在,當你這樣做時

\begin{textblock}{150}[1,0.5](500,000)\flushright\textposstrut helo\end{textblock}
\begin{textblock}{150}[1,0.5](500,200)\flushright\textposstrut world\end{textblock}
\begin{textblock}{150}[1,0.5](500,400)\flushright\textposstrut gX\end{textblock}
\begin{textblock}{150}[1,0.5](700,400)\flushright\textposstrut .\end{textblock}

\placeflushright{150}{300}{400}{gX}

(在與上面問題所示相同的文檔設定中)你會得到

在此輸入影像描述

其中左下角的 表示文字確實已正確定位(從文件邊緣測量的右gX邊緣的基線)。X( 30mm, 40mm )

請注意,為了演示目的,此處定義的支柱具有可見寬度;此外,它的高度和深度都經過精心定制,以匹配此處使用的特定字體尺寸 - 當您切換到另一種字體時,很可能兩者\textposstrutheight和 -depth都必須重新定義。

相關內容