长桌尺寸未显示

长桌尺寸未显示

我已加载以下软件包:

\usepackage[]{multirow}
\usepackage{longtable}
\usepackage{csquotes}
\usepackage{tabulary}
\usepackage{array}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\usepackage{booktabs,dcolumn,caption}
\captionsetup{labelsep=newline,singlelinecheck=false} % optional
\newcolumntype{d}[1]{D{.}{.}{#1}} % "decimal" column type
\renewcommand{\ast}{{}^{\textstyle *}} % for raised "asterisks"

我的文档中有:

\begin{table}[!ht]
\centering
\begin{longtable}{|L|c|L|}\hline
\textbf{Example Sentence} & \textbf{Category} & \textbf{Explanation}
\\\hline
\multicolumn{1}{|m{3cm}|}{We send the EU £350m a week}
 & \multicolumn{1}{|m{3cm}|}{Use a real number, but change its meaning to be in the wrong context
}&  \multicolumn{1}{m{3cm}|}{This is a true National Statistic but it “is not an amount of money that the UK pays to the EU”. In fact, the UK’s net contribution is more like £250m a week which equates to £136m. }
\\\hline
\multicolumn{1}{|m{3cm}|}{Potential cost of leaving the EU as £4,300 per household per year, rather than as the equivalent £120bn for the whole country}
 & \multicolumn{1}{|m{3cm}|}{Make the number look big (but not too big)}&  \multicolumn{1}{m{3cm}|}{Insert text}
\\\hline
\end{longtable}
\end{table}

改编自此来源

我有几个问题:

表格前两行

  1. 目前,所有内容都是居中对齐的,因此文本包含太多空格,而不是左对齐且紧密
  2. 我想让整个表格自动换行。目前,我将每列的所有内容限制为 3cm,但实际上我想将整个表格限制为页面的最大宽度(如果这是某个地方的变量?)并自动换行。
  3. 我的表格并没有像我想象的那样溢出页面longtable。如果我删除table长表格中的换行符,我无法指定[!ht]我的表格是否会出现在页面的某个随机位置。

我该如何解决这个问题?

答案1

让我们来检验一下你的说法:

目前,所有内容都是居中对齐的,因此文本包含太多空格,而不是左对齐且紧密

这种说法是不正确的。您确实指定了L列类型(您已将其定义为居中设置其内容),但随后您通过\multicolumn{1}{|m{3cm}|}{...}包装器覆盖了此设置。m列类型完全对齐其内容。您在屏幕截图中看到的不是居中文本,而是完全对齐的文本,其中许多单词之间有较大的“空洞”。

要获得不规则的格式,可以使用

\multicolumn{1}{|>{\raggedright\arraybackslash}m{3cm}|}{...}

包装器或者完全删除包装器并在列类型的定义中\centering替换。\raggedrightL

...我想限制整个表格的最大宽度为页面的宽度(如果这是某个地方的变量?)并且自动换行

你看过文本表环境?请与环境结合使用longtable

我的表格没有像我以为的 longtable 那样溢出页面。如果我删除 longtable 中的表格换行符,则无法指定 [!ht],因此我的表格将出现在页面的某个随机部分。

longtable浮动环境的前提是错误的。事实并非如此。为什么[ht!]在应用于 a 时没有效果的原因longtable是 alongtable总是从输入流中遇到的位置开始。因此:绝不将 a 包裹longtable在 a 里面table。永远、永远。无论如何都不可能。


以下是我重新编写代码的方法。请注意,我重新组织了内部材料,longtable以便更清楚地区分表头、表脚和表体。我还删除了所有垂直线。

\documentclass{article}
\usepackage{longtable,array,ragged2e}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}p{3.75cm}}
\usepackage{booktabs,caption}
\captionsetup{labelsep=newline,singlelinecheck=false}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[british]{babel}
\begin{document}
\begin{longtable}{@{}LLL@{}}
\toprule
\textbf{Example Sentence} & \textbf{Category} & \textbf{Explanation}\\
\midrule
\endhead
\bottomrule
\endlastfoot
We send the EU £350m a week & 
Use a real number, but change its meaning to be in the wrong context&  
This is a true National Statistic but it ``is not an amount of money that the UK pays to the EU''. In fact, the UK's net contribution is more like £250m a week which equates to £136m.\\
\midrule
Potential cost of leaving the EU as £4,300 per household per year, rather than as the equivalent £120bn for the whole country & 
Make the number look big (but not too big)&  
Insert text\\
\end{longtable}
\end{document}

在此处输入图片描述

答案2

longtable不是一个浮点数,因此你不能使用该table环境。

我提出了两种解决方案,基于, 将ltablex的功能引入。一种解决方案使用垂直和水平线,另一种解决方案使用 的规则,没有垂直线:longtabletabularxbooktabs

\documentclass{article}
\usepackage[utf8]{inputenc} %
\usepackage[T1]{fontenc} %
\usepackage{geometry}%
 \usepackage{array,ltablex, makecell}%
\renewcommand\theadfont{\normalsize\bfseries}
\setcellgapes{4pt}
\usepackage{multirow}
\usepackage{csquotes}
\usepackage{tabulary}
\usepackage{ragged2e} \usepackage{array}
\usepackage{booktabs,dcolumn,caption}
\captionsetup{labelsep=newline,singlelinecheck=false} % optional
\newcolumntype{d}[1]{D{.}{.}{#1}} % "decimal" column type
\renewcommand{\ast}{{}^{\textstyle *}} % for raised "asterisks"

\usepackage{showframe} \renewcommand\ShowFrameLinethickness{0.2pt}

\begin{document}


\centering\keepXColumns
\makegapedcells
\begin{tabularx}{\linewidth}{|*{3}{ >{\RaggedRight\arraybackslash}X|}}%
\hline %
 \thead{Example Sentence} & \thead{Category} & \thead{Explanation} \\%
\hline
We send the EU £\,350\,m a week
 & Use a real number, but change its meaning to be in the wrong context
& This is a true National Statistic but it “is not an amount of money that the UK pays to the EU”. In fact, the UK’s net contribution is more like £\,250\,m a week which equates to £\,136\,m. \\%
\hline
Potential cost of leaving the EU as £\,4,300 per household per year, rather than as the equivalent £\,120\,bn for the whole country & Make the number look big (but not too big) & Insert text \\%
\hline
\end{tabularx}%
\vskip1cm

\begin{tabularx}{\linewidth}{*{3}{ >{\RaggedRight\arraybackslash}X}}%
\toprule %
 \thead{Example Sentence} & \thead{Category} & \thead{Explanation} \\%
\midrule
We send the EU £\,350\,m a week
 & Use a real number, but change its meaning to be in the wrong context
& This is a true National Statistic but it “is not an amount of money that the UK pays to the EU”. In fact, the UK’s net contribution is more like £\,250\,m a week which equates to £\,136\,m. \\%
\addlinespace
Potential cost of leaving the EU as £\,4,300 per household per year, rather than as the equivalent £\,120\,bn for the whole country & Make the number look big (but not too big) & Insert text \\%
\bottomrule
\end{tabularx}

\end{document} 

在此处输入图片描述

相关内容