1

What seems to be so simple has turned so fiddly. All I want to do is have a basic table 3 rows by 10 columns. Row one should be highlighted lightgray and row 3 a lighter gray (defined as lightlightgray). Also in row 1, columns 1 and 2 should be merged, 3 and 4 merged, 5 and 6 merged, 7 and 8 merged and 9 and 10 merged. Finally, the text in each of these merged cells should be centered and wrap where necessary as the table would be too wide to fit on the page. I have added a screenshot of an equivalent table in excel and then what im getting in latex. The issues are the all cells wont color fill, columns wont stay the same size and table lines disappear at random.

enter image description here

enter image description here

My code follows

\documentclass[pdftex,12pt,a4paper]{report}

% SET UP THE DOCUMENT
\usepackage[lmargin=3cm,rmargin=2cm,tmargin=2cm,bmargin=2cm]{geometry}
\usepackage{setspace}
\usepackage{framed}
\usepackage[usenames,table,dvipsnames]{xcolor}
\definecolor{lightlightgray}{gray}{0.95}
\usepackage{fancybox}
\usepackage{caption}
\usepackage[hidelinks]{hyper ref} %Allows for clickable references
\setcounter{secnumdepth}{5} %Allow for levels of section eg:5.2.1.1
\usepackage[none]{hyphenat}

%USE THESE TO CONTROL TABLES
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\usepackage[english]{babel}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage {rotating}

%THESE CONTROL THE IMAGES/PICTURES PACKAGE
\usepackage{float} %Allows for control of float 

%THIS LOADS THE BIBLIOGRAPHY PACKAGE
\usepackage{apacite} %change this to IEEE if you want

\begin{document}

