1

i've used the following table generator site to create the below table but feel like it's a bit more complicated than it's need to be, and I cannot get the color cell working. https://www.tablesgenerator.com/

What is wrong with the code? Do I have all the required packages?

I also would like to understand what is going on with the \multicolumn is this necessary?

\documentclass{beamer}
\usepackage{xcolor}

\usepackage{color}
\usepackage{booktabs}
\usepackage{latexsym}

\usepackage{environ}
\usepackage{varwidth}
%\usepackage[sorting=none]{biblatex}
\usepackage{media9}
\usetheme[progressbar=frametitle]{metropolis}
\setbeamertemplate{frame numbering}[fraction]
\useoutertheme{metropolis}
\useinnertheme{metropolis}
%\usefonttheme{metropolis}
\usepackage{graphicx}
\usepackage{mathtools}
\usecolortheme{spruce}
\setbeamercolor{background canvas}{bg=white}
\usepackage{kpfonts}
\usepackage{amsmath}
\definecolor{mygreen}{rgb}{.125,.5,.25}
\title{Investigating Consonance and Dissonance}
\subtitle{\small By: Max Budnick}
\usepackage{cases}
\usepackage{multimedia}
%\institute{Perimeter College, Dunwoody, G.A.}
\date{}

\usepackage[export]{adjustbox}
\graphicspath{ {./images/} }
\usefonttheme[onlymath]{serif}
\usepackage[Symbol]{upgreek}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{etoolbox}
\newcommand{\zerodisplayskips}{%
  \setlength{\abovedisplayskip}{0pt}%
  \setlength{\belowdisplayskip}{0pt}%
  \setlength{\abovedisplayshortskip}{0pt}%
  \setlength{\belowdisplayshortskip}{0pt}}
\appto{\normalsize}{\zerodisplayskips}
\appto{\small}{\zerodisplayskips}
\appto{\footnotesize}{\zerodisplayskips}
\usepackage[sorting=none]{biblatex}
\AtBeginBibliography{\footnotesize}
\appto\bibsetup{\scriptsize}
%\setlength\bibitemsep{\baselineskip}
\addbibresource{Presentation.bib}
\usepackage{comment}

\begin{document}

