[Tex/LaTex] Formatting of Tables in Latex, using multirow and multicolumn together

multicolumnmultirowpdftextables

When I used this piece down, I got.

\documentclass[a4paper,12pt]{report}
\usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.75in]{geometry}
\usepackage{graphicx}
\usepackage{url}
\usepackage[sc]{mathpazo}
%\usepackage{mathptmx}
\usepackage{url}
\usepackage[onehalfspacing]{setspace}
\usepackage{parskip}
\usepackage{paralist}
\usepackage{multirow}
\begin{document}
\begin{table}[!htb]
\centering
\caption{Present Strength-Production}
\begin{tabular}{|c|l|l|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{Sl.No} & 
\multicolumn{2}{c|}{\multirow{2}{*}{\textbf{Designation}}} & 
\multicolumn{4}{c|}{\textbf{Shifts}} &\textbf{Leave/Off} & 
\multirow{2}{*}{\textbf{Total}}\\
\cline{4-7}
& & &\textbf{A} & \textbf{B} & \textbf{C}& \textbf{G}&\textbf{Reserve}&\\
\hline
1 & \multicolumn{2}{l|}{Plant Engineer} & & & & 1& & 1\\
\hline
\multicolumn{3}{|l|}{\textbf{Sub Total}} & & & & \textbf{1} & & \textbf{1}\\
\hline
2&\multirow{2}{*}{Operator}&Work related to water regeneration&1&1&1&&1& 
4\\
\cline{3-9}
3& & Work related to valve control& 1&1&1& &1&4\\
\hline
\multicolumn{3}{|l|}{\textbf{Sub Total}}&\textbf{2}&\textbf{2}&\textbf{2}&
&\textbf{2} & \textbf{8}\\
\hline
1 & \multicolumn{2}{l|}{Worker} &2 & 2& 2& & 2& 8\\
\hline
\multicolumn{3}{|l|}{\textbf{Sub Total}} &\textbf{2}&\textbf{2}&\textbf{2}&
&\textbf{2} & \textbf{8}\\ \hline \hline
\multicolumn{3}{|l|}{\textbf{Total}} &\textbf{4} &\textbf{4} &\textbf{4} 
&\textbf{1}&\textbf{4} & \textbf{17}\\
\hline
\end{tabular}
\label{tab:pro_pro}
\end{table}
\end{document}

output

Can anyone show me the right path?

Certain important things are

  • The starting place of Sub total and Total should be from the second column
  • The vertical line in the Designation box
  • Horizontal line between 2 and 3

Best Answer

Here are some tips:

  • Use a \multicolumn{1}{|l}{} & \multicolumn{2}{l|}{...} construct;
  • Add another \multicolumn{2}{c|}{} to the second row; and
  • Use an additional \cline{1-1} to insert a rule between elements in the first column.

enter image description here

\documentclass[a4paper,12pt]{report}
\usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.75in]{geometry}
\usepackage[sc]{mathpazo}
\usepackage{multirow}
\begin{document}
\begin{table}[!htb]
  \centering
  \caption{Present Strength-Production}
  \begin{tabular}{|c|l|l|c|c|c|c|c|c|}
    \hline
    \multirow{2}{*}{Sl.No} & 
    \multicolumn{2}{c|}{\multirow{2}{*}{\textbf{Designation}}} & 
    \multicolumn{4}{c|}{\textbf{Shifts}} & \textbf{Leave/Off} & 
    \multirow{2}{*}{\textbf{Total}} \\
    \cline{4-7}
    & \multicolumn{2}{c|}{} & \textbf{A} & \textbf{B} & \textbf{C} & \textbf{G} & \textbf{Reserve} & \\
    \hline
    1 & \multicolumn{2}{l|}{Plant Engineer} & & & & 1 & & 1 \\
    \hline
    \multicolumn{1}{|l}{} & \multicolumn{2}{l|}{\textbf{Sub Total}} & & & & \textbf{1} & & \textbf{1} \\
    \hline
    2 & \multirow{2}{*}{Operator}&Work related to water regeneration & 1 & 1 & 1 & & 1 & 4 \\
    \cline{1-1}\cline{3-9}
    3 & & Work related to valve control & 1 & 1 & 1 & & 1 & 4 \\
    \hline
    \multicolumn{1}{|l}{} & \multicolumn{2}{l|}{\textbf{Sub Total}} & \textbf{2} & \textbf{2} & \textbf{2} & & \textbf{2} & \textbf{8} \\
    \hline
    1 & \multicolumn{2}{l|}{Worker} & 2 & 2 & 2 & & 2 & 8 \\
    \hline
    \multicolumn{1}{|l}{} & \multicolumn{2}{l|}{\textbf{Sub Total}} & \textbf{2} & \textbf{2} & \textbf{2} & & \textbf{2} & \textbf{8} \\
    \hline \hline
    \multicolumn{1}{|l}{} & \multicolumn{2}{l|}{\textbf{Total}} & \textbf{4} & \textbf{4} & \textbf{4} 
    & \textbf{1} & \textbf{4} & \textbf{17} \\
    \hline
  \end{tabular}
  \label{tab:pro_pro}
\end{table}
\end{document}