How to get the cellwidth when inside a tabularx environment

You can normally use \linewidth (but the minipage doesn't make much sense here):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tabularx,graphicx,lipsum}

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{lXX}
bla &
\includegraphics[width=\linewidth]{example-image-a}
&
\begin{minipage}{\linewidth}\lipsum[1]\end{minipage}%
\end{tabularx}
\end{document}

The width of a X-column is saved in \TX@col@width. Define a user command and then you can access it in your table. But it is much easier to use \linewidth. Code:

\documentclass{article}

\usepackage{tabularx}

\makeatletter 
\newcommand\mytxcellwidth{\TX@col@width}
\makeatother

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{l|X|X|}
  \hline
  bla & \rule{\linewidth}{1cm} & \\ \hline
  bla & \rule{\mytxcellwidth}{1cm} &
  \begin{minipage}{\mytxcellwidth}...\end{minipage}
\end{tabularx}

\end{document}

Tags:

Tabularx