2

I have this table (written in overleaf ):

\chapter{Introduction}
\label{cha:chapter1}
\section{Introduction} 

\begin{table}[htp!]
\centering
\small
\resizebox{\textwidth}{!}{
\begin{tabular}{ |p{2.3cm}|p{4.2cm}|p{1.5cm}|p{1.5cm}|p{5.5cm} |}
\hline
\rowcolor{gray!30}
\textbf{Dataset} & \textbf{Description} & \textbf{taxonomy} & \textbf{Platform} & \textbf{Number of instances} \\ \hline

MBTI  & It is collected by M. J from the Personality Cafe forum. & MBTI & Personality Cafe & 50 posts by 8,675 users \\ \hline

PAN-2015 Author Profiling & It is introduced as a part of an Author-Profiling shared task to detect authors' demographics and personality traits from tweets. It is presented in four languages: English, Dutch, Italian and Spanish. & Big Five & X, formerly Twitter & 
\vspace{0pt}\begin{tabular}{@{}p{1.4cm}|p{1.7cm}|p{1.7cm}@{}}

\hline
Language & Training samples & Test samples \\
\hline
English & 152 & 142 \\
\hline
Dutch & 34 & 32 \\
\hline
Italian & 39 & 36 \\
\hline
Spanish & 50 & 45 \\
\hline
\end{tabular}   \\ \hline

\end{tabular}
}
\end{table}

Giving:

table

However, I need to span the nested table in row 2 col 5 to fill the entire cell space as this image table2

How can this be solved ?

2
  • 2
    Please tell us which document class you employ, what the main font size is, and how wide the text block is.
    – Mico
    Commented Aug 3 at 8:29
  • 3
    This is a very instructive example of what can be done with a word processor, but is anathema for real typography.
    – egreg
    Commented Aug 3 at 9:10

4 Answers 4

4

My main suggestion would be to declutter the appearance of the "inner" tabular environment by getting rid of all interior vertical lines and most horizontal lines. Centering rather than left-aligning the contents of the 2nd and 3rd column of the inner table may help too.

My remaining suggestion would be to switch the interior tabular environment to a tabularx environment and to encase it in a \multicolumn{1} wrapper in order to let the tabularx environment occupy the full available width.

Speaking for myself (who else??), I find this table's visual layout to be nearly impenetrable. The layout, and therefore the table's overall readability, is in no meaningful way improved by making the inner table's horizontal lines extend sufficiently to make them touch the adjacent vertical lines. The fact that the effective font size in the table is much smaller than that of the surrounding text (courtesy of the use of the \resizebox sledgehammer...) doesn't help either.

enter image description here