\begin{table}[H]
    \centering
    \caption[2018 SECaT Scores]{Please HELLPPP}.
    \label{tab:secat}
    \begin{tabular}{|p{1.1cm}|p{1.1cm}|p{1.2cm}|p{1.2cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|} \hline
    \rowcolor{lightgray}
    \multicolumn{2}{C{1.1cm}}{\textbf{Strongly Agree}} & \multicolumn{2}{|c|}{\textbf{Agree}} & \multicolumn{2}{C{1.4cm}}{\textbf{Neither Agree/Disagree}} & \multicolumn{2}{|c|}{\textbf{Disagree}} & \multicolumn{2}{C{1.1cm}}{\cellcolor{lightgray}\textbf{Strongly Disagree}} \\ \hline
    \% & No. & \% & No. & \% & No. & \% & No. & \% & No.\\ \hline
    \rowcolor{lightlightgray}
        17\% & 25 & 38\% & 57 & 27\% & 40 & 10\% & 15 & 9\% & 13 \\ \hline
    \end{tabular}
\end{table}

\end{document}
2
  • Welcome to TeX SX! Your \multicolumn{2}{C} won't be 1.1 cm wide.
    – Bernard
    Commented May 27, 2019 at 13:12
  • Thanks, could you advise how I achieve the desired outcome?
    – Skhotheni
    Commented May 27, 2019 at 14:34

2 Answers 2

1

Here is a solution using stackengine for the column heads, and tabularx:

\documentclass[pdftex, 12pt, a4paper]{report}

% SET UP THE DOCUMENT
\usepackage[lmargin=3cm,rmargin=2cm,tmargin=2cm,bmargin=2cm, showframe]{geometry}
\usepackage{setspace}
\usepackage{framed}
\usepackage[usenames,table,dvipsnames]{xcolor}
\definecolor{lightlightgray}{gray}{0.95}
\usepackage{fancybox}
\usepackage{caption}
\usepackage[hidelinks]{hyper ref} %Allows for clickable references
\setcounter{secnumdepth}{5} %Allow for levels of section eg:5.2.1.1
\usepackage[none]{hyphenat}

%USE THESE TO CONTROL TABLES
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\usepackage[english]{babel}
\usepackage{array}
\usepackage {rotating}
\usepackage{tabularx}
%THESE CONTROL THE IMAGES/PICTURES PACKAGE
\usepackage{float} %Allows for control of float
\usepackage[usestackEOL]{stackengine}
%THIS LOADS THE BIBLIOGRAPHY PACKAGE
\usepackage{apacite} %change this to IEEE if you want

\begin{document}

\begin{table}[H]
    \centering\setstackgap{L}{2.5ex}
    \setlength{\extrarowheight}{3pt}
    \setlength{\tabcolsep}{2pt}
    \caption[2018 SECaT Scores]{Please HELLPPP}
    \label{tab:secat}
    \begin{tabularx}{\linewidth}{|*{10}{>{\centering\arraybackslash}X|}}
     \hline
  \rowcolor{lightgray}[\tabcolsep]
 \multicolumn{2}{|>{\bfseries}c|}{\Centerstack{Strongly\\ Agree}} & \multicolumn{2}{c|}{\textbf{Agree}} & \multicolumn{2}{>{\small\bfseries}c|}{\Centerstack{Neither\\ Agree/Disagree}} & \multicolumn{2}{c|}{\textbf{Disagree}} & \multicolumn{2}{>{\bfseries}c|}{\Centerstack{Strongly\\ Disagree}} \\ \hline
    \% & No. & \% & No. & \% & No. & \% & No. & \% & No.\\ \hline
    \rowcolor{lightlightgray}
        17\% & 25 & 38\% & 57 & 27\% & 40 & 10\% & 15 & 9\% & 13 \\ \hline
    \end{tabularx}
\end{table}

\end{document} 

enter image description here

1
  • Thanks so much!
    – Skhotheni
    Commented May 28, 2019 at 4:44
0

an alternative:

\documentclass[12pt,a4paper]{report}
% SET UP THE DOCUMENT
\usepackage[hmargin={3cm,2cm},vmargin=2cm]{geometry}
\usepackage[usenames,dvipsnames,table]{xcolor}
\definecolor{lightlightgray}{gray}{0.95}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newlength{\twocolwidth}
\setlength\twocolwidth{\dimexpr0.2\hsize+\tabcolsep+\arrayrulewidth}

\begin{document}
    \begin{table}[ht]
    \centering
    \setlength\tabcolsep{.5\tabcolsep}
    \setlength\extrarowheight{1pt}
    \renewcommand\tabularxcolumn[1]{m{#1}}
\caption[2018 SECaT Scores]{Please HELLPPP}.
\label{tab:secat}
\begin{tabularx}{\linewidth}{ |*{10}{C|} }
    \hline
\rowcolor{lightgray}
\multicolumn{2}{|>{\hsize=\twocolwidth}C|}{\textbf{Strongly Agree}} 
& \multicolumn{2}{>{\hsize=\twocolwidth}C|}{\textbf{Agree}} 
& \multicolumn{2}{>{\hsize=\twocolwidth}C|}{\textbf{Neither Agree or Disagree}} 
& \multicolumn{2}{>{\hsize=\twocolwidth}C|}{\textbf{Disagree}} 
& \multicolumn{2}{>{\hsize=\twocolwidth}C|}{\textbf{Strongly Disagree}} \\ \hline
\%   & No. & \%   & No. & \%   & No. & \%   & No. & \%  & No.\\ \hline
\rowcolor{lightlightgray}
17\% & 25  & 38\% & 57  & 27\% & 40  & 10\% & 15  & 9\% & 13 \\ \hline
\end{tabularx}
    \end{table}
\end{document}

enter image description here

2
  • Thanks so much!
    – Skhotheni
    Commented May 28, 2019 at 4:44
  • @Skhotheni, you are welcome. Now you can accept (by clicking on the check mark at top left side of answer) one from received answers which on the best way solve your problem :-)
    – Zarko
    Commented May 28, 2019 at 4:48

You must log in to answer this question.

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