\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}
\Q
我怎样才能将第二个表格与和命令创建的段落对齐,\A
使其集中到页面并将内容包装到列边距中,而不删除\multicolumn
?
答案1
我建议使用X
tabularx 提供的列类型,而不是l
列类型。这样可以保证线条不会超出表格的边。您可以对多列使用相同的方法,只需进行一些修复即可这里。为了让整个表格居中,就像 Sveinung 所评论的那样,\noindent
应该可以解决问题。
\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}
答案2
第一个表嵌套在table
环境中,而第二个表没有嵌套——这会产生缩进——简单地说,第二个表也嵌套在环境中\begin{table}.....\end{table}
——这两个表现在将对齐
就页面外装配而言,请参考 TivV 提供的好解决方案 - 当然,我喜欢以视觉方式为我的表格着色 - 您可以在此处使用我的答案中的命令 -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}