![垂直居中 \makebox](https://linux22.com/image/258544/%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD%20%5Cmakebox.png)
代码:
\documentclass{article}
\usepackage{xcolor,hyperref}
\makeatletter
\def\Fld@bordercolor{0 0 0} % this works.
\makeatletter
\begin{document}
\begin{Form}
\setlength\unitlength{1cm}
\begin{tabular}{|l|}
\hline
S + \makebox(4,1){\TextField[name=textfield,width=3cm,height=0.5cm]{Text}} \\
\hline
\end{tabular}
\end{Form}
\end{document}
输出:
输入框向上移动了。如何让它垂直居中,与“S +”在同一行?
答案1
像这样?
代码:
\documentclass{article}
\usepackage{xcolor,hyperref}
\makeatletter
\def\Fld@bordercolor{0 0 0} % this works.
\makeatletter
\begin{document}
\begin{Form}
\setlength\unitlength{1cm}
\begin{tabular}{|l|}
\hline
\phantom{S}\makebox(4,1){ S+\TextField[name=textfield,width=3cm,height=0.5cm]{Text}} \phantom{S}\\
\hline
\end{tabular}
\end{Form}
\end{document}
请注意,\phantom{S}
用于在 TextField 之前和之后获取一些额外的空白。
这也是一个基于 TikZ 的解决方案:它也需要xparse
包。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{xparse}
% TexTForm: arguments:
% #1 (optional): first letter - default = S
% #2 (optional): text - default = Text
% #3 (mandatory): width (set also the unit, i.e. cm)
% #4 (mandatory): height (set also the unit, i.e. cm)
\NewDocumentCommand{\TexTForm}{O{S} O{Text} m m}{
\begin{tikzpicture}[baseline=-0.5ex,show background rectangle]
\node[draw, minimum width=#3, minimum height=#4] (form) {};
\node[left, align=left, yshift=1ex]at (form.south west)(text){#1 + #2};
\end{tikzpicture}
}
\begin{document}
\TexTForm{3cm}{0.5cm}\\[2ex]
\TexTForm[T][Other text]{4cm}{0.75cm}\\[2ex]
\TexTForm[Hello][Some other text]{5cm}{1cm}
\end{document}
结果: