2

I am trying to make nice looking table with some data. Everything is fine except the width of column is fixed. I have tried many solutions but nothing works. How can the width of the column is change so that it can have little big statements perfectly at centred.

What I would like is 'Number of Questions' to take 2 lines and 'Statement A' and 
'Statement B' to appear in a single line without getting out of the columns.

Thanks for your time and help in advance.

enter image description here

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
%\usepackage[table,svgnames]{xcolor}
\usepackage[many]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}


\usepackage{array,multirow,tabularx}



\newcolumntype{Y}{>{\centering\arraybackslash}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=white!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{table}[htb]
\refstepcounter{table}
\begin{tcolorbox}[tab2,tabularx*={\renewcommand{\arraystretch}{1.5}}{Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y},title={Table \thetable. This is a table},boxrule=0.8pt]
& \multicolumn{5}{|c|}{Year 1}  & \multicolumn{5}{|c|}{Year 2}\\ \hline
& \multicolumn{2}{|c|}{Part-B}& \multicolumn{2}{|c|}{Part-C} &  & \multicolumn{2}{|c|}{Part-B}& \multicolumn{2}{|c|}{Part-C} & \\ \hline
 & Number of Questions     & Marks     & Number of Questions    & Marks     & Total    & Number of Questions     & Marks     & Number of Questions    & Marks     & Total\\\hline
statement A   & 10 & 20 & 30  & 4000  & 100& sum & sum    & 60.75  & sum & 121.5\\\hline
RA & 20 & 30 & 40  & 50  & 140 & sum & 60.75    & sum  & 60.75 & 71.5\\\hline
LA  & 30 & 40 & 50  & 60  & 180 & sum & 60.75    & sum  & 60.75 & 60.75\\\hline
statement B   & 60 & 90 & 120 & 150 & 420& 60.75 & 60.75    & sum  & 60.75 & sum\\\hline
\end{tcolorbox}
\end{table}

2 Answers 2

1

With geometry for smaller margins, a slightly smaller \tabcolsep and the help of an abbreviation you can get the following:

enter image description here

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
%\usepackage[table,svgnames]{xcolor}
\usepackage[many]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}

\usepackage{geometry}

\usepackage{array,multirow,tabularx}



\newcolumntype{Y}{>{\centering\arraybackslash}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=white!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{table}[htb]
\setlength{\tabcolsep}{5pt}
\refstepcounter{table}
\begin{tcolorbox}[tab2,tabularx*={\renewcommand{\arraystretch}{1.5}}{c|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y},title={Table \thetable. This is a table},boxrule=0.8pt]
& \multicolumn{5}{c|}{Year 1}  & \multicolumn{5}{c|}{Year 2}\\ \hline
& \multicolumn{2}{c|}{Part-B}& \multicolumn{2}{c|}{Part-C} &  & \multicolumn{2}{c|}{Part-B}& \multicolumn{2}{c|}{Part-C} & \\ \hline
 & NQ     & Marks     & NQ    & Marks     & Total    & NQ & Marks     & NQ    & Marks     & Total\\\hline
statement A   & 10 & 20 & 30  & 4000  & 100& sum & sum    & 60.75  & sum & 121.5\\\hline
RA & 20 & 30 & 40  & 50  & 140 & sum & 60.75    & sum  & 60.75 & 71.5\\\hline
LA  & 30 & 40 & 50  & 60  & 180 & sum & 60.75    & sum  & 60.75 & 60.75\\\hline
statement B   & 60 & 90 & 120 & 150 & 420& 60.75 & 60.75    & sum  & 60.75 & sum\\\hline
\multicolumn{11}{l}{NQ = Number of Questions}\\
\end{tcolorbox}
\end{table}

\end{document}

Similar idea as above but without the geometry package:

enter image description here

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
%\usepackage[table,svgnames]{xcolor}
\usepackage[many]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}

\usepackage{array,multirow,tabularx}



\newcolumntype{Y}{>{\centering\arraybackslash}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=white!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{table}[htb]
\setlength{\tabcolsep}{3pt}
\refstepcounter{table}
\begin{tcolorbox}[tab2,tabularx*={\renewcommand{\arraystretch}{1.5}}{|Y|c|c|c|c|c|c|c|c|c|c|},title={Table \thetable. This is a table},boxrule=0.8pt]
& \multicolumn{5}{c|}{Year 1}  & \multicolumn{5}{c|}{Year 2}\\ \hline
& \multicolumn{2}{c|}{Part-B}& \multicolumn{2}{c|}{Part-C} &  & \multicolumn{2}{c|}{Part-B}& \multicolumn{2}{c|}{Part-C} & \\ \hline
 & NQ     & Marks     & NQ    & Marks     & Total    & NQ & Marks     & NQ    & Marks     & Total\\\hline
statement A   & 10 & 20 & 30  & 4000  & 100& sum & sum    & 60.75  & sum & 121.5\\\hline
RA & 20 & 30 & 40  & 50  & 140 & sum & 60.75    & sum  & 60.75 & 71.5\\\hline
LA  & 30 & 40 & 50  & 60  & 180 & sum & 60.75    & sum  & 60.75 & 60.75\\\hline
statement B   & 60 & 90 & 120 & 150 & 420& 60.75 & 60.75    & sum  & 60.75 & sum\\\hline
\multicolumn{11}{l}{NQ = Number of Questions}\\
\end{tcolorbox}
\end{table}

\end{document}

With geometry, a smaller font size and without the abbreviation:

enter image description here

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
%\usepackage[table,svgnames]{xcolor}
\usepackage[many]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}

\usepackage{geometry}
\usepackage{makecell}
\usepackage{array,multirow,tabularx}



