在 tabularx 环境中是否可以检索具有 ap{} 列的行的高度?
最终,我希望能够获取 X 列单元格的宽度和高度。宽度可以通过 获得\TX@col@width
,但如何获取高度?
用例:我想使用 tabularx 作为环境,将 hyperref 包的 \TextField 完美地放入表格单元格中。要调整字段大小,我需要宽度和高度。
\documentclass{scrartcl}
\usepackage[table,xcdraw]{xcolor}
\definecolor{hyperlinkblue}{RGB}{204,215,251}
\usepackage{tabularx}
\usepackage{hyperref}
\hypersetup{pdflinkmargin=-.5pt}
\def\LayoutTextField#1#2{#2} % ignore label of \TextField
\makeatletter
% Determine the width of a cell including the tabcolsep
% First argument: number of columns
% TODO \TX@col@width does not calculate the width correctly. Sometimes it includes \tabcolsep sometimes not
\newcommand{\tabularxCellWidth}[1]{\dimexpr #1\TX@col@width+ 2\tabcolsep\relax}
\makeatother
% TODO missing: get dynamic height of a cell to resize the TextField always correctly
\newcommand{\tabularxCellHeight}{1em}
\newcommand{\myTextField}[1]{\TextField[name={#1}, width=\tabularxCellWidth{1}, height=\tabularxCellHeight, default={#1}]{}}
% Use multicolumn to ignore tabcolsep @{} for cells with a TextField
% TODO Problem: multicolumn removes the outer borders from the table
\newcommand{\TabularTextField}[1]{\multicolumn{1}{@{}@{}X@{}@{}}{\myTextField{#1}}}
\begin{document}
\begin{tabularx}{\textwidth}{|p{3cm}|X|}
\hline
text which may have line breaks & Get width and height of this cell \\
\hline
but this has none & \TabularTextField{this text field has perfect size} \\
\hline
text which may have many many many many many many line breaks & \TabularTextField{resize me} \\
\TabularTextField{resize me too} & text which may have many many many many many many line breaks\\
\TabularTextField{resize me tooo} & text which may have many many many many many many line breaks\\
\hline
\end{tabularx}
\end{document}
我面临的另一个问题是计算宽度和仅删除特定单元格的 tabcolsep。我可以用 删除 tabcol \multicolumn
,但这也会删除边框。将它们重新添加可能会重复一些边框,这看起来很糟糕。还有其他解决方案吗?
此外,\TX@col@width
并不总是返回单元格的正确宽度。有时它包含,\tabcolsep
有时不包含。
这是我的 PDF 的片段,显示了我所面临的问题。
- 红色:宽度计算错误(超出
2*\tabcolsep
- 蓝色:缺少边框(多列会删除边框,但将其添加到多列会重复一些边框)
- 绿色:错误的场地高度