我想让我的表格适合文本块。目前,我的表格的很大一部分在页面的右侧被截断。我的代码是:
\documentclass{article}
\usepackage{graphicx} % for \scalebox macro
\begin{document}
\begin{table}[h]
\begin{center}
\scalebox{0.8}{
\begin{tabular}{|l|l|l|l|l}
\cline{1-4}
Risk Event & Chance of Happening & Severity & Measures to be taken & \\ \cline{1-4}
Team member missing meetings & Significant & Low & Encourage team members to read over minutes and inform of any tasks set. If regularly absent issue a warning and then card. & \\ \cline{1-4}
QA/Project manager missing meetings & Significant & Low/Moderate & Deputy in role will act as manager. & \\ \cline{1-4}
Team member leaving project group & Low & Moderate/High & List all tasks assigned to missing team member and reassign them, after this refactor the timetable and planning. & \\ \cline{1-4}
\end{tabular}}
\end{center}
\end{table}
\end{document}
我尝试用 替换,\begin{center}
但flushleft
无济于事。如何让表格适合页面?
答案1
您的表格只有四列实际数据;第五列始终为空,因此应完全省略。如果删除第五列,您还可以将所有\cline{1-4}
说明替换为更简单的说明\hline
。
这主要问题不过,表格的宽度对于任何正常的页面尺寸来说都太宽了除非您让所有四列中的文本换行。因此,您不应使用基本l
列类型,而应使用允许文本换行的列类型。我建议您使用包tabularx
和该包的列类型(修改形式)X
。将环境的宽度设置tabularx
为\textwidth
。另外,由于列很窄,我建议您将材料排版为右对齐而不是完全对齐,以避免单词间空格太宽。
\documentclass{article}
\usepackage{tabularx,ragged2e}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{|*{4}{Y|}}
\hline
Risk Event & Chance of Happening & Severity & Measures to be taken \\
\hline
Team member missing meetings & Significant & Low & Encourage team members to read over minutes and inform of any tasks set. If regularly absent issue a warning and then card. \\ \hline
QA/Project manager missing meetings & Significant & Low/Moderate & Deputy in role will act as manager.\\ \hline
Team member leaving project group & Low & Moderate/High & List all tasks assigned to missing team member and reassign them, after this refactor the timetable and planning. \\
\hline
\end{tabularx}
\end{table}
\end{document}
附录:仅供比较,以下是表格的原始外观,我对代码只做了一处调整:我使用了\resizebox{\textwidth}{!}{...}
而不是\scalebox{0.8}{...}
来使表格适合文本块。我认为我们可以同意使用resizebox
along with l
-type 列是不是在这种情况下要走的路。
答案2
您可以使用tabularx
包来实现这一点。为了改进表格,我还加载了cellspace
,以使单元格内容的垂直间距不那么紧密,makecell
并使列标题具有通用格式以及单元格中换行的可能性。
我不明白这里最后一个空列是干什么用的,但是如果你不使用它,你不妨删除它。这样既可以简化代码,又可以使最后一个垂直规则与右边距对齐。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[showframe, nomarginpar]{geometry}
\usepackage{array, tabularx}
\renewcommand{\tabularxcolumn}[1]{>{\raggedright}m{#1}}
\newcolumntype{Y}{ >{\hsize =0.8\hsize}X}
\newcolumntype{Z}{ >{\hsize =1.2\hsize}X}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadalign{lc}
\renewcommand\cellalign{lc}
\usepackage{cellspace}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\addparagraphcolumntypes{X, Y, Z}
\begin{document}
\begin{table}[!htbp]
\begin{tabularx}{\linewidth}{|Y|l|l|S{Z}|l}
\cline{1-4}
\thead{Risk Event} & \thead{Chance\\ of Happening} & \thead{Severity} & \thead{Measures\\ to be taken} & \\
\cline{1-4}
Team member\break missing meetings & Significant & Low & Encourage team members to read over minutes and inform of any tasks set. If regularly absent issue a warning and then card. & \\
\cline{1-4}
QA/Project manager missing meetings & Significant & Low/Moderate & Deputy in role will act as manager. & \\
\cline{1-4}
Team member leaving project group & Low & Moderate/High & List all tasks assigned to missing team member and reassign them, after this refactor the timetable and planning. & \\
\cline{1-4}
\end{tabularx}%
\end{table}
\end{document}
答案3
使用@{}
:
\documentclass{article}
\usepackage[showframe]{geometry}
\begin{document}
\noindent\begin{tabular}{@{}*5{l}}
1 & 2 & 3 & 4 & 5\\
A & B & C & D & E\\
\end{tabular}
\end{document}
编辑
正如约翰在他的评论中指出的那样,你甚至不需要@{}
在你的表中有垂直线:
\documentclass{article}
\usepackage[showframe]{geometry}
\begin{document}
\noindent\begin{tabular}{*5{|l}}
1 & 2 & 3 & 4 & 5\\
A & B & C & D & E\\
\end{tabular}
\end{document}