\newcolumntype{Y}{>{\centering\arraybackslash}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\small\sffamily,
colback=white!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{table}[htb]
\setlength{\tabcolsep}{3pt}
\refstepcounter{table}
\begin{tcolorbox}[tab2,tabularx*={\renewcommand{\arraystretch}{1.5}}{c|Y|c|Y|c|c|Y|c|Y|c|c},title={Table \thetable. This is a table},boxrule=0.8pt]
& \multicolumn{5}{c|}{Year 1}  & \multicolumn{5}{c|}{Year 2}\\ \hline
& \multicolumn{2}{c|}{Part-B}& \multicolumn{2}{c|}{Part-C} &  & \multicolumn{2}{c|}{Part-B}& \multicolumn{2}{c|}{Part-C} & \\ \hline
 & Number of \newline Qeustions     & Marks     & Number of \newline Qeustions   & Marks     & Total    & Number of \newline Qeustions & Marks     & Number of \newline Qeustions    & Marks     & Total\\
\hline
statement A   & 10 & 20 & 30  & 4000  & 100& sum & sum    & 60.75  & sum & 121.5\\\hline
RA & 20 & 30 & 40  & 50  & 140 & sum & 60.75    & sum  & 60.75 & 71.5\\\hline
LA  & 30 & 40 & 50  & 60  & 180 & sum & 60.75    & sum  & 60.75 & 60.75\\\hline
statement B   & 60 & 90 & 120 & 150 & 420& 60.75 & 60.75    & sum  & 60.75 & sum\\\hline
\end{tcolorbox}
\end{table}

\end{document}

Without geometry but with an even smaller font size:

enter image description here

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
%\usepackage[table,svgnames]{xcolor}
\usepackage[many]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}

%\usepackage{geometry}
\usepackage{makecell}
\usepackage{array,multirow,tabularx}



\newcolumntype{Y}{>{\centering\arraybackslash}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\scriptsize\sffamily,
colback=white!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{table}[htb]
\setlength{\tabcolsep}{2pt}
\refstepcounter{table}
\begin{tcolorbox}[tab2,tabularx*={\renewcommand{\arraystretch}{1.5}}{c|Y|c|Y|c|c|Y|c|Y|c|c},title={Table \thetable. This is a table},boxrule=0.8pt]
& \multicolumn{5}{c|}{Year 1}  & \multicolumn{5}{c|}{Year 2}\\ \hline
& \multicolumn{2}{c|}{Part-B}& \multicolumn{2}{c|}{Part-C} &  & \multicolumn{2}{c|}{Part-B}& \multicolumn{2}{c|}{Part-C} & \\ \hline
 & Number of \newline Qeustions     & Marks     & Number of \newline Qeustions   & Marks     & Total    & Number of \newline Qeustions & Marks     & Number of \newline Qeustions    & Marks     & Total\\
\hline
statement A   & 10 & 20 & 30  & 4000  & 100& sum & sum    & 60.75  & sum & 121.5\\\hline
RA & 20 & 30 & 40  & 50  & 140 & sum & 60.75    & sum  & 60.75 & 71.5\\\hline
LA  & 30 & 40 & 50  & 60  & 180 & sum & 60.75    & sum  & 60.75 & 60.75\\\hline
statement B   & 60 & 90 & 120 & 150 & 420& 60.75 & 60.75    & sum  & 60.75 & sum\\\hline
\end{tcolorbox}
\end{table}

\end{document}
2
  • Thanks for the ideas leandriis.. These are workaround solutions. I was looking for something with which I can control the width of column as I can with rows.
    – Kumarm
    Jun 13, 2019 at 0:09
  • If you want to manually control the column width, use p type columns instead. If this is still not what you are looking for please clarify your question.
    – leandriis
    Jun 13, 2019 at 5:15
4

This is just an idea: if you rotate the table, it easily fits in one text line.

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}


\usepackage{array,multirow,tabularx}

\newtcolorbox[blend into=tables]{mytable}[2][]{%
    enhanced,
    fonttitle=\bfseries,
    fontupper=\sffamily,
    colback=white!10!white,
    colframe=red!50!black,
    colbacktitle=Salmon!40!white,
    coltitle=black,
    center title,
    boxrule=.8pt,
    float=htb,
    title={#2},
    #1
}

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}
\begin{mytable}[tabularx*={\renewcommand{\arraystretch}{1.5}}{ccccccc}]{This is a table}
& & & Statement A & RA & LA & Statement B \\
\multirow{5}{*}{\rotatebox{90}{Year 1}}  & 
\multirow{2}{*}{\rotatebox{90}{Part B}}  &
Number of questions   & 10 & 20 & 30 & 60 \\
&& Marks & 20 & 30 & 40 & 90 \\
 & \multirow{2}{*}{\rotatebox{90}{Part C}}  &
Number of questions   & 30 & 40 & 50 & 120 \\
&& Marks & 4000 & 50 & 60 & 150 \\
&& Total & 100 & 140 & 180 & 420 \\
%
\hline
\multirow{5}{*}{\rotatebox{90}{Year 2}}  & 
\multirow{2}{*}{\rotatebox{90}{Part B}}  &
Number of questions   & 10 & 20 & 30 & 60 \\
&& Marks & 20 & 30 & 40 & 90 \\
 & \multirow{2}{*}{\rotatebox{90}{Part C}}  &
Number of questions   & 30 & 40 & 50 & 120 \\
&& Marks & 4000 & 50 & 60 & 150 \\
&& Total & 100 & 140 & 180 & 420 \\

\end{mytable}
\end{document}

enter image description here

1
  • Thanks, but that's not what I am looking for.
    – Kumarm
    Jun 12, 2019 at 16:29

You must log in to answer this question.

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