Is it possible to retrieve the height of a row, which has a p{}-column in an tabularx environment?
Ultimately I want to be able to get the width and height of the X column cells.
The width is available by \TX@col@width, but how can I get the height?
Usecase: I want to fit a \TextField of the hyperref package perfectly in a table cell using tabularx as environment. To size the field, I need a width and height.
\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}
Another problem I face is the calculation of the width and the removal of the tabcolsep for only a specific cell.
I can remove the tabcol with a \multicolumn, but this will also remove the borders. Adding them back might duplicate some borders, which looks bad.
Is there another solution to this?
Furthermore \TX@col@width does not always return the correct width of a cell. Sometimes it includes the \tabcolsep sometimes it does not.
Here is a snipped of my pdf, which shows the problems I face.
- red: error in width calculation (overshoots by
2*\tabcolsep - blue: missing borders (multicolumn removes borders, but adding them to multicolumn duplicates some borders)
- green: wrong field height

\begin{document} \begin{tabularx}{\textwidth}{|p{3cm}|X|@{}c@{\rule[-4em]{0pt}{4em}}} \hline text which may have line breaks & Get width and height of this & \ \hline text which may have many many many many many many line breaks & \href{https://tex.stackexchange.com/questions/530775}{resize me} & \ \hline but this has none & \href{https://tex.stackexchange.com/questions/530775}{resize me too} & \\hline \end{tabularx} \end{document}˙`.
– Zarko Mar 02 '20 at 12:53\TextFieldsto fill the respective cell perfectly. I'll edit my MWE. – Carsten Mar 02 '20 at 13:17\TabularTextField. InXcolumn type you shouldn't change /adopt column width with to its content. It is prescribed with column type. For test use code from my previous comment and delete in it last column and then see, if result is close to what you like to have. – Zarko Mar 02 '20 at 14:11\TextField(the blue area in which you can enter text) to fill the respective cell? – Carsten Mar 02 '20 at 14:24\TabularTextFieldnot show up). Does text in\TabularTextFieldcan have more than one line? Unfortunately I'm lost in your code ... – Zarko Mar 02 '20 at 15:31sumatra. I'm sorry but I will give up. I can't help you. – Zarko Mar 02 '20 at 15:54