2

I am trying to recreate this table using LaTeX.

enter image description here

I want to additionally align the decimals. I have tried using this code to do so.

\begin{frame}
\frametitle{Table}
\begin{table}
\begin{tabular}{l *{4}{d{3.3}} }
\toprule
Variable & Weighted Test Statistic  & Unweighted p-value & Weighted Test Statistic  & Unweighted p-value\\
\midrule
Attendance Rate&0.55&0.0875&2.15&$<$0.0001\\
Test Average&4.14&0.0320&4.68&0.0080\\
Final Exam&4.12&0.0022&1.99&0.1590\\
\makecell{Data Analysis \\ Assignment Average}&20.98&$<$0.0001&17.42&$<$0.0001\\
Quiz Average&3.88&0.0035&2.33&0.0399\\
\bottomrule
\end{tabular}
\caption{Kruskal-Wallis Tests by Semester}
\end{table}

\end{frame}

This code created the following table. There are several things I would like to fix. Namely

  • Adding fall and spring panels like in the original table
  • Aligning the values associated with the "Data Analysis Assignment Average" at the top of that row
  • Fixing the < signs
  • Fixing the headings so that they can be within the bounds of a PowerPoint slide. I tried using the makecell{.} function but it didn't work the same as with the \midrule components.

enter image description here

Note: I wasn't sure what to title this question so feel free to change it.

Edit:

Using Zarko's code, I get the following.

enter image description here

1

with tabularx, siunitx and makecell packages:

enter image description here

\documentclass{beamer}
\usepackage{booktabs, makecell, multirow, tabularx}
\renewcommand\theadfont{\footnotesize}
\renewcommand\theadgape{}
\usepackage{siunitx}

\begin{document}

\begin{frame}
    \begin{table}
\caption{Kruskal-Wallis Tests by Semester}
\renewcommand{\arraystretch}{1.2}
\setlength\tabcolsep{2pt}
\small
\begin{tabularx}{\textwidth}{@{}
                            >{\raggedright\linespread{0.84}\selectfont}X
                            *{2}{S[table-format=2.2]
                                  S[table-format=1.4,
                                    table-comparator=true]}
                            @{}}
    \toprule
\multirow[b]{3}{=}{Variable}
    &   \multicolumn{2}{c}{Fall} &  \multicolumn{2}{c}{Spring}  \\
    \cmidrule(r){2-3} \cmidrule(l){4-5}
    &   {\thead{Weighted\\ Test Statistic}}
        &   {\thead{Unweighted\\ p-value}}
            &   {\thead{Weighted\\ Test Statistic}}
                &   {\thead{Unweighted\\ p-value}}           \\
    \midrule
Attendance Rate                     &  0.55 &  0.0875 &  2.15 & <0.0001\\
Test Average                        &  4.14 &  0.0320 &  4.68 &  0.0080\\
Final Exam                          &  4.12 &  0.0022 &  1.99 &  0.1590\\
Data Analysis Assignment Average    & 20.98 & <0.0001 & 17.42 & <0.0001\\
Quiz Average                        &  3.88 &  0.0035 &  2.33 &  0.0399\\
    \bottomrule
\end{tabularx}
    \end{table}
\end{frame}
\end{document}
  • I used your code and "Variable" looks weird. I added a picture to my original post. Any idea what happened there? – Remy Apr 23 at 16:46
  • @Remy, if you not obtain the same result as I show, than you or change something in my code or you have installed older version of used packages. I test my code with recent versions of all used packages. – Zarko Apr 23 at 17:40
  • I'm using Overleaf. When I just use multirow{Variable}, I get what you have except variable is adjacent to "Fall" and "Spring." Does it matter what other packages I'm using to go along with those? – Remy Apr 23 at 17:48
  • @Remy, oh Overleaf` .... it hasn't installed decent ˙\multirow` package. You need to change line \multirow[b]{3}{=}{Variable} to older syntax \multirow{5}{*}{Variable}. – Zarko Apr 23 at 18:07
  • Thanks so much. I think your code is what I'll go with. – Remy Apr 23 at 18:54
4

Here my suggestions.

I have not met the point two. It seems more elegant to me aligned at the bottom, or as showed here, aligned at the middle. But if you disagree, just change the m column by a p. Anyway, with p,m or b the main point is that without awful the horizontal rows, this table needs some extra vertical space between rows to mark clearly where start/end the text of the multiline cell. Otherwise, the "Variable" column is a mess.

mwe

