将一页中的表格对齐到右边距

将一页中的表格对齐到右边距

由于我的研究论文指南规定的规则,我需要在同一页上对齐某些文本和与其相关的表格。我的问题是,将表格与其值和内容对齐会将其推到右边距。我尝试过将其居中甚至左对齐,但它并没有从其位置移动。如何解决这个问题?

\documentclass{article}

\usepackage[square, comma, sort&compress]{natbib} 
\usepackage[none]{hyphenat}
\usepackage[table]{xcolor}
\usepackage[rightcaption]{sidecap}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}


\begin{document}

\begin{table}[h]

\setlength\tabcolsep{1pt}
\begin{tabular}{ |P{1cm}|p{6cm}|P{2.1cm}|P{2cm}|p{5cm}|  }
\hline
\textbf{ID}& \textbf{Risk} &\textbf{Probability}& \textbf{Impact}& 
\textbf{Mitigation/Limitation} \\
\hline \hline
R1 & \textbf{Issues with Model}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xssssyz & xyzxyz 
& aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R2 & \textbf{System Faults}: aaaaa, aaaaa bbbbbbbb aaaaaaa, aaaaaaa xxxxxxxxx aaaaaa & 
xyz & xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R3 & \textbf{Outcome Unobtainable}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xyz & 
xyzxaaaaavyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R4 & \textbf{Delayed Deadlines}: aaaaa, aaaaa yyyyyy zzzzzzzzzzz yyyyyaaaa aaaaaaa, 
aaaaaaa aaaaaa & xyz & xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R5 & \textbf{Difficulty developing models}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xyz & 
xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa zzzzzz zzzzzzz yyyyyy aaaaa xxxxxxx.\\ \hline
\end{tabular}

\caption{Risk Analysis Table}
\label{table:5}
\end{table}

\end{document}

图片供参考: 在此处输入图片描述

答案1

为了避免使表格比文本区域更宽,我建议使用包裹tabularx

\documentclass{article}

\usepackage[square, comma, sort&compress]{natbib} 
\usepackage[none]{hyphenat}
\usepackage[table]{xcolor}
\usepackage[rightcaption]{sidecap}
\usepackage{tabularx}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
%\usepackage{showframe}% visualize the text area, head and marginpar column

\begin{document}

\begin{table}[ht]% note: h does not really work to place it always here
\setlength\tabcolsep{1pt}
\begin{tabularx}{\textwidth}{|c|X|c|c|X|}
\hline
\textbf{ID}& \textbf{Risk} &\textbf{Probability}& \textbf{Impact}& 
\textbf{Mitigation/\newline\hspace*{\fill}Limitation} \\
\hline \hline
R1 & \textbf{Issues with Model}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xssssyz & xyzxyz 
& aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R2 & \textbf{System Faults}: aaaaa, aaaaa bbbbbbbb aaaaaaa, aaaaaaa xxxxxxxxx aaaaaa & 
xyz & xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R3 & \textbf{Outcome Unobtainable}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xyz & 
xyzxaaaaavyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R4 & \textbf{Delayed Deadlines}: aaaaa, aaaaa yyyyyy zzzzzzzzzzz yyyyyaaaa aaaaaaa, 
aaaaaaa aaaaaa & xyz & xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R5 & \textbf{Difficulty developing models}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xyz & 
xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa zzzzzz zzzzzzz yyyyyy aaaaa xxxxxxx.\\ \hline
\end{tabularx}
\caption{Risk Analysis Table}
\label{table:5}
\end{table}

\end{document}

使用 tabularx 的表格

-columnsX组合在一起将表格提升到给定的宽度(\textwidth在示例中)。有关更多信息,请参阅手册。

但如果您愿意,您也可以使用页边距将表格相对于页面居中:

\documentclass{article}

\usepackage[square, comma, sort&compress]{natbib} 
\usepackage[none]{hyphenat}
\usepackage[table]{xcolor}
\usepackage[rightcaption]{sidecap}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{showframe}% visualize the text area, head and marginpar column

\begin{document}

\begin{table}[h]

\setlength\tabcolsep{1pt}
\centerline{\begin{tabular}{ |P{1cm}|p{6cm}|P{2.1cm}|P{2cm}|p{5cm}|  }
\hline
\textbf{ID}& \textbf{Risk} &\textbf{Probability}& \textbf{Impact}& 
\textbf{Mitigation/Limitation} \\
\hline \hline
R1 & \textbf{Issues with Model}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xssssyz & xyzxyz 
& aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R2 & \textbf{System Faults}: aaaaa, aaaaa bbbbbbbb aaaaaaa, aaaaaaa xxxxxxxxx aaaaaa & 
xyz & xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R3 & \textbf{Outcome Unobtainable}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xyz & 
xyzxaaaaavyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R4 & \textbf{Delayed Deadlines}: aaaaa, aaaaa yyyyyy zzzzzzzzzzz yyyyyaaaa aaaaaaa, 
aaaaaaa aaaaaa & xyz & xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R5 & \textbf{Difficulty developing models}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xyz & 
xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa zzzzzz zzzzzzz yyyyyy aaaaa xxxxxxx.\\ \hline
\end{tabular}}
\caption{Risk Analysis Table}
\label{table:5}
\end{table}

\end{document}

表格居中于页面

注意:图像中的附加框架是由包装制作的showframe,仅用于说明表格现在使用左边距和右边距。

另一种方法是使用以下方法旋转桌子:包裹rotating

\documentclass{article}

\usepackage[square, comma, sort&compress]{natbib} 
\usepackage[none]{hyphenat}
\usepackage[table]{xcolor}
\usepackage[rightcaption]{sidecap}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
%\usepackage{showframe}% visualize the text area, head and marginpar column
\usepackage{rotating}
\begin{document}

\begin{sidewaystable}[h]
\centering
\setlength\tabcolsep{1pt}
\begin{tabular}{ |P{1cm}|p{6cm}|P{2.1cm}|P{2cm}|p{5cm}|  }
\hline
\textbf{ID}& \textbf{Risk} &\textbf{Probability}& \textbf{Impact}& 
\textbf{Mitigation/Limitation} \\
\hline \hline
R1 & \textbf{Issues with Model}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xssssyz & xyzxyz 
& aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R2 & \textbf{System Faults}: aaaaa, aaaaa bbbbbbbb aaaaaaa, aaaaaaa xxxxxxxxx aaaaaa & 
xyz & xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R3 & \textbf{Outcome Unobtainable}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xyz & 
xyzxaaaaavyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R4 & \textbf{Delayed Deadlines}: aaaaa, aaaaa yyyyyy zzzzzzzzzzz yyyyyaaaa aaaaaaa, 
aaaaaaa aaaaaa & xyz & xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa\\ \hline
R5 & \textbf{Difficulty developing models}: aaaaa, aaaaa aaaaaaa, aaaaaaa aaaaaa & xyz & 
xyzxyz & aaaaa and aaaaa aaa aaaa aaaaa zzzzzz zzzzzzz yyyyyy aaaaa xxxxxxx.\\ \hline
\end{tabular}
\caption{Risk Analysis Table}
\label{table:5}
\end{sidewaystable}
\end{document}

使用 sidewaystable

还有其他几种可能的解决方案,例如使用较小的字体,使用包裹pdflscape, 使用包裹tabularrayETC。

补充一点:如果删除垂直线并减少水平线,大多数表格看起来会更好。请参阅包裹booktabs有关美观且易读的表格的信息。

相关内容