我正在尝试编写一个文档,该文档需要在我的文档的一个部分中放入许多小表格(其中包含其他嵌套表格),我想将其放入一个两列部分。我使用tabu
来获取表格,并multicol
只为文档的一部分获取两列格式。当我不使用 时multicol
,我特意为我的表格选择一个大小tabu
,使它们彼此很好地对齐。然而,一旦我引入multicol
,事情就开始变得......奇怪。
总而言之,我从这个开始,并且有效:
\documentclass[10pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{array,booktabs,tabu}
Some initial text goes here, that should not be in two-column format.
\begin{tabu} to 0.45/linewidth {X}
\toprule
\centering {\bf A table heading}\\
\midrule
\begin{tabular}{lp{6.2cm}}
{\bf Text} & More text\\
& Other text.\\
& Yet more text.\\
\end{tabular}\\
\begin{tabular}{lp{1.6cm}p{3.8cm}}
{\bf Text} & More complicated & table.\\
& More & complexity.\\
\end{tabular}\\
\end{tabu}
\begin{tabu} to 0.45/linewidth {X}
\toprule
\centering {\bf Another table heading}\\
\midrule
\begin{tabular}{lp{6.2cm}}
{\bf Text} & More text\\
& Other text.\\
& Yet more text.\\
\end{tabular}\\
\begin{tabular}{lp{1.6cm}p{3.8cm}}
{\bf Text} & More complicated & table.\\
& More & complexity.\\
\end{tabular}\\
\end{tabu}
\end{document}
然后,我尝试将这两个tabu
表包装multicols
如下:
\documentclass[10pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{array,booktabs,tabu,multicol}
Some initial text goes here, that should not be in two-column format.
\begin{multicols}{2}
\begin{tabu} to 0.45/linewidth {X}
\toprule
\centering {\bf A table heading}\\
\midrule
\begin{tabular}{lp{6.2cm}}
{\bf Text} & More text\\
& Other text.\\
& Yet more text.\\
\end{tabular}\\
\begin{tabular}{lp{1.6cm}p{3.8cm}}
{\bf Text} & More complicated & table.\\
& More & complexity.\\
\end{tabular}\\
\end{tabu}
\begin{tabu} to 0.45/linewidth {X}
\toprule
\centering {\bf Another table heading}\\
\midrule
\begin{tabular}{lp{6.2cm}}
{\bf Text} & More text\\
& Other text.\\
& Yet more text.\\
\end{tabular}\\
\begin{tabular}{lp{1.6cm}p{3.8cm}}
{\bf Text} & More complicated & table.\\
& More & complexity.\\
\end{tabular}\\
\end{tabu}
\end{multicols}
\end{document}
但是,这导致格式严重损坏且难以阅读。然后我尝试返回并包装每个tabu' in a
表的环境,如下所示:
\documentclass[10pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{array,booktabs,tabu,multicol}
Some initial text goes here, that should not be in two-column format.
\begin{multicols}{2}
\begin{table}[!h]
\begin{tabu} to 0.45/linewidth {X}
\toprule
\centering {\bf A table heading}\\
\midrule
\begin{tabular}{lp{6.2cm}}
{\bf Text} & More text\\
& Other text.\\
& Yet more text.\\
\end{tabular}\\
\begin{tabular}{lp{1.6cm}p{3.8cm}}
{\bf Text} & More complicated & table.\\
& More & complexity.\\
\end{tabular}\\
\end{tabu}
\end{table}
\begin{table}
\begin{tabu} to 0.45/linewidth {X}
\toprule
\centering {\bf Another table heading}\\
\midrule
\begin{tabular}{lp{6.2cm}}
{\bf Text} & More text\\
& Other text.\\
& Yet more text.\\
\end{tabular}\\
\begin{tabular}{lp{1.6cm}p{3.8cm}}
{\bf Text} & More complicated & table.\\
& More & complexity.\\
\end{tabular}\\
\end{tabu}
\end{table}
\end{multicols}
\end{document}
然而,当我这样做的时候那,我最终得到了两张桌子消失,而只是在它们的位置上有一个空白页。我做错了什么,我怎样才能让所有这些组件彼此很好地协作?
答案1
如果使用\begin{multicols}{2}
,则\linewidth
不是全文行宽,而是列的行宽。因此0.45\linewidth
小于当前列宽的一半。
因此,该示例使用.9\linewidth
表格并将其水平居中在列内:
\documentclass[10pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{array,booktabs,tabu,multicol}
\usepackage{lipsum}
\begin{document}
Some initial text goes here, that should not be in two-column format.
\lipsum[2]
\begin{multicols}{2}
\centering
\begin{tabu} to .9\linewidth {X}
\toprule
\centering {\bf A table heading}\\
\midrule
\begin{tabular}{lp{6.2cm}}
{\bf Text} & More text\\
& Other text.\\
& Yet more text.\\
\end{tabular}\\
\begin{tabular}{lp{1.6cm}p{3.8cm}}
{\bf Text} & More complicated & table.\\
& More & complexity.\\
\end{tabular}\\
\end{tabu}
\begin{tabu} to .9\linewidth {X}
\toprule
\centering {\bf Another table heading}\\
\midrule
\begin{tabular}{lp{6.2cm}}
{\bf Text} & More text\\
& Other text.\\
& Yet more text.\\
\end{tabular}\\
\begin{tabular}{lp{1.6cm}p{3.8cm}}
{\bf Text} & More complicated & table.\\
& More & complexity.\\
\end{tabular}\\
\end{tabu}
\end{multicols}
\lipsum[2]
\end{document}