\documentclass{beamer}
\usepackage{booktabs,tabularx,dcolumn}
\newcolumntype{d}{D{.}{\cdot}{-1}}
\begin{document}
\begin{frame}
\begin{table}
\caption{Kruskal-Wallis Tests by Semester}
\footnotesize\tabcolsep0em
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\textwidth}{>{\raggedright}m{10em}dddd}\toprule & 
\multicolumn{2}{c}{Fall} &
\multicolumn{2}{c}{Spring} \\
\cmidrule(r){2-3}
\cmidrule(l){4-5}
\multicolumn{1}{X}{\leavevmode\newline Variable} & 
\multicolumn{1}{X}{\centering Weighted Test Statistic}  & 
\multicolumn{1}{X}{\centering Unweighted p-value} & 
\multicolumn{1}{X}{\centering Weighted Test Statistic}  & 
\multicolumn{1}{X}{\centering Unweighted p-value} \tabularnewline
\cmidrule(r){1-1}
\cmidrule(rl){2-2}
\cmidrule(rl){3-3}
\cmidrule(rl){4-4}
\cmidrule(rl){5-5}
Attendance Rate                     &  0.55 &  0.0875 &  2.15 & <0.0001\\
Test Average                        &  4.14 &  0.0320 &  4.68 &  0.0080\\
Final Exam                          &  4.12 &  0.0022 &  1.99 &  0.1590\\
Data Analysis Assignment Average    & 20.98 & <0.0001 & 17.42 & <0.0001\\
Quiz Average                        &  3.88 &  0.0035 &  2.33 &  0.0399\\
\bottomrule
\end{tabularx}
\end{table}
\end{frame}
\end{document}
  • How can I make the decimals not be in the center but down? It looks like a multiplication sign. – Remy Apr 23 at 3:56
  • 1
    @Reny In old British typography, the interpunct is the formal decimal point. As using full stops is easier in computers, this style is disappearing, however is still used in some good academic journals. Change this is as simple as replace on line 3 the \cdot by . or , or whatever that you want as decimal separator. – Fran Apr 23 at 23:36
3

This might work for your purposes. I used the article class for this but I think you can change it to beamer and use the \frametitle{} option in lieu of the caption and you can adjust the font size as needed using \footnotesize or anything else that can fit the dimensions of the slide. In addition, you can add the \begin{frame} and \end{frame} to the beginning and end of the table chunk of code.

\documentclass{article}

\usepackage{fullpage}
\usepackage{tabulary}
\usepackage{booktabs}
\begin{document}

\begin{table}
    \caption{Kruskal-Wallis Tests by Semester}
    \begin{tabulary}{\linewidth}{LCCCC}
        \\
        \hline
        & \multicolumn{2}{c}{Falll}&\multicolumn{2}{c}{Spring} \\
        \hline
        Variable & Weighted Test Statistic  & Unweighted p-value & Weighted Test Statistic  & Unweighted p-value\\
        \hline
        Attendance Rate&0.55&0.0875&2.15&$<$0.0001\\
        Test Average&4.14&0.0320&4.68&0.0080\\
        Final Exam&4.12&0.0022&1.99&0.1590\\
        Data Analysis&&&&\\ 
        Assignment Average&20.98&$<$0.0001&17.42&$<$0.0001\\
       Quiz Average&3.88&0.0035&2.33&0.0399\\
       \hline 
    \end{tabulary}
\end{table}

\end{document}

Edit:

For beamer class,

\begin{frame}
\footnotesize %Or whatever other size you need
\frametitle{MY TABLE} %Frame Title
\begin{table}
    \caption{Kruskal-Wallis Tests by Semester}
    \begin{tabulary}{\linewidth}{LCCCC}
        \\
        \hline
        & \multicolumn{2}{c}{Falll}&\multicolumn{2}{c}{Spring} \\
        \hline
        Variable & Weighted Test Statistic  & Unweighted p-value & Weighted Test Statistic  & Unweighted p-value\\
        \hline
        Attendance Rate&0.55&0.0875&2.15&$<$0.0001\\
        Test Average&4.14&0.0320&4.68&0.0080\\
        Final Exam&4.12&0.0022&1.99&0.1590\\
        Data Analysis&&&&\\ 
        Assignment Average&20.98&$<$0.0001&17.42&$<$0.0001\\
       Quiz Average&3.88&0.0035&2.33&0.0399\\
       \hline 
    \end{tabulary}
\end{table}
\end{frame}

I hope this helps!

  • Thank you for your response. I tried adding your packages but it made every slide look weird. I have edited my post with a picture. Would it help if I showed each package I'm currently using? – Remy Apr 23 at 0:26
  • I think your problem might come from the fullpage package because I never use that for beamer. If that is not it, please let me know what packages you are using. – Jennifer Apr 23 at 0:29
  • That worked! Could you please edit your post to show where the font size adjustment goes? – Remy Apr 23 at 0:32
  • I added it and hope it works for your purposes! – Jennifer Apr 23 at 0:37

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.