\documentclass{report} % or some other suitable document class
\usepackage[demo]{graphicx} % for '\resizebox' sledgehammer
\usepackage[table]{xcolor}
\usepackage{tabularx} % for 'tabularx' env. and 'X' column type
\usepackage{ragged2e} % for '\RaggedRight' and '\Centering' macros
\usepackage{calc}     % for '\widthof' macro
\newcolumntype{P}[1]{>{\RaggedRight}m{#1}} % disable full justification
\newcolumntype{L}{>{\RaggedRight}X}
\newcolumntype{C}{>{\Centering}X}

\begin{document}

\begin{table}[htp!]
\setlength\tabcolsep{3pt} % default: 6pt
\setlength\extrarowheight{2pt}
\footnotesize % <-- was '\small'
\resizebox{\textwidth}{!}{%
\begin{tabular}{ | P{2.1cm}|
                   P{4.2cm}|
                   P{\widthof{\textbf{Personality}}}|
                   P{1.6cm}|
                   P{5.5cm} |}
\hline
\rowcolor{gray!15}
\textbf{Dataset} & \textbf{Description} & \textbf{Personality taxonomy} & \textbf{Platform} & \textbf{Number of instances} \\ \hline

MBTI  & It is collected by M. J from the Personality Cafe forum. & MBTI & Personality Cafe & 50 posts by 8,675 users \\ \hline

PAN-2015 Author Profiling & It is introduced as a part of an Author-Profiling shared task to detect authors' demographics and personality traits from tweets. It is presented in four languages: English, Dutch, Italian and Spanish. & Big Five & X, formerly Twitter & 

\multicolumn{1}{@{}c@{}|}{%
\begin{tabularx}{5.5cm+2\tabcolsep}{LCC}
%\hline
Language & Training samples & Test samples \\
\hline
English & 152 & 142 \\
%\hline
Dutch & 34 & 32 \\
%\hline
Italian & 39 & 36 \\
%\hline
Spanish & 50 & 45 \\
%\hline
\end{tabularx}}   
\\ \hline
\end{tabular}
}
\end{table}
\end{document}
2

You might do it, but the result is really difficult to read. By trial and error the 1.2 factor gives good alignment.

\documentclass{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{tabularx}

\begin{document}

\begin{table}[htp!]
\centering
\footnotesize
\newcommand{\subheader}[1]{%
  \renewcommand{\arraystretch}{1}%
  \begin{tabular}[t]{@{}c@{}}#1\end{tabular}%
}

\begin{tabularx}{\textwidth}{
  |
  >{\hsize=0.6\hsize\raggedright}X |
  >{\hsize=2\hsize\raggedright}X   |
  >{\hsize=0.7\hsize\raggedright}X |
  >{\hsize=0.7\hsize\raggedright}X |
  l |
}
\hline
\rowcolor{gray!30}
\textbf{Dataset} &
  \textbf{Description} &
  \textbf{taxonomy} &
  \textbf{Platform} &
  \textbf{Number of instances} \\
\hline

MBTI &
  It is collected by M. J from the Personality Cafe forum. &
  MBTI &
  Personality Cafe &
  50 posts by 8,675 users \\
\hline

PAN-2015 Author Profiling &
  It is introduced as a part of an Author-Profiling shared task 
    to detect authors' demographics and personality traits from tweets.
    It is presented in four languages: English, Dutch, Italian and Spanish. &
 Big Five &
 X, formerly Twitter &
\renewcommand{\arraystretch}{1.2}%
\hspace*{-\tabcolsep}%
\begin{tabular}[t]{l|c|c}
Language & \subheader{Training \\ samples} & \subheader{Test \\ samples} \\
\hline
English & 152 & 142 \\
\hline
Dutch & 34 & 32 \\
\hline
Italian & 39 & 36 \\
\hline
Spanish & 50 & 45 \\
\end{tabular}%
\hspace*{-\tabcolsep} \\
\hline

\end{tabularx}

\end{table}

\end{document}

unscrutable output

A different layout:

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{table}[htp!]
\newcommand{\subheader}[1]{%
  \begin{tabular}[t]{@{}c@{}}#1\end{tabular}%
}

Data is presented by dataset, taxonomy, platform and description

\begin{itemize}
\item MBTI (MBTI; Personality Cafe) \\
  It is collected by M. J from the Personality Cafe forum.
  The user base is 50 posts by 8,675 users

\item PAN-2015 Author Profiling (Big Five; X, formerly Twitter) \\
  It is introduced as a part of an Author-Profiling shared task 
    to detect authors' demographics and personality traits from tweets.
    It is presented in four languages: English, Dutch, Italian and Spanish.
    \begin{center}
    \begin{tabular}{@{}lcc@{}}
    \toprule
    Language & \subheader{Training \\ samples} & \subheader{Test \\ samples} \\
    \midrule
    English & 152 & 142 \\
    Dutch & 34 & 32 \\
    Italian & 39 & 36 \\
    Spanish & 50 & 45 \\
    \bottomrule
    \end{tabular}
    \end{center}
\end{itemize}

\caption{Some meaningful caption to the table}

\end{table}

\end{document}

Different layout

1

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage[left=2cm,right=2cm]{geometry}
\usepackage{nicematrix}
\usepackage{makecell}

\begin{document}

\begin{table}[htp!]
\setlength{\tabcolsep}{3pt} % default: 6pt
\setlength{\extrarowheight}{2pt}
\footnotesize
\begin{NiceTabular}{p{14mm}p{42mm}p{19mm}p{16mm}p{55mm}}[color-inside,hvlines,&-in-blocks]
\RowStyle[rowcolor=gray!15]{\bfseries}
Dataset & Description & Personality taxonomy & Platform & Number of instances \\ 
MBTI  & It is collected by M. J from the Personality Cafe forum. & MBTI & Personality Cafe & 50 posts by 8,675 users \\ 
\Block[t,l]{5-1}{PAN-2015 Author Profiling} & 
\Block[t,l]{5-1}{It is introduced as a part of an Author-Profiling shared task 
            to detect authors' demographics and personality traits from tweets. 
            It is presented in four languages: English, Dutch, Italian and Spanish.} &  
\Block[t,l]{5-1}{Big Five} & 
\Block[t,l]{5-1}{X, formerly Twitter} & 
\Block{}{Language & \makecell[t]{Training\\ samples} & Test samples} \\[\normalbaselineskip]
&&&&\Block{}{English & 152 & 142} \\
&&&&\Block{}{Dutch & 34 & 32} \\
&&&&\Block{}{Italian & 39 & 36} \\
&&&&\Block{}{Spanish & 50 & 45} \\
\end{NiceTabular}
\end{table}

\end{document}

Output of the above code

0

One more option: by use of tabularray package, without nested tables and a bit wider \textwidth:

\documentclass{article}
\usepackage{geometry}       % new
\usepackage{ragged2e}       % new
\usepackage{xcolor}
\usepackage{tabularray} 
\UseTblrLibrary{siunitx}    % new

\begin{document}

\begin{table}[htp!]
\small%\footnotesize % <-- was '\small'
\begin{tblr}{hlines, vlines,
             colsep  = 3pt,
             colspec = {X[l,h] X[3,l,h, cmd=\RaggedRight] 
                          *{4}{X[l,h]}
                               X[c, si={table-format=3}]},
             cell{1,2}{3} = {c=5}{},
             cell{3}{1-4} = {r=5}{},
             row{1}  = {font=\bfseries, bg=gray!15},
             row{3}  = {guard}
             }
Dataset & Description   
            & Personality taxonomy  
                & Platform  
                    & Number of instances   
                        &   &                       \\
MBTI    & It is collected by M. J from the Personality Cafe forum. 
            & MBTI 
                & Personality Cafe 
                    & 50 posts by \num{8 675} users 
                        &   &               \\ 
PAN-2015 Author Profiling 
        & It is introduced as a part of an Author-Profiling shared task to detect authors' demographics and personality traits from tweets. It is presented in four languages: English, Dutch, Italian and Spanish. 
            & Big Five 
                & X, formerly Twitter 
                    &   Language 
                        &   Training samples 
                            &   Test samples    \\
        &   &   &   &   English 
                        & 152 
                            & 142               \\
        &   &   &   &   Dutch 
                        & 34 & 32               \\
        &   &   &   &   Italian 
                        & 39 & 36               \\
        &   &   &   &   Spanish 
                        & 50 
                            & 45                \\
    \end{tblr}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .