Table: align two columns values in a row

I am writing a long document until I reached a point to write my work plan in a table. Now I want to set the timeline of each activity, to align to the corresponding task.

MSE below:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{floatrow}
\usepackage{tabularx}

\begin{document}

\begin{table}[h]
\caption{Table of activities}
\label{tblactivity}
\centering
\begin{tabular}{lccc}
\toprule
\textbf{No.} & \textbf{Activity}   & \textbf{Task(s) to be completed}  &
\textbf{Timeline}\\
\midrule
\textbf{1} &\multicolumn{1}{m{3cm}}{\textbf{\textit{Activity number 1}}} & \multicolumn{1}{m{7cm}}{ \begin{enumerate}
\item Some long sentence here, describing task 1 of activity 1
\item Another long sentence here, describing task 2 of activity 1
\item Yet another long sentence here, describing task 3 of activity 1
\item Activity 1 task 4 ...
\end{enumerate} } &
\\
\midrule
\textbf{2} &  \multicolumn{1}{m{3cm}}{\textbf{\textit{Activity number 2}}} & \multicolumn{1}{m{7cm}}{ \begin{enumerate}
\item Activity 2 task 1
\item Activity 2 task 2
\item Activity 2 task 3
\end{enumerate} } \\

\bottomrule
\end{tabular}
\hfill
\end{table}

\end{document}


For each task 1,2,3 & 4 of activity 1 (say 2 months, 2 months, 1 month, 1 month), I want to set the deadline such that the time align with the task. So also Activity 2 etc...

• Are you aware that our table is much wider than the textwidth of a standard article document? – leandriis Dec 7 '19 at 15:31

The easiest way to align the deadlines with the tasks is probably just not to use enumerate environments, and to place each task in a separate cell in the table. This way you can easily place each deadline in its own cell, properly aligned with the corresponding task.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{floatrow}
\usepackage{tabularx}
\usepackage{multirow}

\begin{document}

\begin{table}[h]
\caption{Table of activities}
\label{tblactivity}
\centering
\begin{tabular}{llp{1mm}p{6cm}p{2cm}}
\toprule
\textbf{No.} & \multicolumn{1}{c}{\textbf{Activity}} && \textbf{Task(s) to be completed}  &
\textbf{Timeline}\\
\midrule
\multirow{7}{*}{\textbf{1}} & \multirow{7}{*}{\textbf{\textit{Activity number 1}}}
& 1. & Some long sentence here, describing task 1 of activity 1 & Deadline 1 \\
&& 2. & Another long sentence here, describing task 2 of activity 1 & Deadline 2 \\
&& 3. & Yet another long sentence here, describing task 3 of activity 1 & Deadline 3 \\
&& 4. & Activity 1 task 4 & Deadline 4 \\
\midrule
\multirow{3}{*}{\textbf{2}} & \multirow{3}{*}{\textbf{\textit{Activity number 2}}}
& 1. & Activity 2 task 1 & Deadline 1 \\
&& 2. & Activity 2 task 2 & Deadline 2 \\
&& 3. & Activity 2 task 3  & Deadline 3 \\
\bottomrule
\end{tabular}
\hfill
\end{table}

\end{document}


• I cannot figure out where you set the font size, it looking small in the table. – arilwan Dec 8 '19 at 23:03
• I left the default in this example. If you want to set it, you can specify it as an optional argument to documentclass. For example, you could write \documentclass[12pt]{article}. – Vincent Dec 8 '19 at 23:11
• my document class is already set to 10pt \documentclass[a4paper, 10pt]{report} all sections are OK as I want to, but the font size within the table is small. See the screenshot I added. – arilwan Dec 9 '19 at 0:05
• I'm not sure what is the best way to increase the font size only in the table, but you could add a \large at the beginning of the table environment. The answers here should be helpful. – Vincent Dec 9 '19 at 1:02
• No itºs OK, I managed to workaround and make it better. – arilwan Dec 9 '19 at 1:42

With defining special column tyle E which˙has integrated enumerate and minipage :

\documentclass{article}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{E}{ >{\csname @minipagetrue\endcsname% list is in minipage env.
\RaggedRight\enumerate}X<{\endenumerate}}  % <---
\newcommand*\mcc[1]{\multicolumn{1}{>{\bfseries}l}{#1}}         % <---
\usepackage{enumitem}

\begin{document}
\begin{table}
\setcellgapes{1pt}
\makegapedcells
\setlist[enumerate]{%
resume=column, % ensure sequential numbering
nosep,
leftmargin=*,
label=\arabic*.,
after=\vspace*{-\baselineskip}
}
\begin{tabularx}{\linewidth}{@{} c >{\RaggedRight}p{17mm} E l @{}}
\toprule
\mcc{No.}
& \mcc{Activity}
& \mcc{Task(s) to be completed}         & \mcc{Timeline}    \\
\midrule
1   &   \multirow[t]{4}{=}{Activity number 1}
& \setcounter{enumi}{0}   %%%% <------- start numbering with 1
\item Some long sentence here,
describing task 1 of activity 1 & monday            \\
&   & \item Another long sentence here,
describing task 2 of activity 1 & in 2 weeks        \\
&   & \item Yet another long sentence here,
describing task 3 of activity 1 & timeline          \\
&   & \item Activity 1 task 4 \dots         & timeline          \\
\midrule
2   &   \multirow[t]{2}{=}{Activity number 2}
& \setcounter{enumi}{0}   %%%% <------- restart numbering with 1
\item Some long sentence here,
describing task 1 of activity 1 & monday            \\
&   & \item Another long sentence here,
describing task 2 of activity 1 & in 2 weeks        \\
&   & \item Yet another long sentence here,
describing task 3 of activity 1 & timeline          \\
&   & \item Activity 1 task 4 \dots         & timeline          \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}


• Yes, but I want the tasks numbering to start from 1 for each activity. – arilwan Dec 7 '19 at 23:52
• @arilwan, ah, I overlooked that. Now is corrected. – Zarko Dec 8 '19 at 6:47

Here is my suggestion using enumitem and a custom defined command to save typing. I have also used tabularx in order to make the table fit into the textwidth. I have also added an alternative layout with less white space in the left columns:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabularx}

\usepackage{enumitem}

\newcommand{\mytabenum}[2][resume=mylist]{\begin{enumerate}[#1, label*=\arabic*.,leftmargin=*,nosep,leftmargin=*,before=\vspace{-0.5\baselineskip},after=\vspace{-1\baselineskip}]\item #2 \end{enumerate}}

\begin{document}

\begin{table}[h]
\caption{Table of activities}
\label{tblactivity}
\centering
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}p{1.5cm}Xl}
\toprule
\textbf{No.} & \textbf{Activity}   & \textbf{Task(s) to be completed}  &  \textbf{Timeline}\\
\midrule
1 & Activity number 1 & \mytabenum[series=mylist]{Some long sentence here, describing task 1 of activity 1} & monday \\
&  & \mytabenum{Another long sentence here, describing task 2 of activity 1} & in 2 weeks\\
&  & \mytabenum{Yet another long sentence here, describing task 3 of activity 1} & timeline\\
&  & \mytabenum{Activity 1 task 4 ...} & timeline\\
\midrule
2 & Activity number 2 & \mytabenum[series=mylist]{Some long sentence here, describing task 1 of activity 1} & monday \\
&  & \mytabenum{Another long sentence here, describing task 2 of activity 1} & in 2 weeks\\
&  & \mytabenum{Yet another long sentence here, describing task 3 of activity 1} & timeline\\
&  & \mytabenum{Activity 1 task 4 ...} & timeline\\
\bottomrule
\end{tabularx}
\end{table}

\begin{table}[h]
\caption{Table of activities}
\label{tblactivity}
\centering
\begin{tabularx}{\textwidth}{p{\tabcolsep}Xl}
\toprule
& \textbf{Task(s) to be completed}  &  \textbf{Timeline}\\
\midrule
\multicolumn{3}{l}{1 Activity number 1} \\
& \mytabenum[series=mylist]{Some long sentence here, describing task 1 of activity 1} & monday \\
& \mytabenum{Another long sentence here, describing task 2 of activity 1} & in 2 weeks\\
& \mytabenum{Yet another long sentence here, describing task 3 of activity 1} & timeline\\
& \mytabenum{Activity 1 task 4 ...} & timeline\\
\midrule
\multicolumn{3}{l}{2 Activity number 2} \\
& \mytabenum[series=mylist]{Some long sentence here, describing task 1 of activity 1} & monday \\
& \mytabenum{Another long sentence here, describing task 2 of activity 1} & in 2 weeks\\
& \mytabenum{Yet another long sentence here, describing task 3 of activity 1} & timeline\\
& \mytabenum{Activity 1 task 4 ...} & timeline\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}