# Unexpected box sizes with textpos

UPDATE i've since published a LaTeX style file based on the below finds, CXLTX Position Absolute, part of the (incipient) CXLTX Style Collection, which makes it easier to precisely position one-liners on the page. pull requests: awesome!

i'm trying to position text à la CSS position: absolute and found the textpos package which basically works great. in the documentation they say (p4) that "the box that is positioned by the \textblock environment is a tight fit to the block of text (or other material) inside it, but when i try

\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}


what i get is

so while the right edges of the boxes is correctly positioned at 500 (tenths mm) and the top edges as such correctly at, respectively, 0, 200, and 400, and the lower edges of the boxes do wrap tightly around the descenders as advertised, the boxes are still 8mm high – how can i have them wrap as advertised?

now this was an easy one... sometimes writing down a question leads you to solving a problem. for the record:

i had incorrectly assumed that putting something into an textpos textblock would act a bit like putting stuff onto a page or into a minipage, i.e., paragraph 'skips' would be silently elided.

not so.

first, setting

\setlength{\parskip}{0pt}


brought a reduction of the box heights; then,

\setlength{\parskip}{-\baselineskip}


yielded this:

which is sort of counter-intuitive—i mean, zero space between paragraphs should equal 'zero whitespace above paragraph', no?

Note in the real world, you would not want to set \parskip globally to the surprising value shown here, but rather make it appear locally, inside the textblock environments (and maybe cast that as a new macro).

Update as a follow-up, i've defined a handy macro that simplifies the absolute positioning of text. here it is:

\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}%
}


now, when you do

\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}


(within the same document setup as shown in the question, above) you get

where the gX in the bottom left demonstrates that the text has indeed been positioned correctly (the baseline of the right edge of the X being at ( 30mm, 40mm ) measured from the edge of the document).

note that the strut as defined here has a visible width for the sake of demonstration; also, its height and depth have been carefully tailored so as to match the specific font dimensions used here—when you switch to another font, chances are that both \textposstrutheight and -depth will have to be re-defined.

• Half of your problems would be solved if you don't set \parskip to a non zero value: have mercy of your readers. ;-)` – egreg Mar 25 '14 at 17:41
• i do not normally do this; in the general case, i think using either whitespace between paragraphs or indenting the first line are the best ways to indicate paragraph breaks. however, parskip = parindent = 0 does have its uses. here it is done solely to demonstrate how parskip interacts with textpos boxes in unexpected ways. – flow Mar 25 '14 at 17:52