TransWikia.com

Textpos: Let text end, instead of starting at specified coordinate

TeX - LaTeX Asked by user224041 on December 6, 2020

I am trying to fill out a pdf form using LaTeX with the package pdfoverlay and textpos.
The problem
When I specify a coordinate with textpos and give it some text, the text will start at the coordinate, but I want the end of the text to end at the coordinate (you can see on the picture I have specified a coordinate where the form ends, but instead of the text ending there it begins)

I have asked others about this and there was some confusion, someone thought I was trying to create a form, I am not, the underline and all is already part of the pdf I am filling out.

2 Answers

You didn't show what you are doing exactly, but if the left edge of the text is being placed where you want the right edge, then using llap{AAAA} will put the right edge there. That probably looks like

begin{textblock*}{some_width}(hsize,vert_pos)
 llap{AAAA}
end{textblock*}

It is somewhat annoying that the textpos package only positions text blocks contained in the equivalent of parbox. It would be nice to also have a type that was packaged like makebox.

The llap command (left overlap) comes from plain TeX, and it does not follow the paragraph parameters of the textblock, so the width parameter is irrelevant, as is the default centering performed by the textblock. (llap is a bare hbox, and goes on the vertical list instead of starting a paragraph.)

Alternatively, to do the job using the positioning parameters of textblock, you have to get a handle on the right edge of the text, and the easiest way is to push it to the right edge of the text block. So then

begin{textblock*}{textwidth}[1,1](hsize,42mm)
  raggedleft AAAAA
end{textblock*}

The width (textwidth) just has to be anything wider than the text. The [1, indicates positioning at the right edge of the text, and raggedleft pushes the text to the right edge.

I would probably do

newcommandfillin[2]{% #1 = position, #2 = text
  begin{textblock*}{textwidth}[1,1](hsize,#1)
     raggedleft #2
  end{textblock*}}

Correct answer by Donald Arseneau on December 6, 2020

See the textpos manual, Sect.1.3.3 Choosing the textblock reference point:

You may give an optional argument to the {textblock} environment, specifying which point in the box is to be placed at the specified point:

begin{textblock}{⟨hsize⟩}[⟨ho⟩,⟨vo⟩](⟨hpos⟩,⟨vpos⟩)
text...
end{textblock}

The coordinates ⟨ho⟩ and ⟨vo⟩ are fractions of the width and height of the text box, respectively, and state that the box is to be placed so that the reference point (⟨ho⟩,⟨vo⟩) within the box is to be placed at the point (⟨hpos⟩,⟨vpos⟩) on the page. The default specification is [0,0], indicating the top left of the box; the argument [0,1] (for example) would specify the bottom left, and [0.5,0.5] the middle.

There are further details, including how to default this, later in that section.

Answered by Norman Gray on December 6, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP