# How to make 'Form' fields in line with other text

I used the second answer (by Christian Lindig) to this question to make my own fillable PDF form. I edited it slightly to suit my needs. I tried to make a MWE:

\documentclass[11pt]{article}

\usepackage[margin=2cm]{geometry}
\usepackage[pdftex]{hyperref}
\usepackage{xcolor}
\def\LayoutTextField#1#2{#2} % override default in hyperref

\begin{document}
\newlength\somewidth

\def\lbl#1{\hbox to 2cm{#1\hfill\strut}}
\def\labelline#1#2{\lbl{#1}\vbox{\hbox{\TextField[name=#1,width=#2,bordercolor=white]{\null}}\kern2pt\hrule}}

\def\q#1{\hbox to \hsize{\labelline{#1}{\somewidth}}\vskip1.4ex}

\begin{Form}
\q{Question 1}
\q{Question 2}
\q{Etc}
\end{Form}

\noindent I want to write some text first. \begin{Form} \q{question} \end{Form} some more text \begin{Form} \q{question2} \end{Form}

\end{document}


When I do this throughout my document normally I play with the size of the forms (the '\somewidth' and 3cm in this case). I know it is cumbersome but I don't have to do it often and it works with my lack of understanding.

I want to have two form fields in a single line that already has text in it. I have noticed that the environment 'Form' always ends the line after itself, which is problematic if I want to put text or another form next to it. In the example, 'some more text' would be in the same line after the form called 'question' and then the form 'question2' would come behind that as well (ignoring the fact that in this case, it might not all fit in one line). So, how do I prevent this environment from ending the line, or should I solve this in another way?

• You should always make complete examples to demonstrate a problem, don't show only snippets where it is unclear how you actually combine them. Jun 11 '19 at 12:34
• You're right, of course. I changed the question quite a bit, I hope it is clear now
– Iris
Jun 11 '19 at 12:56
• There should be only one Form-environment in the whole document. But beside this: don't use the primitives \hbox and \vbox, you clearly have no idea how they behave. Use latex commands like \makebox and \parbox. Jun 11 '19 at 13:02
• I put the first Form with the three questions in it to show how the environment normally behaves. Not completely minimal, I agree, but I thought it might be helpful. I definitely need more than one Form-environment to demonstrate how I would want two different ones in one line.
– Iris
Jun 11 '19 at 13:11
• Regarding \hbox and \vbox, I indeed have no clue how they behave.. nor do I know how \makebox or \parbox works. I clearly stated at the beginning of my question that I used an answer of the question I linked to. I did not create this code, I'm merely using it because I don't know how to do it otherwise. If this is what I need to change to solve my 'problem', I'll happily do so but I'd appreciate it if someone could show me how
– Iris
Jun 11 '19 at 13:11

We can't use more than one form, so we first need to remove unnecessary \begin{form} and \end{form}, then we have to redefine the command \q so it doesn't end the current line or paragraph, some thing like this

\def\q#1{\hbox {\labelline{#1}{\somewidth}}}.

Here is a MWE

\documentclass[11pt]{article}

\usepackage[margin=2cm]{geometry}
\usepackage[pdftex]{hyperref}
\usepackage{xcolor}

\def\LayoutTextField#1#2{#2} % override default in hyperref

\newlength\somewidth

\def\lbl#1{\hbox to 2cm{#1\hfill\strut}}
\def\labelline#1#2{\lbl{#1}\vbox{\hbox{\TextField[name=#1,width=#2,bordercolor=white]{\null}}\kern2pt\hrule}}

\def\q#1{\hbox {\labelline{#1}{\somewidth}}}
\begin{document}

\begin{Form}
\q{Question 1}
\q{Question 2}
\q{Etc}

\noindent I want to write some text first. \q{question}  some more text  \q{question2}
\end{Form}

\end{document}