3

I am having trouble with this table that I originally made in Excelenter image description here

There are two things that I am having trouble with:

  1. Setting up the borders just for the bottom right
  2. Making sure that "Trust in political parties" centered in between columns 3 and 4

So far, this is the code that I am working with:

\begin{table}[H]
\begin{center}
\caption{Theory}
\begin{tabular}{ cccc } 
 & & Trust in political parties \\
 & & Low & High \\
 \multirow{2}{4em}{Emotion} & Low & A & Preemtive B \\
 & High & C & D \\
\end{tabular}
\end{center}
\end{table}

Thank you

1
  • You should try something with tabularray.
    – projetmbc
    Apr 6 at 15:06

4 Answers 4

5

One way is to use the nicematrix package.

enter image description here

\documentclass{article}

\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{lw{l}{1cm}w{c}{2cm}w{c}{2cm}}
 & & \Block{1-2}{\textbf{Trust in political parties}} & \\
 & & Low & High\\
\Block{2-1}{\textbf{Policy priority}} & Low & \Block[draw]{}A & \Block[draw]{}B\\
 & High & \Block[draw]{}C & \Block[draw]{}D
\end{NiceTabular}

\end{document}
5

I just discovered the amazing tabularray package, which provides many customisations for tables through a modern key-value interface and replicates the functionalities of classic table packages.

It's my first try, probably not optimal, but it works.

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{table}
  \begin{center}
    \caption{Theory}
    \begin{tblr}
      {%
        colspec={ lllll }             % 5 left aligned columns
        ,cell{3-Z}{3-Z}={c}           % center cells from row 3 and column 3 until the end
        ,row{1} = {font=\bfseries}    % format row 1
        ,column{1} = {font=\bfseries} % format column 1
        ,hline{3-Z}={3-Z}{}           % draw hlines starting from the 3rd, for rows 3 until the end
        ,vline{3-Z}={3-Z}{}           % draw vlines starting from the 3rd, for columns 3 until the end
      }
      &
      &
      \SetCell[c=2]{c} Trust in political parties % centered across 2 columns
      \\
      &
      & Low & High                 \\
      \SetCell[r=2]{c} Emotion                    % centered across 2 rows
      & Low  & A   & Preemtive B          \\
      & High & C   & D
    \end{tblr}
  \end{center}
\end{table}

\end{document}

solution with tabularray

3

Here's another example

\documentclass{article}
\usepackage{multirow}   % Merge rows
\usepackage{array}      % More convenient column spec.

\newcolumntype{L}{@{}p{2.5cm}}
\newcolumntype{C}{w{c}{2.5cm}}


\begin{document}
\begin{table}[tbh]
    \renewcommand*\arraystretch{1.2}
    \centering
    \caption{Theory}
    \begin{tabular}{*2{l} | *2{C|}} 
        & \multicolumn{1}{c}{}
        & \multicolumn{2}{c}{\bfseries Trust in political parties} \\
        & \multicolumn{1}{c}{}
        & \multicolumn{1}{L}{Low} & \multicolumn{1}{L}{High} \\
        \cline{3-4}
        \multirow{2}*{\bfseries Emotion}
        & Low  & A & B \\
        \cline{3-4}
        & High & C & D \\
        \cline{3-4}
    \end{tabular}
\end{table}
\end{document}

enter image description here

2

You only need some \multicolumns , that no need any package.

Besides, the table will look like off-center with a centered caption, because the jailed data are only on the right, so I will put the whole scheme in some box:

mwe

   \documentclass{article}
    \usepackage{multirow,array}
    \begin{document}
    \begin{table}\caption{Theory}
    \extrarowheight2.5pt
    \centering\fboxsep1em\fbox{%
    \begin{tabular}{@{}c|l|p{4em}p{6em}} 
    \multicolumn{4}{c}{}\\[-20pt]
    \multicolumn{2}{c}{} & \multicolumn{2}{c}{Trust in political parties}\\\cline{3-4}
    \multicolumn{2}{c}{}            & \centering Low  & \multicolumn{1}{c}{High} \\\cline{3-4}
    \multirow{2}{*}{Emotion} & Low  & \centering A    & \multicolumn{1}{|c|}{Preemtive B} \\\cline{3-4}
                             & High & \centering C    & \multicolumn{1}{|c|}{D} \\\cline{3-4}                        
    \end{tabular}}
    \end{table}
    \end{document}

You must log in to answer this question.

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