2

I have a table where I need to display lots of text in the first column and the first 3 rows. I therefore require to wrap the text so I have been using centered |p| cells. Since i have so much text i need to have a fixed width for the cells. some cells need to span multiple columns, so i have tried to set them to double the width of the columns themselves, but thee ends up being a lot of whitespace that isn't filled. How can i make this work?

My problem is the following white areas in the "analysis" cell and the 3 cells below:

Attempt at table :)

This is my current code attempt:

\documentclass{article}
\usepackage{caption}
\usepackage[dvipsnames, table]{xcolor}
\usepackage{colortbl}
\usepackage{multirow} %for cells over multiple rows
\usepackage{diagbox} %for tables with diagonal lines in cells
\usepackage{array} %Allows for more fine-tuning of table padding
\usepackage{float}

%Colour used for tables
\definecolor{HEAD}{gray}{0.80}
\definecolor{COL}{gray}{0.95}
\colorlet{GRE}{green!30}

%Custom proposition command, since these sentences are used a lot.
%\prop{} just returns a text string based on the number given
\newcommand{\prop}[1]{%
  \ifnum#1=11
    People in SOs have a motivation to learn causing them to perform innovations%
  \else\ifnum#1=13
    SOs experience innovation benefits from setting aside time for reflection in groups%
  \else\ifnum#1=12
    SOs utilise available external knowledge to assist innovation projects%
  \else\ifnum#1=21
    To increase innovation, SOs should show support for innovation by letting members try new things%
  \else\ifnum#1=22
    Missions and ambitious visions positively influence innovation in SOs%
  \else\ifnum#1=32
    SOs’ high turnover leads to increased innovation%
  \else\ifnum#1=31
    An organic organisational structure positively influences innovation in SOs%
  \else
    \textbf{Invalid proposition number!}%
  \fi\fi\fi\fi\fi\fi\fi
}

\begin{document}


\begin{table}[H]
    \centering
    \tiny

    \newcolumntype{A}[0]{>{\centering\arraybackslash}p{0.08\textwidth}}
    \newcolumntype{B}[0]{>{\centering\arraybackslash}p{0.16\textwidth}} %spans 2 columns
    \newcolumntype{D}[0]{>{\centering\arraybackslash}p{0.24\textwidth}} %spans 3 columns
    \newcolumntype{E}[0]{>{\centering\arraybackslash}p{0.56\textwidth}} %spans 7 columns
    
    \begin{tabular}{
        |>{\columncolor{COL}}p{0.16\textwidth}
        |A
        |A
        |A
        |A
        |A
        |A
        |A|}
    \hline


    %first row
    \rowcolor{HEAD}
    & 
    \multicolumn{7}{E|}{\textbf{Analysis}} \\
    \cline{2-8}

    
    %second row
    \rowcolor{HEAD}
    & 
    \multicolumn{3}{D|}{\textbf{Learning Activities}} & 
    \multicolumn{2}{B|}{\textbf{Guiding Organisational Principles}} & 
    \multicolumn{2}{B|}{\textbf{Organisational Durability}} \\ 
    \cline{2-8}


    
    %third row
    \rowcolor{HEAD}
    Empirical Findings & Prop 1.1: \prop{11} & Prop 1.2: \prop{12} & 3 & 4 & 5 & 6 & 7 \\ \hline 
    %\prop{} command just pasts in some text which i use a lot

    %---------
    %Data rows
    4.2.1: SOs Focus on Offering Students Learning and Development Opportunities &  &  &  & \cellcolor{GRE} &  & \cellcolor{GRE} &  \\ \hline
    4.2.2: Team and member independence leads to ownership & \cellcolor{GRE} &  &  &  & \cellcolor{GRE} &  &  \\ \hline
    4.2.3: Showing Openness to Failure, Trial and Error &  &  &  &  &  &  &  \\ \hline
    ++++ &  &  & \cellcolor{GRE} & \cellcolor{GRE} & \cellcolor{GRE} &  &  \\ \hline
    \end{tabular}
    \caption{Use of Empirical Findings}
    \label{tab:analysematrise}
\end{table}

\end{document}

How can I make this table without the white areas in the \multicolumn cells?

I'm sort of a beginner to latex, so all help is appreciated! Also if someone has any ideas for how I can better format my table, they are welcome!

(also bonus-rant: in the start, I tried to have "Empirical Findings" and "Analysis" in the same cell (Cell 1,1), with a diagonal line separating them, but \diagbox[]{}{} seems to be very janky with multi-row cells. I could not figure it out)

Thanks for all the help in advance!

9
  • 1
    Have a look at the tabularray package. It makes it easy to merge and colour cells. Commented Jun 10 at 12:05
  • Welcome to TeX.SE. This probably isn't related to the problem, but could you complete your example with \documentclass and the necessary packages? Then we don't have to guess what you're using.
    – Teepeemm
    Commented Jun 10 at 12:06
  • Ah sorry, I have tried to include the necessary packages now! Thanks for the tip Commented Jun 10 at 12:23
  • 1
    @JustAnotherPerson Overleaf, doesn't hold the process if any error occurs, you should check the .log file for the details
    – MadyYuvi
    Commented Jun 10 at 13:06
  • 1
    If overleaf puts a big red circle with an error count at the top of the view, it has not "compiled for you", it has failed to compile and any shown pdf is, at best, a debugging aid not usable output. Commented Jun 10 at 14:29

