[Tex/LaTex] Wrapping text in a fixed width table so that table height adjusts

multirowtablestabularywrap

I looked at these questions but they didn't seem to solve my issue because using a parbox for the first column cell doesn't make the table adjust to the content in the first cell, nor does simply specifying the cm width within the multirow option.

\documentclass[12pt]{report}

\usepackage[]{multirow}
\usepackage[autostyle]{csquotes}% This is for quotes
\usepackage{tabulary}% This is for tables
\usepackage{ragged2e}
\usepackage{longtable,array,ragged2e}% This is formatting for long tables
% \newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}%This is a wrapper to make everything a certain width - http://tex.stackexchange.com/questions/12703/how-to-create-fixed-width-table-columns-with-text-raggedright-centered-raggedlef
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{graphicx}% This is for images
\usepackage{booktabs,dcolumn,caption}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}%This is for precision tables per property
% \captionsetup{labelsep=newline,singlelinecheck=false} % optional, this makes the caption numbers appear on a new line.
\newcolumntype{d}[1]{D{.}{.}{#1}} % "decimal" column type
\renewcommand{\ast}{{}^{\textstyle *}} % for raised "asterisks"
\usepackage{bookmark}% This overrides warnings like http://tex.stackexchange.com/questions/52576/difference-between-bookmark-levels-greater-than-one-what-does-this-mean
\begin{document}


\begin{table}[!ht]
\centering
\begin{tabular}{ |C{3.25cm}|C{3.25cm}|C{3.25cm}|C{3.25cm}| }
\hline
\textbf{Sentence} & \textbf{Training Examples} & \textbf{Region} & \textbf{Value} \\ \hline
\multirow{4}{3.25cm}{"Countries with higher GDP per capita at the lower end of the scale include Azerbaijan (around \$7,500) and Botswana (around \$8,900) and as we head up the scale we find South Korea (around \$27,500),the United Kingdom (\$39,600), the United States (\$48,150) and right at the top we find Qatar (\$98,000) and Luxembourg (\$ 122,147)."} & LB & Lucus Radebe & Bla \\
 & DC & Michael Duberry & Bla \\
 & DC & Dominic Matteo & Bla \\
 & RB & Didier Domi  & Bla\\ \hline
\end{tabular}
\end{table} 

\end{document}

enter image description here

Best Answer

\savebox can be really useful in many examples, although sometimes they might be a bit hacky.

This works in the way that it is saving a parbox set to the specified width into a box. We can then calculate the height of that box using \totalheightof{} from calc-package. Then we distribute this length for every row, 4 rows would equal 25% of the height of the box. We then use this length for the linelinespecifier \\[\spacing], but this would overshoot a bit. How much? Well, LaTeX has first added a line in the table, and aftwerwards inserts this length of black space, so we need to take that into account. Therefore, we change the length to \setlength{\customSpacing}{.25\sentenceHeight-\baselineskip}

Further suggestions:

  • Putiting this much text in a table is not very convinient for your reader. Consider putting that text in a a paragraph for itself, possibly in a caption, or notes below the table.

Output

enter image description here

Code

\documentclass[12pt]{report}

\usepackage[]{multirow}
\usepackage{ragged2e}
\usepackage{array}%
\usepackage{calc}

\newcolumntype{W}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}

\begin{document}

  \newsavebox{\sentence}
  \savebox{\sentence}{\parbox{3.25cm}{\RaggedRight``Countries with higher GDP per capita at the lower end of the scale include Azerbaijan (around \$7,500) and Botswana (around \$8,900) and as we head up the scale we find South Korea (around \$27,500),the United Kingdom (\$39,600), the United States (\$48,150) and right at the top we find Qatar (\$98,000) and Luxembourg (\$122,147).''}}
  \newlength{\sentenceHeight}
  \setlength{\sentenceHeight}{\totalheightof{\usebox{\sentence}}}

  \begin{table}[!ht]
    \newcommand{\headerFormat}[1]{% Define a headerformat, only used in this specific table.
  \multicolumn{1}{|m{3.25cm}|}{\centering\bfseries#1}
}
    \newlength{\customSpacing}
    \setlength{\customSpacing}{.25\sentenceHeight-\baselineskip}
    \centering
    \begin{tabular}{ *{4}{|W{3.25cm}}| }
      \hline
      \headerFormat{Sentence} & \headerFormat{Training\par Examples} & \headerFormat{Region} & \headerFormat{Value} \\
      \hline
      \multirow{4}{*}{\usebox{\sentence}} & LB & Lucus Radebe & Bla \\[\customSpacing]
      & DC & Michael Duberry & Bla \\[\customSpacing]
      & DC & Dominic Matteo & Bla \\[\customSpacing]
      & RB & Didier Domi  & Bla\\[\customSpacing]
      \hline
    \end{tabular}
  \end{table}



\end{document}