I have a relatively complex table that looks like this:
The same table structure is going to be repeated so many times. I already have the tables in MS Word. My question is if there is an easy method to fill the data in the table code?
Here's the code:
\documentclass[12pt]{report}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{multirow}
%This will change the font for all the tables in the document.
\makeatletter
\g@addto@macro{\table[ht]}{\fontsize{9pt}{10.8pt}\selectfont}
\makeatother
\begin{document}
\begin{table}[ht]
\newcolumntype{Z}{>{\centering\arraybackslash}m{4.11in}}
\newcolumntype{Y}{>{\centering\arraybackslash\columncolor{Gainsboro}}c}
\renewcommand*{\arraystretch}{1.2}
\centering
\caption{Experiences in practical Physics work}
\begin{tabular}{|c|Y|c|c|c|c|c|c|}
\hline
& & \multicolumn{3}{c}{\emph{\textbf{\%}}} & \multicolumn{3}{|c|}{\emph{\textbf{Comparisons}}} \\
\hline \rowcolor{Gainsboro} {\textbf{Group}}& {\textbf{N}} & \textbf{positive} & \textbf{neutral} & \textbf{negative} & \textbf{$\chi^2$} & \textbf{df} & \textbf{p} \\
\hline
\rowcolor{Gainsboro}{\emph{Q1 (a)}} & \multicolumn{7}{Z|}{I prefer to have written instructions for experiments} \\
\hline
\cellcolor{PowderBlue}\emph{University group} & {150} & 73 & 7 & 20 & \multirow{2}{*}{0.9} & \multirow{2}{*}{4} & \multirow{2}{*}{ns} \\
\cline{1-5}
\cellcolor{YellowGreen}\emph{School group} & {150} & 70 & 8 & 22 & & & \\
\hline
\rowcolor{Gainsboro}{\emph{Q1 (b)}} & \multicolumn{7}{Z|}{Practical work helps my understanding of Physics topics} \\
\hline
\cellcolor{PowderBlue}\emph{University group} & {150} & 34 & 11 & 55 & \multirow{2}{*}{3.9} & \multirow{2}{*}{4} & \multirow{2}{*}{ns} \\
\cline{1-5}
\cellcolor{YellowGreen}\emph{School group} & {150} & 38 & 7 & 55 & & & \\
\hline
\rowcolor{Gainsboro}{\emph{Q1 (c)}} & \multicolumn{7}{Z|}{Discussions in the laboratory enhance my understanding of the subject} \\
\hline
\cellcolor{PowderBlue}\emph{University group} & {150} & 70 & 8 & 22 & \multirow{2}{*}{2.4} & \multirow{2}{*}{4} & \multirow{2}{*}{ns} \\
\cline{1-5}
\cellcolor{YellowGreen}\emph{School group} & {150} & 65 & 10 & 25 & & & \\
\hline
\rowcolor{Gainsboro}{\emph{Q1 (d)}} & \multicolumn{7}{Z|}{I felt confident in carrying out the experiments in Physics} \\
\hline
\cellcolor{PowderBlue}\emph{University group} & {150} & 52 & 12 & 36 & \multirow{2}{*}{13.7} & \multirow{2}{*}{4} & \multirow{2}{*}{< 0.05} \\
\cline{1-5}
\cellcolor{YellowGreen}\emph{School group} & {150} & 44 & 15 & 41 & & & \\
\hline
\rowcolor{Gainsboro}{\emph{Q1 (e)}} & \multicolumn{7}{Z|}{The experimental procedure was clearly explained in the instructions given} \\
\hline
\cellcolor{PowderBlue}\emph{University group} & {150} & 31 & 14 & 55 & \multirow{2}{*}{14.8} & \multirow{2}{*}{4} & \multirow{2}{*}{< 0.01} \\
\cline{1-5}
\cellcolor{YellowGreen}\emph{School group} & {150} & 46 & 11 & 43 & & & \\
\hline
\rowcolor{Gainsboro}{\emph{Q1 (f)}} & \multicolumn{7}{Z|}{I was so confused in the laboratory that I ended up following the instructions without understanding what I was doing} \\
\hline
\cellcolor{PowderBlue}\emph{University group} & {150} & 63 & 12 & 25 & \multirow{2}{*}{1.1} & \multirow{2}{*}{4} & \multirow{2}{*}{ns} \\
\cline{1-5}
\cellcolor{YellowGreen}\emph{School group} & {150} & 65 & 9 & 26 & & & \\
\hline
\rowcolor{Gainsboro}{\emph{Q1 (g)}} & \multicolumn{7}{Z|}{There was good linkage between experiments and the relevant theory} \\
\hline
\cellcolor{PowderBlue}\emph{University group} & {150} & 36 & 15 & 49 & \multirow{2}{*}{94.4} & \multirow{2}{*}{4} & \multirow{2}{*}{<0.001} \\
\cline{1-5}
\cellcolor{YellowGreen}\emph{School group} & {150} & 68 & 11 & 21 & & & \\
\hline
\end{tabular}
\label{ch7:tab:experiencesinpracticalphysics}
\end{table}
\end{document}
I know that I shouldn't be asking two questions but this one is small: How do I make an individual cell transparent?
Edit: I made it MWE and here's another table with the same structure but different data:
Best Answer
The biggest thing to figure out really is exactly how do you want to specify the data. Here I have defined a
\Data
macro that accepts four mandatory parameters:To simplify things I decided to go with
&
separator as that is whattabular
needs (see Further Enhancements below). So, for instance the first set of data is defined as:and as you can see from this I defined macros for the labels
\UGroup
and\SGroup
. Specifying the data in this manner within the customMyTabular
environment yields:Notes:
collcell
package is used to automatically place the last three columns within a\multirow{2}{*}{<data>}
.\multirow
is only applied after the header is completed, I usednewtoggle
from theetoolbox
package as I prefer that syntax versus the\newif
syntax. But if you don't want to include an additional package it should be pretty straightforward to adapt this to use\newif
or some other conditional methods\UGroup
and\SGroup
for labels not only makes it more readable but provides additional flexibility in case you decide to tweak it later.\arraystretch
and\fontsize
to be within theMyTabular
environment, so that the adjustments are only have an effect withinMyTabular
.QuestionCount
andQuestionSubCount
are used to automate the labeling of the tables and each row of that data. You can adjust the formatting of these as desired.MyTabular
environment accepts an optional (i.e., within square brackets) first parameter to override the label for each row. Defaults toQ<n>
where<n>
takes on increasing integer values starting at 1.References:
booktabs
package for more table formatting options.Further Enhancements:
&
as a delimiter, a comma separated list would be preferred. However it should be noted that this is not at all as simple as it seems.Code: