4

I want to create a (par)box which starts wherever I am right now and extends to the end of the line. I noticed this related question:

Get current position in the line / get space until end of line

and, indeed, if I could get the position I could do position arithmetic; but perhaps there's another, simpler way to do it?

1

2 Answers 2

3

The following uses zref's savepos module to store the x-coordinate at the call to \fillparbox, as well as the x-coordinate after issuing an \hfill. The difference between these two x-coordinates then provides the width of a \parbox that you can place there:

enter image description here

\documentclass{article} \usepackage[margin=1in]{geometry} \usepackage[nopar]{lipsum} \usepackage{zref-savepos} \newcounter{fillparbox} \newcommand{\fillparbox}[2][c]{% \stepcounter{fillparbox}% New \fillparbox \mbox{}\zsaveposx{\thefillparbox-L}\hfill\zsaveposx{\thefillparbox-R}% Mark Left and Right end-points remaining on line. \makebox[0pt][r]{\parbox[#1]{\dimexpr\zposx{\thefillparbox-R}sp-\zposx{\thefillparbox-L}sp}{\strut #2\strut}}% } \begin{document} \lipsum[1] \fillparbox{\itshape\bfseries one two three four five six seven eight nine ten eleven twelve thirteen} \lipsum[2] \fillparbox{\itshape\bfseries one two three four five six seven eight nine ten eleven twelve thirteen} \lipsum[3] \fillparbox[t]{\itshape\bfseries one two three four five six seven eight nine ten eleven twelve thirteen} \end{document} 

You can still issue the various alignment options association with \parbox, the default being [c]entred (vertically). \struts are inserted to ensure a consistent baseline (see How to keep a constant \baselineskip when using minipages (or \parboxes)?).

3

enter image description here

You can use the pdftex \pdfsavepos extension to record the point on the line. This will also work in xetex, and with some name changes (or with luatex85 package) in luatex.

\documentclass{article} \makeatletter \newcount\zzcount \def\zz#1{\global\advance\zzcount\@ne \edef\tmp{\pdfsavepos\write\@auxout{\gdef\string\ZZ\romannumeral\zzcount{\noexpand\the\pdflastxpos}}}% \tmp \expandafter\ifx\csname ZZ\romannumeral\zzcount\endcsname\relax \message{first pass re-run latex to see zz box}% \dotfill \else \dimen@\dimexpr\csname ZZZ\romannumeral\zzcount\endcsname sp-\csname \romannumeral\zzcount\endcsname sp\relax \ifdim\dimen@>\p@ \parbox[t]% {\dimen@}% {\itshape\bfseries#1}\hfill \else \message{something wrong try deleting aux file}% XX\dotfill \fi \fi \edef\tmp{\pdfsavepos\write\@auxout{\gdef\string\ZZZ\romannumeral\zzcount{\noexpand\the\pdflastxpos}}} \tmp } \begin{document} aaaa aaa aaa aaaaaaa aaa aaa aaaaaaa aaa aaa aaaaaaa aaa aaa aaa aaaa aaa aaa aaaaaaa aaa aaa aaaaaaa aaa aaa aaaaaaa aaa aaa aaa aaaa aaa aaa aaaaaaa aaa aaa aaaaaaa aaa aaa aaaaaaa aaa aaa aaa aaa aaa aaaa aaa aaa aaa \zz{one two three four five six seven eight nine ten eleven twelve thirteen} aaa aaa aaaa aaa aaa aaa bbb bb bbb bb bbb bbbb \zz{one two three four five six seven eight nine ten eleven twelve thirteen} \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.