Featured Book

LaTeX Beginners Guide

Who is online

In total there are 6 users online :: 0 registered, 0 hidden and 6 guests (based on users active over the past 5 minutes)
Most users ever online was 424 on Sat May 04, 2013 4:33 pm

Users browsing this forum: No registered users and 6 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

Measure remaining length of line Topic is solved

Add tags Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)

Measure remaining length of line

Postby rhino7890 on Fri Sep 24th, 2010

I am using the package eforms as found in the AcroTex bundle. With it, I am trying to make an electronic form in which the user fills out text fields. With eforms, you can make interactive text boxes in LaTeX using the command \textField{<ID>}{<box width>}{<box height>}.

Where I run into trouble is the length of the text box. The way that I would like the form to look is as follows:

text1: _______________________________
text2: _______________________________
...
textN: _______________________________

where the underline section is where the interactive text field exists. As the command \textField requires an absolute length to specify the box width, I need some way of measuring the remaining length of the current line. Commands like \linewidth only return the current linewidth of the environment and not the remaining width of the current line. I also tried some variations of \hfill but without any luck. I even tried subtracting the length the leading text (by measuring it with the command \settowidth{\gnat}{text}) from the \linewidth value, but this was inconsistent from line to line.

Does anyone have any ideas on how I can get a text box to stretch the remaining length of the page?
Last edited by rhino7890 on Fri Oct 1st, 2010, edited 1 time in total.
rhino7890
 
Posts: 10
Joined: Fri Sep 24th, 2010

Re: Measure remaining length of line  Topic is solved

Postby gmedina on Sat Sep 25th, 2010

Hi,

in the code below I defined a command \MyField that solves your problem:

Code: Select all  •  Open in writeLaTeX
\documentclass{book}
\usepackage[pdftex]{eforms
}

\newsavebox\mybox
\newlength\mylen
\newlength\fieldlen

% Syntax: \MyField{title-of-the-field}{text-before-the-field}
\newcommand\MyField[2]{%
  \sbox\mybox{#2}
  \settowidth\mylen{\usebox\mybox}
  \setlength\fieldlen{\linewidth}
  \addtolength\fieldlen{-\mylen}
  \addtolength\fieldlen{-1em}
  \par\noindent\usebox\mybox\hspace*{1em}\hfil\textField{#1}{\the\fieldlen}{20pt}\par\medskip
}

\begin{document}

\MyField{field1}{Text}

\MyField{field2}{Text two}

\MyField{field3}{Text three is longer}

\end{document
}


Feel free to modify my example to suit your needs.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
gmedina
 
Posts: 2313
Joined: Wed Jul 11th, 2007
Location: Colombia

Re: Measure remaining length of line

Postby rhino7890 on Mon Sep 27th, 2010

Awesome! That did the trick. Thanks so much!
rhino7890
 
Posts: 10
Joined: Fri Sep 24th, 2010

Re: Measure remaining length of line

Postby martin_gm on Tue Apr 24th, 2012

Just to clarify the herein provided solution:

You don't actually measure the remaining of the current line, you measure the beginning of the line and subtract it from \linewidth.

At least that's what the example code does. I don't know if there is actually a way to get the remainder of the line. I feel like it should be possible b/c LaTeX needs to know. How else could it produce the wonderful "overful \hbox" greetings?
martin_gm
 
Posts: 1
Joined: Tue Apr 24th, 2012


Return to Text Formatting

Who is online

Users browsing this forum: No registered users and 6 guests