How do I get the width of the current cell in tabular? (This is part of a large project I am working on.)
Here is the MWE.
\documentclass{article}
\makeatletter
\newlength{\cellwidth}
\def\s@vewidth{%
\setlength{\cellwidth}{\linewidth} % Set to \linewidth
\typeout{L\the\cellwidth L}
\setlength{\cellwidth}{\dimen0} % Set to \dimen0
\typeout{D\the\cellwidth D}
}
\begin{document}
\typeout{M\the\linewidth M}
\begin{tabular}{|c|l|p{0.4\textwidth}|}
Text\s@vewidth&More Text\s@vewidth&Even More Text\s@vewidth
\end{tabular}
\makeatother
\end{document}
\s@vewidth will be expected to store the width of the current cell in some dimension. This has been set to be both \linewidth and \dimen0 based on the advice from
ChatGPT.
But as evidenced by the following output, neither of the above gives the correct solution. The following values are not consistent.
M345.0ptM L345.0ptL D24.88ptD L345.0ptL D24.88ptD L137.9979ptL D24.88ptD
The M value is from the main document. The L and D values are the \linewidth and \dimen0 values (supposedly cell widths) from inside the table, respectively.