0
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{caption,tabularx,booktabs}


\begin{document}


\newcounter{question}
\setcounter{question}{0}

\newcommand\Q{%
\refstepcounter{question}
\paragraph{Question \thequestion.}
}

\newcommand\A{%
\smallskip
}


\Q A medium company (40 people, all located in offices) is considering two options for cleaning the offices...

\A 

\begin{table}[h!]
\begin{tabular}{lll}
    \hline
    ~ & Insourced & Outsourced \\
    \hline
    Agency monitoring & Control employees & Control company service \\
    Agency bonding & Employees' report & Company report \\
    Agency residual loss & None & None \\
    \hline
    Transaction cost & None & Search company, establish contract \\
    \hline
    Decision & Collection of KPIs, cleaning logs & Collection of KPIs, cleaning logs \\
    \hline
    KPI1 - Cost & Cost of employees and equipment & Cost of service \\
    KPI2 - Quality & \multicolumn{2}{l}{Level of cleanness} \\
    KPI3 - Frequency & \multicolumn{2}{l}{Frequency of cleaning, n times per week a place is cleaned} \\
    \hline
\end{tabular}
\end{table}

\begin{tabularx}{\textwidth}{lll}
    \toprule
    Agency monitoring & Control employees & Control company service \\
    Agency bonding & Employees' report & Company report \\
    Agency residual loss & None & None \\
    \hline
    Transaction cost & None & Search company, establish contract \\
    \hline
    Decision & Collection of KPIs, cleaning logs & Collection of KPIs, cleaning logs \\
    \hline
    KPI1 - Cost & Cost of employees and equipment & Cost of service \\
    KPI2 - Quality & \multicolumn{2}{l}{Level of cleanness} \\
    KPI3 - Frequency & \multicolumn{2}{l}{Frequency of cleaning, n times per week a place is cleaned} \\
    \bottomrule
\end{tabularx}

\end{document}

How can I align the second table to the paragraph created by the \Q and \A commands centralizing it to the page and to wrap the content into the column margins without getting rid of the \multicolumn?

enter image description here

  • Just add a \noindentcommand before `\begin{tabularx}. – Sveinung Jan 21 '20 at 16:32
  • the first table is nested in a table environment the second is not -- this creates the indent--simply put the second table also within the \begin{table}.....\end{table} -- the 2 tables will be now aligned – js bibra Jan 22 '20 at 01:08

2 Answers2

2

I suggest using the X column type tabularx provides instead of the l column type. This takes care of the lines not going over the side of the table. You can use the same for the multicolumn, with a little fixing found here. In order for the whole table to be centered, like Sveinung commented, \noindent should do the trick.

\documentclass{article}

\usepackage{tabularx,booktabs,multirow,ragged2e}

\begin{document}

\noindent \begin{tabularx}{\textwidth}{@{} l *{2}{>{\RaggedRight\hspace{0pt}}X} @{}}
    \toprule
    Agency monitoring & Control employees & Control company service \\
    Agency bonding & Employees' report & Company report \\
    Agency residual loss & None & None \\
    \hline
    Transaction cost & None & Search company, establish contract \\
    \hline
    Decision & Collection of KPIs, cleaning logs & Collection of KPIs, cleaning logs \\
    \hline
    KPI1 - Cost & Cost of employees and equipment & Cost of service \\
    KPI2 - Quality & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+3\tabcolsep\relax}X}{Level of cleanness} \\
    KPI3 - Frequency & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+3\tabcolsep\relax}X}{Frequency of cleaning, n times per week a place is cleaned} \\
    \bottomrule
\end{tabularx}

\end{document}

enter image description here

TivV
  • 743
  • +1!, hoever: (i) in preamble I would add package ragged2e and than defined table X columns as >{\RaggedRight\hspace{0pt}}X, (ii) in defining width of the last multicolumn is arrayrulewidth superfluous since table hasn't vertical lines, (iii)last multicolumn cell spanfourtabcolsepoor only three, if the table options is defined as{@{} l *{2}{>{\RaggedRight\hspace{0pt}}X} @{}}`. – Zarko Jan 21 '20 at 18:14
  • @Zarko I think I implemented your advice. Feel free to edit the answer if I have misunderstood you. – TivV Jan 24 '20 at 14:24
0

enter image description here

the first table is nested in a table environment the second is not -- this creates the indent--simply put the second table also within the \begin{table}.....\end{table} -- the 2 tables will be now aligned

so far as the out of page fitment is concerned please refer to the nice solution by TivV--off course I like to visually color my tables--you can use the commands in my answer here -- https://tex.stackexchange.com/a/525106/197451

    \documentclass{article}
    \usepackage{caption,tabularx,booktabs}
    \usepackage[table]{xcolor}
    \usepackage{showframe}
    \usepackage{multirow}
    \begin{document}
    \begin{table}[h!]
    \begin{tabular}{lll}
    \hline
    ~ & Insourced & Outsourced \\
    \hline
    Agency monitoring & Control employees & Control company service \\
    Agency bonding & Employees' report & Company report \\
    Agency residual loss & None & None \\
    \hline
    Transaction cost & None & Search company, establish contract \\
    \hline
    Decision & Collection of KPIs, cleaning logs & Collection of KPIs, cleaning logs \\
    \hline
    KPI1 - Cost & Cost of employees and equipment & Cost of service \\
    KPI2 - Quality & \multicolumn{2}{l}{Level of cleanness} \\
    KPI3 - Frequency & \multicolumn{2}{l}{Frequency of cleaning, n times per week a 
    place is cleaned} \\
    \hline
    \end{tabular}

   \begin{tabularx}{\textwidth}{lll}
    \toprule
    Agency monitoring & Control employees & Control company service \\
    Agency bonding & Employees' report & Company report \\
    Agency residual loss & None & None \\
    \hline
    Transaction cost & None & Search company, establish contract \\
    \hline
    Decision & Collection of KPIs, cleaning logs & Collection of KPIs, cleaning logs \\
    \hline
    KPI1 - Cost & Cost of employees and equipment & Cost of service \\
    KPI2 - Quality & \multicolumn{2}{l}{Level of cleanness} \\
    KPI3 - Frequency & \multicolumn{2}{l}{Frequency of cleaning, n times per week a 
    place is cleaned} \\
    \bottomrule
    \end{tabularx}
    \end{table}

    \end{document}
js bibra
  • 21,280