表格对于双列模式文档来说太宽

表格对于双列模式文档来说太宽

我有一个表格,它超出了文本列的宽度,进入了纸张的边缘。如何让表格中的文本左对齐?

 \documentclass[a4paper,10pt]{article}
 \usepackage[utf8]{inputenc}

 \title{}
\author{}

\begin{document}

\maketitle

 \begin{abstract}
 abc
\end{abstract}

\section{table}
\begin{table}[h!]
\caption{Top 5 movies recommended by content-based CF algorithm} %title of the table
\centering
% centering table
\begin{tabular}{c r}
% creating eight columns
\hline\hline
%inserting double-line
Movies&\multicolumn{1}{c}{Genre} \\ [0.5ex]
\hline
% inserts single-line
The Flintstones(1994)
& Children's,Comedy\\
% Entering row contents
Son in Law(1974) & Comedy, Horror\\
The Princess Bride(1987) & Action, Adventure, Comedy, Romance\\
Star Wars(1977) & Action, Adventure, Romance, Sci-Fi, War\\
Toy Story(1995)
& Animated, Animated Children's, Comedy\\[1ex] % [1ex] adds vertical space
\hline
% inserts single-line
\end{tabular}
\label{tab:hresult}
\end{table}
 \end{document}


 This is how it looks : 

在此处输入图片描述

答案1

由于您使用双列模式,因此您应该使用 atable*而不是 atable环境。该table*环境跨越两列。限制是这些浮动元素只能出现在页面顶部。

在此处输入图片描述

顺便说一句,我建议您使用环境中包的命令\toprule\midrule和,而不是各种临时垂直间距命令。以下修改后的 MWE 形式显示了如何使用这些命令。\bottomrulebooktabstabular\hline

\documentclass[a4paper,10pt,twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,lipsum}
\begin{document}
\lipsum[1-5] % filler text
\begin{table*}
\caption{Top 5 movies recommended by content-based CF algorithm} \label{tab:hresult}
\centering
\begin{tabular}{@{}ll@{}}
\toprule
Movies & Genre \\ 
\midrule
The Flintstones (1994) & Children's, Comedy\\
Son in Law (1974) & Comedy, Horror\\
The Princess Bride (1987) & Action, Adventure, Comedy, Romance\\
Star Wars (1977) & Action, Adventure, Romance, Sci-Fi, War\\
Toy Story (1995) & Animated, Animated Children's, Comedy\\
\bottomrule
\end{tabular}
\end{table*}
\lipsum[6-14] % more filler text
\end{document}

答案2

这里为您的餐桌提供了多种不同的选择:

  1. 您原来的表格是\centering
  2. 使用\noindent(将其与左边距对齐),并且其列规范{@{}c r@{}}删除第一列之前和最后一列之后的列填充。
  3. 用 删除所有列间距{@{}c@{}r@{}},只是为了查看效果(可能不是一个好主意)。
  4. 使用{@{}c P{1.5in}@{}}它按照 2 删除列间距,但也使用p第二列的列类型以允许段落换行。

在此处输入图片描述

笔记:

代码:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{showframe}

\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}<{}}%


\newcommand*{\MyTabular}[1]{%
\begin{tabular}{#1}
% creating eight columns
\hline\hline
%inserting double-line
Movies&\multicolumn{1}{c}{Genre} \\ [0.5ex]
\hline
% inserts single-line
The Flintstones(1994)
& Children's, Comedy\\
% Entering row contents
Son in Law(1974) & Comedy, Horror\\
The Princess Bride(1987) & Action, Adventure, Comedy, Romance\\
Star Wars(1977) & Action, Adventure, Romance, Sci-Fi, War\\
Toy Story(1995)
& Animated, Animated Children's, Comedy\\[1ex] % [1ex] adds vertical space
\hline % inserts single-line
\end{tabular}
}%

\begin{document}

\begin{table}[h!]% Keep effect of \centering localized
\centering 
\MyTabular{c r}
\end{table}


\begin{table}[h!]
\noindent % 
\MyTabular{@{}c r@{}}
\end{table}

\begin{table}[h!]
\noindent % 
\MyTabular{@{}c@{}r@{}}
\end{table}

\begin{table}[h!]
\noindent % 
\MyTabular{@{}c P{1.5in}@{}}
\end{table}
\end{document}

相关内容