5

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

5

\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}
  • this is a great answer and makes sense, however I am getting that \spacing is already defined - perhaps because of conflict with another package I might have loaded? – Dhruv Ghulati Sep 4 '16 at 19:49
  • Yes, just rename it. – Runar Sep 4 '16 at 20:33
  • Also, I took your advice on changing the table so easier to read - I now have a multicolumn sentence column as the second column so I only have two columns overall, and the entity/value appear below the sentence in the second column. See \small \begin{longtable}{@{}|C{5cm}|C{4cm}|C{4cm}|@{}} \hline \textbf{Sentence} & \multicolumn{2}{@{}C{8cm}|}{\textbf{Training Examples}}\\ \toprule \multirow{4}{5cm}{"bla"} & \multicolumn{2}{@{}C{8cm}}{"bla"}\\\cline{2-3} & Radebe & Bla \\\cline{2-3} \end{longtable} \normalsize – Dhruv Ghulati Sep 4 '16 at 20:43
  • I tried your method, renaming \spacing to \customspacing but I get this effect: prnt.sc/cegnz1 – Dhruv Ghulati Sep 5 '16 at 16:34
  • @DhruvGhulati Have a look at the column-specifier. I changed it into using p instead of m for the C-column. You could ofcourse create a new column instead and use that. – Runar Sep 5 '16 at 16:43
5

You can solve your problem in two ways:

  • With multirow, count the number of lines required ((not rows!) and add to the 2nd column a supplementary cell with invisible rule of the required depth (found by trial and errors)
  • without multirow, make, from the 2nd row, the 2nd to 4th columns a nested tabular inserted in a\multicolumn`.

In both cases I based the definition of L,C,R columntypes on p{…} type, as I supposed the m{…}type was used to have column heads vertically centred, which I obtain with the \thead command, from makecell.

Added:: I also propose a third solution so that rows 2-5 in columns 2-4 be equally spaced.

    \documentclass[12pt]{report}
    \usepackage{xcolor} %
    \usepackage{multirow}
    \usepackage[autostyle]{csquotes}% This is for quotes
    \usepackage{tabulary}% This is for tables
    \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\arraybackslash\hspace{0pt}}m{#1}}
    \newcolumntype{C}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}
    \newcolumntype{R}[1]{>{\raggedleft\\\arraybackslash\hspace{0pt}}m{#1}}
    \usepackage{graphicx}% This is for images
    \usepackage{booktabs,dcolumn,caption, makecell}
    \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
    \renewcommand\theadfont{\normalsize\bfseries}

    \begin{document}

    \begin{table}[!htb]
    \centering
    \begin{tabular}{ |C{3.25cm}|C{3.25cm}|C{3.25cm}|C{3.25cm}| }
    \hline
    \thead{Sentence} & \thead{Training\\ Examples} & \thead{Region} & \thead{Value} \\ \hline
    \multirow{17}{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 \rule{0pt}{2.5ex}\\
     & DC & Michael Duberry & Bla \\
     & DC & Dominic Matteo & Bla \\
     & RB & Didier Domi & Bla \\%
      & \rule[-18.5\baselineskip] {0pt}{0pt} & & \\
    \hline
    \end{tabular}
    \end{table}

    \begin{table}[!hb]
    \centering%
    \begin{tabular}{ |C{3.25cm}|C{3.25cm}|C{3.25cm}|C{3.25cm}|}
    \hline
    \thead{Sentence} & \thead{Training\\ Examples} & \thead{Region} & \thead{Value}
    \\ \hline
   \rule{0pt}{2.5ex} {"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)."}
     &
     \multicolumn{3}{@{}c|}{\begin{tabular}[t] {C{3.25cm}|C{3.25cm}|C{3.25cm}}
     \rule{0pt}{2.5ex}LB & Lucus Radebe & Bla \\
      DC & Michael Duberry & Bla \\
     DC & Dominic Matteo & Bla \\
     RB & Didier Domi & Bla \\[18.2\baselineskip] & & \end{tabular}}%%
    \\
      \hline
    \end{tabular}
    \end{table}

    \clearpage

    \begin{table}[!htb]
    \centering%
    \begin{tabular}{ |C{3.25cm}|C{3.25cm}|C{3.25cm}|C{3.25cm}|}
    \hline
    \thead{Sentence} & \thead{Training\\ Examples} & \thead{Region} & \thead{Value}
    \\ \hline
  \multirow{17}{\linewidth}{"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)."}
     & \rule{0pt}{2.5ex}LB & Lucus Radebe & Bla\\ %
     & \multicolumn{3}{@{}c|}{\setlength\extrarowheight{92pt}\begin{tabular}[t] {C{3.25cm}|C{3.25cm}|C{3.25cm}}%
      DC & Michael Duberry & Bla \\%
     DC & Dominic Matteo & Bla \\%
     RB & Didier Domi & Bla %
     \end{tabular}}%
    \\
      \hline
    \end{tabular}
    \end{table}

     \end{document} 

enter image description here enter image description here enter image description here

  • this doesn't seem to do what i need as the other rows are not matching up to fit the first column in terms of vertical distribution. – Dhruv Ghulati Sep 4 '16 at 19:55
  • @Dhruv Gulati: If I've well understood what you mean, this is due to the use of \extrarowheight and \makegapedcells to give some vertical padding to cells. I've modified my code to retain the padding without the side effect. Is it like you want now? – Bernard Sep 4 '16 at 21:15
  • See @RunarTrollets answer - the issue is that the rest of the cells from columns 2-4 are not distributed evenly vertically spaced through the columns, unlike what he does. – Dhruv Ghulati Sep 5 '16 at 13:09
  • @Dhruv Gulati: I didn't even try to obtain such a result. I didn't understand it's what you want. – Bernard Sep 5 '16 at 13:20
  • @Dhruv Gulati: I added a third solution that fulfills your requirements (hope I've well understood now…) – Bernard Sep 5 '16 at 14:10
1

FWIW, such a multirow works out of the box with ConTeXt Natural Tables; no trickery required:

\startsetups table:style
\setupTABLE[each][each][frame=off,leftframe=on, rightframe=on]
\setupTABLE[row][first][style=bold, align={middle,lohi}, topframe=on, bottomframe=on]
\setupTABLE[row][last] [bottomframe=on]
\setupTABLE[each][each][align=middle, width=3.25cm]
\stopsetups

\starttext
\startTEXpage[offset=2mm]
\startTABLE[setups={table:style}]
  \NC Sentence \NC Training Examples \NC Region \NC Value \NC \NR
  \NC[nr=4, align=flushleft, bottomframe=on]
     “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).”
  \NC LB \NC Lucus Radebe    \NC Bla \NC \NR
  \NC DB \NC Michael Duberry \NC Bla \NC \NR
  \NC DB \NC Dominic Matteo  \NC Bla \NC \NR
  \NC RB \NC Didier Domi     \NC Bla \NC \NR
\stopTABLE
\stopTEXpage
\stoptext

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.