\begin{frame}[t]{Equal Temperament} 
\begin{figure}
\begin{table}[]
\scalebox{0.7}{
\begin{tabular}{llll}
\cline{1-4}
             
                     
\multicolumn{1}{|l|}{\textbf{\textit{Interval Name}}}     &     \multicolumn{1}{|l|}{\textbf{\textit{Notes}}}        & \multicolumn{1}{|l|}{\textbf{\textit{Consonant/Dissonant}}} & \multicolumn{1}{c|}{\textbf{\textit{Expressed as a Function}}} \\ \hline
\multicolumn{1}{|l|}{Perfect Unison} & \multicolumn{1}{l|}{C4 | C4} & \multicolumn{1}{l|}{Consonant}     & \multicolumn{1}{l|}{$f(x)= \sin{261.63\uppi x} +\sin{261.63\uppi x}$}    \\ \hline
\multicolumn{1}{|l|}{Minor 2nd}      & \multicolumn{1}{l|}{C4 | D$\flat$4}  & \multicolumn{1}{l|}{Dissonant}      & \multicolumn{1}{l|}{261.63}          \\ \hline
\multicolumn{1}{|l|}{Major 2nd}      & \multicolumn{1}{l|}{C4 | D4}  & \multicolumn{1}{l|}{Dissonant}      & \multicolumn{1}{l|}{277.18}          \\ \hline
\multicolumn{1}{|l|}{Minor 3rd}      & \multicolumn{1}{l|}{C4 | E$\flat$4}  & \multicolumn{1}{l|}{Consonant}      & \multicolumn{1}{l|}{293.66}          \\ \hline
\multicolumn{1}{|l|}{Major 3rd}      & \multicolumn{1}{l|}{C4 | E4}  & \multicolumn{1}{l|}{Consonant}      & \multicolumn{1}{l|}{311.13}          \\ \hline
\multicolumn{1}{|l|}{Perfect 4th}      & \multicolumn{1}{l|}{C4 | F4}  & \multicolumn{1}{l|}{Consonant}      & \multicolumn{1}{l|}{329.63}          \\ \hline
%\multicolumn{1}{|l|}{Augmented 4th}      & \multicolumn{1}{l|}{f\#}  & \multicolumn{1}{l|}{$2^{1/2}$}      & \multicolumn{1}{l|}{349.23}          \\ \hline
\multicolumn{1}{|l|}{Tritone}      & \multicolumn{1}{l|}{\cellcolor{blue}C4 | F$\sharp$4}  & \multicolumn{1}{l|}{Dissonant}      & \multicolumn{1}{l|}{369.99}          \\ \hline
\multicolumn{1}{|l|}{Perfect 5th}      & \multicolumn{1}{l|}{C4 | G4}  & \multicolumn{1}{l|}{Consonant}      & \multicolumn{1}{l|}{391.99}          \\ \hline
\multicolumn{1}{|l|}{Minor 6th}      & \multicolumn{1}{l|}{C4|A$\flat$4}  & \multicolumn{1}{l|}{$2^{2/3}$}      & \multicolumn{1}{l|}{415.30}          \\ \hline

\multicolumn{1}{|l|}{Major 6th}      & \multicolumn{1}{l|}{C4|A4}  & \multicolumn{1}{l|}{$2^{3/4}$}      & \multicolumn{1}{l|}{440}          \\ \hline
\multicolumn{1}{|l|}{Minor 7th}      & \multicolumn{1}{l|}{C4|B$\flat$4}  & \multicolumn{1}{l|}{$2^{5/6}$}      & \multicolumn{1}{l|}{466.16}          \\ \hline
\multicolumn{1}{|l|}{Major 7th}      & \multicolumn{1}{l|}{C4|B4}  & \multicolumn{1}{l|}{$2^{11/12}$}      & \multicolumn{1}{l|}{494}          \\ \hline
\multicolumn{1}{|l|}{Perfect Octave}      & \multicolumn{1}{l|}{C4|C5}  & \multicolumn{1}{l|}{$2$}      & \multicolumn{1}{l|}{523.25}          \\ \hline
                           &                        &                            &                               
\end{tabular}}
\end{table}



\end{figure}
\end{frame}

\end{document}
5
  • \cellcolor is provided by package colortbl. You could add \PassOptionsToPackage{table}{xcolor} before \documentclass{beamer} to load colortbl. Nov 27, 2021 at 3:17
  • Thank you! I included that package and it worked. Anyway for me to color a whole row?
    – Ziggy
    Nov 27, 2021 at 3:32
  • colortbl has a \rowcolor command. Nov 27, 2021 at 3:33
  • Okay. I'm also getting double row highlights on my grid. My lines that are outlining each box are doubling up only in one corner. How do I fix that?
    – Ziggy
    Nov 27, 2021 at 3:37
  • 1
    I fixed it! Thank you for your help.
    – Ziggy
    Nov 27, 2021 at 3:38

2 Answers 2

2

Beside problem with coloring one cell in table, you document example has many other issues:

  • You should be aware, that beamer load many packages as are xcolor, amsmath, graphicx, hyperref ...
  • Options for those packages you can write as options of `beamer. IN your case, you should write
\documentclass[xcolor={table}]{beamer}

instead of \documentclass{beamer} and your problem will disappear.

  • some packages you load twice. Remove all duplicates!
  • Using a table generator seems like a convenient solution at first glance, but resulted code is full of clutter
  • Scaling table, that it can be fit in frame is not good idea, Better is a bit redesign a table. Try to write long text in column headers and bot equation in two lines in select smaller font (for example \scriptsize).
  • For last column I would use S column type defined in `siunitx package.
  • Used standard beamer cm (computer modern) fonts hasn't italic boldface versions. For them you should load lmodern or newtxtext, newtxmath or ...

Beside aforementioned you may consider to use tabularray package with libraries varwidth and siunitx for your table. Using it, your MWE can be:

\documentclass[xcolor={table}]{beamer}
\usepackage{mathtools}
\usepackage{newtxtext, newtxmath}
%\usepackage{lmodern}       % <--- alternative to standard cm fonts
\usepackage{tabularray}
\UseTblrLibrary{varwidth, siunitx}

\begin{document}
\begin{frame}[t]
\frametitle{Equal Temperament} 
\begin{table}
    \centering
\caption{My table}
\label{tab:tblr}
    \scriptsize
\begin{tblr}{hlines, vlines,
             colspec={*{3}{ Q[c,m] }
                            Q[c,m, si={table-format=3.2}] },
             row{1} ={font=\itshape\bfseries\linespread{0.84}\selectfont},
             rowsep ={1pt},
             measure=vbox
                 }
{Interval\\ Name}
            & Notes & {Consonant/\\ Dissonant}
                                & {{{Expressed\\ as a Function}}}   
                                                            \\
Perfect Unison
            & C4 -- C4          & Consonant & {{{$\begin{multlined}
                                                f(x)= \sin 261.63\pi x \\[-1ex]
                                                        {} + \sin 261.63\pi x
                                               \end{multlined}$}}}  
                                                            \\
Minor 2nd   & C4 -- D$\flat$4   & Dissonant     & 261.63    \\
Minor 2nd   & C4 -- D$\flat$4   & Dissonant     & 261.63    \\
Major 2nd   & C4 -- D4          & Dissonant     & 277.18    \\
Minor 3rd   & C4 -- E$\flat$4   & Consonant     & 293.66    \\
Major 3rd   & C4 -- E4          & Consonant     & 311.13    \\
Perfect 4th & C4 -- F4          & Consonant      & 329.63   \\
Tritone     & \SetCell[c=1]{bg=blue!30} C4 -- F$\sharp$4 
                                & Dissonant     & 369.99    \\
Perfect 5th & C4 -- G4          & Consonant     & 391.99    \\
Minor 6th   & C4 -- A$\flat$4   & $2^{2/3}$     & 415.30    \\
Major 6th   & C4 -- A4          & $2^{3/4}$     & 440       \\
Minor 7th   & C4 -- B$\flat$4   & $2^{5/6}$     & 466.16    \\
Major 7th   & C4 -- B4          & $2^{11/12}$   & 494       \\
Perfect Octave
            & C4 -- C5          & $2$           & 523.25    \\
    \end{tblr}
\end{table}
\end{frame}
\end{document}

enter image description here

7
  • Thank you for the feedback!!
    – Ziggy
    Nov 27, 2021 at 23:07
  • @MaxB, you are welcome.! BTW, you can upvote answer or even accept it :-)
    – Zarko
    Nov 27, 2021 at 23:19
  • I'd really like to incorporate your changes but doing so seems like it would be a great deal of work. I cannot get the line break to work as you have it specified with my tabular table. \vtop{\hbox{\strut Consonant/}\hbox{\strut Dissonant}} This option worked but it doesn't look as nice.
    – Ziggy
    Nov 27, 2021 at 23:28
  • @MaxB, I do not understand your comment. If you like to have nice tables, my answer show you a way, how to do this. BTW, use of table generator is not a short way to write a table. Especially when you like to have nice table or even use new, more powerful table packages (as is tabularray and for example also nicematrix). It is not so hard write table directly in your LaTeX editor. Syntax is very simple, for some commands may happen that you need to consult package documentation or ask here for help. Let me noted: don't insert huge tables in beamer, audience will not be grateful ...
    – Zarko
    Nov 27, 2021 at 23:40
  • I've been able to integrate your edits, and it's looking better!! Thank you! What can I do to change the entire row to one color? Instead of using \SetCell
    – Ziggy
    Nov 28, 2021 at 0:10
0

I needed to include a package that was missing.

\usepackage{colortbl}

this fixed my error.

0

You must log in to answer this question.

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