答案:https://tex.stackexchange.com/a/630701/294918当我发现这个问题时,它基本上满足了我的要求;即:TextFields 自动调整大小。
我尝试修改示例,将一个 CheckBox 和两个 TextField 放在同一行/列上。
这有效:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{multirow}
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\renewcommand\LayoutTextField[2]{%
#1 \raisebox{-3.0pt}{#2}%
}
\newlength\templength
\newcommand{\DefaultTextField}[2][]{%
\settowidth\templength{#2 }%
\mbox{\TextField[align=1,bordercolor=0 1 1,backgroundcolor={},#1,width=\dimexpr\linewidth-\templength]{#2}}%
}
\renewcommand\LayoutCheckField[2]{%
\raisebox{-1.0pt}{#2}\hspace*{2mm}#1%
}
\newcommand{\DefaultCheckBox}[2][]{%
\mbox{\CheckBox[bordercolor=0 0 0,backgroundcolor={},borderwidth=0.4mm,height=3mm,width=3mm,#1]{#2}}%
}
\begin{document}
\begin{Form}
\renewcommand{\arraystretch}{1.5}%
\noindent
\begin{tabular}{@{}L{\dimexpr0.5\textwidth-\tabcolsep}L{\dimexpr0.5\textwidth-\tabcolsep}@{}}
\DefaultTextField[name=firstname]{Firstname} &
\DefaultTextField[name=lastname]{Lastname}\\ \hline
\DefaultTextField[name=address1]{Address} &
\DefaultTextField[name=address2]{ZIP, City}\\ \hline
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=mail,width=0.25\textwidth]{E-Mail}}\\ \hline
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=phone,width=0.25\textwidth]{Phone/Mobile}}\\ \hline
Foo\hfil\DefaultCheckBox[name=bar]{Bar}\hfil & \DefaultTextField[name=something,width=0.25\textwidth]{other} \\ \cline{2-2}
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=number,width=0.25\textwidth]{Something}}\\ \hline
\end{tabular}
\end{Form}
\end{document}
但在以下示例中,第二个 \begin{tabular} 环境无法按预期/期望工作:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{multirow}
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\renewcommand\LayoutTextField[2]{%
#1 \raisebox{-3.0pt}{#2}%
}
\newlength\templength
\newcommand{\DefaultTextField}[2][]{%
\settowidth\templength{#2 }%
\mbox{\TextField[align=1,bordercolor=0 1 1,backgroundcolor={},#1,width=\dimexpr\linewidth-\templength]{#2}}%
}
\renewcommand\LayoutCheckField[2]{%
\raisebox{-1.0pt}{#2}\hspace*{2mm}#1%
}
\newcommand{\DefaultCheckBox}[2][]{%
\mbox{\CheckBox[bordercolor=0 0 0,backgroundcolor={},borderwidth=0.4mm,height=3mm,width=3mm,#1]{#2}}%
}
\begin{document}
\begin{Form}
\renewcommand{\arraystretch}{1.5}%
\noindent
\begin{tabular}{@{}L{\dimexpr0.5\textwidth-\tabcolsep}L{\dimexpr0.5\textwidth-\tabcolsep}@{}}
\DefaultTextField[name=firstname]{Firstname} &
\DefaultTextField[name=lastname]{Lastname}\\ \hline
\DefaultTextField[name=address1]{Address} &
\DefaultTextField[name=address2]{ZIP, City}\\ \hline
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=mail,width=0.25\textwidth]{E-Mail}}\\ \hline
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=phone,width=0.25\textwidth]{Phone/Mobile}}\\ \hline
Foo\hfil\DefaultCheckBox[name=bar]{Bar}\hfil & \DefaultTextField[name=something,width=0.25\textwidth]{other} \\ \cline{2-2}
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=number,width=0.25\textwidth]{Something}}\\ \hline
\end{tabular}
\vspace{10ex}
\renewcommand{\arraystretch}{1.5}%
\noindent
\begin{tabular}{@{}L{\dimexpr0.5\textwidth-\tabcolsep}L{\dimexpr0.5\textwidth-\tabcolsep}@{}}
\DefaultTextField[name=firstname]{Firstname} &
\DefaultTextField[name=lastname]{Lastname}\\ \hline
\DefaultTextField[name=address1]{Address} &
\DefaultTextField[name=address2]{ZIP, City}\\ \hline
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=mail,width=0.25\textwidth]{E-Mail}}\\ \hline
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=phone,width=0.25\textwidth]{Phone/Mobile}}\\ \hline
%Foo\hfil\DefaultCheckBox[name=bar]{Bar}\hfil & \DefaultTextField[name=something,width=0.25\textwidth]{other} \\ \cline{2-2}
\DefaultCheckBox[name=bar]{Bar} & \DefaultTextField[name=something1]{other1} & \DefaultTextField[name=something2]{other2}\\
\multicolumn{2}{@{}p{\textwidth}@{}}{\DefaultTextField[name=number,width=0.25\textwidth]{Something}}\\ \hline
\end{tabular}
\end{Form}
\end{document}