4 Answers 4

4

As proposed by @samcarter_is_at_topanswers.xyz, a try with tabularray:

\documentclass{article}
\usepackage{caption}
\usepackage[dvipsnames, table]{xcolor}
\usepackage{tabularray}

\usepackage{lipsum}

%Colour used for tables
\definecolor{HEAD}{gray}{0.80}
\definecolor{COL}{gray}{0.95}
\colorlet{GRE}{green!30}

%Custom proposition command, since these sentences are used a lot.
%\prop{} just returns a text string based on the number given
\NewExpandableDocumentCommand{\prop}{m}{%
  \ifnum#1=11
  People in SOs have a motivation to learn causing them to perform innovations%
  \else\ifnum#1=13
  SOs experience innovation benefits from setting aside time for reflection in groups%
  \else\ifnum#1=12
  SOs utilise available external knowledge to assist innovation projects%
  \else\ifnum#1=21
  To increase innovation, SOs should show support for innovation by letting members try new things%
  \else\ifnum#1=22
  Missions and ambitious visions positively influence innovation in SOs%
  \else\ifnum#1=32
  SOs’ high turnover leads to increased innovation%
  \else\ifnum#1=31
  An organic organisational structure positively influences innovation in SOs%
  \else
  \textbf{Invalid proposition number!}%
  \fi\fi\fi\fi\fi\fi\fi
}

\begin{document}
  \lipsum[1]
  
  \begin{table}[!ht]
    \centering
    \tiny
    \begin{tblr}[expand=\expanded]{colspec={*{8}{X[c,m]}}
        ,hlines, vlines,
        ,hspan=minimal
        ,row{1,2,3}={HEAD}
        ,column{1}={HEAD}
      }
      %first row
      \SetCell[r=3,c=1]{} \textbf{Empirical Findings} & \SetCell[r=1,c=7]{} \textbf{Analysis} \\
%      %second row
      & \SetCell[r=1,c=3]{} \textbf{Learning Activities} &&& \SetCell[r=1, c=2]{} \textbf{Guiding Organisational Principles} && \SetCell[r=1,c=2]{} \textbf{Organisational Durability} \\
      %third row
      & Prop 1.1: \expanded{\prop{11}} & Prop 1.2: \expanded{\prop{12}} & \expanded{\prop{11}} & 4 & 5 & 6 & 7 \\
      %---------
      %Data rows
      4.2.1: SOs Focus on Offering Students Learning and Development Opportunities &  &  &  & \SetCell{GRE} &  & \SetCell{GRE} &  \\
      4.2.2: Team and member independence leads to ownership & \SetCell{GRE} &  &  &  & \SetCell{GRE} &  &  \\
      4.2.3: Showing Openness to Failure, Trial and Error &  &  &  &  &  &  &  \\
      ++++ &  &  & \SetCell{GRE} & \SetCell{GRE} & \SetCell{GRE} &  &  \\
    \end{tblr}
    \caption{Use of Empirical Findings}
    \label{tab:analysematrise}
  \end{table}
  
  \lipsum[2]
  
\end{document}

which produces enter image description here

In order to use your \prop command you have to define it through \NewExpandableDocumentCommand.

I also use 8 (centered) X columns, instead of your AB… ones.

For the diagbox part, have a look at https://tex.stackexchange.com/a/669807/151808. But as it is now, your table is cramped for space And IMHO, this is not a good presentation.

1
  • This worked great, thank you so much! It really helped during the final days of my thesis. Commented Jun 10 at 17:30
3

You are specifying incorrect column widths for spanning entries.

\newcolumntype{B}[0]
   {>{\centering\arraybackslash}p{0.16\textwidth}} %spans 2 columns

There is \tabcolsep (normally 6pt) padding on either side of each column, so cell that spans two columns is spanning two lots of .16\textwidth and both of the two inner column seprations so should be

\newcolumntype{B}
  {>{\centering\arraybackslash}p{\dimexpr 0.16\textwidth+2\tabcolsep}} %spans 2 columns

where in general spanning n columns means you have to add 2 n \tabcolsep to the width.

2

Basically, the same idea as in the answer of NBur, but moving all cell decorations to the table header, which makes the table contents nicer and more easily manageable:

\documentclass{article}
\usepackage[dvipsnames, table]{xcolor}

%Colour used for tables
\definecolor{HEAD}{gray}{0.80}
\definecolor{COL}{gray}{0.95}
\colorlet{GRE}{green!30}

