![表单:如何将表单字段完美地放入多列单元格中?](https://linux22.com/image/388291/%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%E5%A4%9A%E5%88%97%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%EF%BC%9F.png)
我有一个后续问题:表单:如何将表单字段完美地放入表格单元格中?
如果我使用多列,计算方法会再次崩溃。
我应该做些什么不同的事情?
\documentclass[fontsize=14pt]{scrreprt}
\usepackage{tabularx}
\setlength\arrayrulewidth{1pt}
\usepackage{xcolor}
\usepackage{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}%
}
\begin{document}
\begin{Form}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{\textwidth}{|m{0.5\textwidth} | X |}
\hline
\Name & \Career \\ \hline
\multicolumn{2}{| l |}{\Career} \\ \hline
\end{tabularx} \par
\end{Form}
\end{document}
答案1
正如这里所建议的由于乳胶中的多列导致列间距错误,您可以使用固定宽度的多列:
\multicolumn{2}{| p{\dimexpr\linewidth-2\arrayrulewidth-2\tabcolsep} |}
我减去规则的宽度和内部填充以适应线宽。MWE:
\documentclass[fontsize=14pt]{scrreprt}
\usepackage{tabularx}
\setlength\arrayrulewidth{1pt}
\usepackage{xcolor}
\usepackage{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}%
}
\begin{document}
\begin{Form}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{\textwidth}{|m{0.5\textwidth} | X |}
\hline
\Name & \Career \\ \hline
\multicolumn{2}{| p{\dimexpr\linewidth-2\arrayrulewidth-2\tabcolsep} |}{\Career} \\ \hline
\end{tabularx} \par
\end{Form}
\end{document}