[Tex/LaTex] Table cell overflow

boxesheighttablestabularx

Consider this document example:

\documentclass[a4paper,draft]{article}

\usepackage{calc}
\usepackage[demo]{graphicx}
\usepackage{tabularx,multirow}

\usepackage{geometry}
\geometry{hmargin=0cm}

\newlength\framewidth
\setlength{\framewidth}{\paperwidth}
\addtolength{\framewidth}{-3cm}

\begin{document}
\centering

\fbox{
\begin{tabularx}{\framewidth}{XXX}
\multirow{3}{0.30\framewidth}{\centering
\includegraphics[width=0.2\textwidth, height=1cm]{test}\vspace{0.1cm}\linebreak\sffamily\tiny
subtext\linebreak
more text} &%
\multirow{3}{0.30\framewidth}{\centering\large\textsc{Project name}\linebreak\textbf{Current document, more text, and even more text, still more text}} &%
a \\
& & b \\
& & c \\
\end{tabularx}
}
\end{document}

I've marked with yellow color the text that was overflown out of the cell. Also, if I put everything in a box, and measure that box, it is shorter than actual text contained in the box. Why is that?

Overflown table cell

Best Answer

You are using \multirow{3}{...} for this cell and therefore explicitly requesting three lines, but then you have enough text for four lines. Either change it to \multirow{4}{...} and add a \\ or change the column type to p{.3\framewidth}.

Note that AFAIK \multirow sets the official height of the content to be only the first line and the rest is then part of the depth.

See also the answers to the questions "Why doesn't \settoheight of \parbox work?" and "Measuring height of fixed-width text box" which explain how to measure the correct height for such boxes.


In response to the OP's comment:

You could define all three columns as p type columns and enter the right side content as one cell, like the others. You can use \newline as line break command:

\documentclass[a4paper,draft]{article}

\usepackage{calc}
\usepackage{graphicx}
\usepackage{tabularx,multirow}

\usepackage{geometry}
\geometry{hmargin=0cm}

\newlength\framewidth
\setlength{\framewidth}{\paperwidth}
\addtolength{\framewidth}{-3cm}

\begin{document}
\centering

\fbox{%
\begin{tabularx}{\framewidth}{p{.3\framewidth}p{.3\framewidth}p{.3\framewidth}}
 \multirow{3}{0.30\framewidth}{%
   \centering
   %\includegraphics[width=0.2\textwidth]{Images/Logo}%
   \rule{.2\textwidth}{1cm}
   \vspace{0.1cm}\linebreak\sffamily\tiny
   subtext\linebreak
   more text} &%
   \centering\large\textsc{Project name}\linebreak\textbf{Current document, more text, and even more text, still more text}
  &%
  { a \newline b \newline c \newline } \\
\end{tabularx}%
}
\end{document}

I think the tabular environment might be not the best option in this case. Three minipages side by side would be better suited:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{calc}


\newlength\framewidth
\setlength{\framewidth}{\textwidth-4\tabcolsep-2\fboxsep}

\begin{document}
\centering

% Horizontal rule for comparison
\hrule\par\bigskip

\fbox{%
\begin{minipage}[t]{.333\framewidth}
   \centering
   \vspace*{0pt}
   %\includegraphics[width=0.2\textwidth]{Images/Logo}%
   \rule{.8\textwidth}{1cm}% graphic dummy
   \\[.1cm]\sffamily\tiny
   subtext\linebreak
   more text
\end{minipage}%
\hspace{2\tabcolsep}%
\begin{minipage}[t]{.333\framewidth}
   \centering\large\textsc{Project name}\\
   \bfseries Current document, more text, and even more text,
   still more text
\end{minipage}%
\hspace{2\tabcolsep}%
\begin{minipage}[t]{.333\framewidth}
   a \\ b \\ c
\end{minipage}%
}
\end{document}
Related Question