%Custom proposition command, since these sentences are used a lot.
%\prop{} just returns a text string based on the number given
\newcommand{\prop}[1]{%
  \ifnum#1=11
    People in SOs have a motivation to learn causing them to perform innovations%
  \else\ifnum#1=13
    SOs experience innovation benefits from setting aside time for reflection in groups%
  \else\ifnum#1=12
    SOs utilise available external knowledge to assist innovation projects%
  \else\ifnum#1=21
    To increase innovation, SOs should show support for innovation by letting members try new things%
  \else\ifnum#1=22
    Missions and ambitious visions positively influence innovation in SOs%
  \else\ifnum#1=32
    SOs’ high turnover leads to increased innovation%
  \else\ifnum#1=31
    An organic organisational structure positively influences innovation in SOs%
  \else
    \textbf{Invalid proposition number!}%
  \fi\fi\fi\fi\fi\fi\fi
}

\usepackage{tabularray}

\begin{document}

\begin{table}[h]
    \centering
    \tiny
    \begin{tblr}{
        width={\linewidth},
        colspec={X[2,l]X[c]X[c]X[c]X[c]X[c]X[c]X[c]},
        column{1}={COL},
        row{1-3}={HEAD},
        cell{1}{1}={r=3}{},
        cell{1}{2}={c=7}{font=\bfseries},
        cell{2}{2}={c=3}{font=\bfseries},
        cell{2}{5,7}={c=2}{font=\bfseries},
        cell{4}{5,7}={GRE},
        cell{5}{2,6}={GRE},
        cell{7}{4-6}={GRE},
        hspan=minimal,
        hlines,
        vlines,
    }
    %first row
    Empirical Findings & Analysis & & & & & & \\
    %second row
    & Learning Activities & & & Guiding Organisational Principles & & Organisational Durability \\ 
    %third row
    & Prop 1.1: \prop{11} & Prop 1.2: \prop{12} & 3 & 4 & 5 & 6 & 7 \\
    %Data rows
    4.2.1: SOs Focus on Offering Students Learning and Development Opportunities & & & & & & & \\
    4.2.2: Team and member independence leads to ownership & & & & & & & \\
    4.2.3: Showing Openness to Failure, Trial and Error & & & & & & & \\
    ++++ & & & & & & & \\
    \end{tblr}
    \caption{Use of Empirical Findings}
    \label{tab:analysematrise}
\end{table}

\end{document}

The result: enter image description here

0

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{caption}
\usepackage[dvipsnames]{xcolor}
\usepackage{nicematrix}

\usepackage{lipsum}

%Colour used for tables
\definecolor{HEAD}{gray}{0.80}
\definecolor{COL}{gray}{0.95}
\colorlet{GRE}{green!30}

%Custom proposition command, since these sentences are used a lot.
%\prop{} just returns a text string based on the number given
\newcommand{\prop}[1]{%
  \ifnum#1=11
  People in SOs have a motivation to learn causing them to perform innovations%
  \else\ifnum#1=13
  SOs experience innovation benefits from setting aside time for reflection in groups%
  \else\ifnum#1=12
  SOs utilise available external knowledge to assist innovation projects%
  \else\ifnum#1=21
  To increase innovation, SOs should show support for innovation by letting members try new things%
  \else\ifnum#1=22
  Missions and ambitious visions positively influence innovation in SOs%
  \else\ifnum#1=32
  SOs’ high turnover leads to increased innovation%
  \else\ifnum#1=31
  An organic organisational structure positively influences innovation in SOs%
  \else
  \textbf{Invalid proposition number!}%
  \fi\fi\fi\fi\fi\fi\fi
}

\begin{document}
\lipsum[1]

\begin{table}[!ht]
  \centering
  \tiny
  \begin{NiceTabular}{*{8}{X[c,m]}}[hvlines,cell-space-limits=3pt,color-inside]
  \CodeBefore
    \rowcolor{HEAD}{1,2}
    \columncolor{HEAD}{1}
  \Body
  \RowStyle{\bfseries}
    \Block{2-1}{\diagbox{Empirical\\ Findings}{Analysis}} 
    & \Block{1-3}{Learning Activities} &&& \Block{1-2}{Guiding\\ Organisational\\ Principles} && \Block{1-2}{Organisational\\ Durability} \\
    & Prop 1.1: \prop{11} & Prop 1.2: \prop{12} & \prop{11} & 4 & 5 & 6 & 7 \\
    4.2.1: SOs Focus on Offering Students Learning and Development Opportunities &  &  &  & \cellcolor{GRE} &  & \cellcolor{GRE} &  \\
    4.2.2: Team and member independence leads to ownership & \cellcolor{GRE} &  &  &  & \cellcolor{GRE} &  &  \\
    4.2.3: Showing Openness to Failure, Trial and Error &  &  &  &  &  &  &  \\
    ++++ &  &  & \cellcolor{GRE} & \cellcolor{GRE} & \cellcolor{GRE} &  &  \\
  \end{NiceTabular}
  \caption{Use of Empirical Findings}
  \label{tab:analysematrise}
\end{table}

\lipsum[2]
  
\end{document}

You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

Output of the above code

You must log in to answer this question.

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