我们使用文档类生成多列文档scrartcl
。
以下面的数据为例,我们可以看到当我们使用命令\begin{table}[h]
时没有桌子在部分中生成multicols
。如果我们使用该\begin{centering}
命令,则会生成一个表,但是他没有\caption{}
等。
然而,当我们处于单列特征(在数据末尾)时,我们看到的\begin{table}[h]
行为符合预期。有人知道如何将其集成到多列环境中吗?
\documentclass[10pt,a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage[colaction]{multicol}
\usepackage{hyperref}
\usepackage{lineno}
\usepackage{setspace}
\usepackage{lipsum}
\title{Table formatting}
\author{The geniuses at SE}
\begin{document}
\maketitle
\doublespacing
\begin{abstract}
\lipsum[1-1]
\end{abstract}
\begin{multicols}{2}
\section{Introduction}
\lipsum[1-2]
\begin{table}[h]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{lllll}
& \multicolumn{2}{l}{XYZ} & \multicolumn{2}{l}{ABC} \\
& Sex & P & Sex & P \\
AGE1 & 0.5 & 1 & 0.6 & 1 \\
& & & &
\end{tabular}
\end{table}
\lipsum[1-1]
\begin{centering}
\begin{tabular}{lllll}
& \multicolumn{2}{l}{XYZ} & \multicolumn{2}{l}{ABC} \\
& Sex & P & Sex & P \\
AGE1 & 0.5 & 1 & 0.6 & 1 \\
& & & &
\end{tabular}
\end{centering}
\lipsum[1-1]
\end{multicols}
\bigskip
\lipsum[1-1]
\begin{table}[h]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{lllll}
& \multicolumn{2}{l}{XYZ} & \multicolumn{2}{l}{ABC} \\
& Sex & P & Sex & P \\
AGE1 & 0.5 & 1 & 0.6 & 1 \\
& & & &
\end{tabular}
\end{table}
\lipsum[1-1]
\end{document}
答案1
请记住,它multicol
不支持浮点数。解决方案似乎是这样的:
\begin{centering}
\begin{tabular}{lllll}
& \multicolumn{2}{l}{XYZ} & \multicolumn{2}{l}{ABC} \\
& Sex & P & Sex & P \\
AGE1 & 0.5 & 1 & 0.6 & 1 \\
& & & &
\end{tabular}
\captionof{table}{My important table}% <--- for table caption
\end{centering}
编辑:要在表格上方添加标题enter code here
,您需要将标题移到表格前面:
\begin{center}% not centering as you use in your example and I overtake from your MWE
\captionof{table}{My important table}% <--- for table caption
\begin{tabular}{lllll}
& \multicolumn{2}{l}{XYZ} & \multicolumn{2}{l}{ABC} \\
& Sex & P & Sex & P \\
AGE1 & 0.5 & 1 & 0.6 & 1 \\
& & & &
\end{tabular}
\end{center}
答案2
注意这\centering
是一个命令,不是环境。请使用center
环境。
KOMA-Script 定义了用于浮动图形或表格等的\captionof
命令。\captionaboveof
\captionbelowof
我建议使用来minipage
确保标题和表格之间没有分栏符或分页符。
\begin{center}% insert some space before and after the table
\begin{minipage}{\columnwidth}% ensure that there is no page or column break
\centering% center the table
\captionaboveof{table}{My caption}
\label{my-label}
\begin{tabular}{lllll}
& \multicolumn{2}{l}{XYZ} & \multicolumn{2}{l}{ABC} \\
& Sex & P & Sex & P \\
AGE1 & 0.5 & 1 & 0.6 & 1 \\
& & & &
\end{tabular}
\end{minipage}
\end{center}
代码:
\documentclass[10pt,a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{booktabs}
\usepackage[colaction]{multicol}
\usepackage{lineno}
\usepackage{setspace}
\usepackage{lipsum}
\title{Table formatting}
\author{The geniuses at SE}
\begin{document}
\maketitle
\doublespacing
\begin{abstract}
\lipsum[1-2]
\end{abstract}
\begin{multicols}{2}
\section{Introduction}
\lipsum[1]
\begin{center}% insert some space before and after the table
\begin{minipage}{\columnwidth}% ensure that there is no page or column break
\centering% center the table
\captionaboveof{table}{My caption}
\label{my-label}
\begin{tabular}{lllll}
& \multicolumn{2}{l}{XYZ} & \multicolumn{2}{l}{ABC} \\
& Sex & P & Sex & P \\
AGE1 & 0.5 & 1 & 0.6 & 1 \\
& & & &
\end{tabular}
\end{minipage}
\end{center}
\lipsum[1-2]
\begin{center}
\begin{minipage}{\columnwidth}
\centering
\captionaboveof{table}{My caption}
\label{my-label}
\begin{tabular}{lllll}
& \multicolumn{2}{l}{XYZ} & \multicolumn{2}{l}{ABC} \\
& Sex & P & Sex & P \\
AGE1 & 0.5 & 1 & 0.6 & 1 \\
& & & &
\end{tabular}
\end{minipage}
\end{center}
\lipsum[1]
\end{multicols}
\lipsum[1]
\end{document}
如果删除minipage
上面例子中的第一个,您将看到标题和表格之间可能存在中断。