![表单:如何将表单字段完美地放入表格单元格中?](https://linux22.com/image/388208/%E8%A1%A8%E5%8D%95%EF%BC%9A%E5%A6%82%E4%BD%95%E5%B0%86%E8%A1%A8%E5%8D%95%E5%AD%97%E6%AE%B5%E5%AE%8C%E7%BE%8E%E5%9C%B0%E6%94%BE%E5%85%A5%E8%A1%A8%E6%A0%BC%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%EF%BC%9F.png)
我能做什么文本域s 等(除了一个小的“外部分隔符”)是否完全适合表格单元格(具有其设定的尺寸)?
\documentclass[fontsize=14pt]{scrreprt}
\usepackage{tabularx, xcolor}
\usepackage{hyperref}
% Style
\renewcommand*{\DefaultOptionsofText}{print, bordercolor=red,
borderstyle={U},
bordercolor={red},
backgroundcolor=lightgray!60
}
% Textfields
\def\Name{\mbox{\TextField[name=Name,height=1em, width=0.375\textwidth]{Name:}}%
}
\def\Career{\mbox{\TextField[name=Career,height=1em, width=0.375\textwidth]{Career:}}%
}
\usepackage{mwe}
\begin{document}
\begin{Form}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{\textwidth}{|m{0.5\textwidth} | X |}
\hline
\Name & \Career \\ \hline
\end{tabularx} \par
\end{Form}
\end{document}
答案1
通过测量标签可以相当轻松地确定宽度。高度则比较困难:最佳值还取决于使用的 pdf 查看器以及您想要实现的确切视觉效果。
\documentclass[fontsize=14pt]{scrreprt}
\usepackage{tabularx, xcolor,calc}
\usepackage{hyperref}
% Style
\renewcommand*{\DefaultOptionsofText}{print, bordercolor=red,
borderstyle={U},
bordercolor={red},
backgroundcolor=lightgray!60
}
% Textfields
\newlength\lentmpa
\newcommand\Name{%
\settowidth\lentmpa{Name: }%
\mbox{%
\TextField[name=Name,
height=\dimexpr\normalbaselineskip-4\arrayrulewidth,
width=\dimexpr\linewidth-\lentmpa]{Name:}}}
\newcommand\Career{\settowidth\lentmpa{Career: }%
\mbox{%
\TextField[name=Career,
height=\dimexpr\normalbaselineskip-4\arrayrulewidth,
width=\dimexpr\linewidth-\lentmpa]{Career:}}%
}
\def\LayoutTextField#1#2{% label, field
#1 \raisebox{-0.3\normalbaselineskip+2\arrayrulewidth}[0pt][0pt]{#2}%
}
\usepackage{mwe}
\begin{document}
\begin{Form}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{\textwidth}{|m{0.5\textwidth} | X |}
\hline
\Name & \Career \\ \hline
\end{tabularx} \par
\end{Form}
\end{document}