如何解决 longtable 不是 1 列模式错误?

如何解决 longtable 不是 1 列模式错误?

我正在尝试使用 longtable 的示例代码编译文档,但出现错误,提示 longtable 不是单列模式。请告诉我正确的方法?

答案1

longtable与 配合使用效果不佳twocolumn。但您可以使用supertabular。以下是示例:

\documentclass[twocolumn]{article}
\usepackage{supertabular,booktabs}
\usepackage[textheight=10cm]{geometry}   %% just for this example.

\begin{document}

\tablefirsthead{\toprule First&\multicolumn{1}{c}{Name} \\ \midrule}
%
\tablehead{%
\multicolumn{2}{c}%
{{\bfseries  Continued from previous column}} \\
\toprule
First&\multicolumn{1}{c}{Name}\\ \midrule}
%
\tabletail{%
\midrule \multicolumn{2}{r}{{Continued on next column}} \\ \midrule}
\tablelasttail{%
\\\midrule
\multicolumn{2}{r}{{Concluded}} \\ \bottomrule}
\begin{supertabular}{ll}
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text comes\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text comes here too \\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text
\end{supertabular}%
\end{document}

在此处输入图片描述

正如 egreg 所建议的,xtab这是另一种选择。xtab建立supertabular在避免其弱点的基础上。

\documentclass[twocolumn]{article}
\usepackage{xtab,booktabs}
\usepackage[textheight=10cm]{geometry}   %% just for this example.

\begin{document}
\topcaption{This is top caption}
\bottomcaption{This is bottom caption}
\tablecaption{this is table caption}
\tablefirsthead{\toprule First&\multicolumn{1}{c}{Name} \\ \midrule}
%
\tablehead{%
\multicolumn{2}{c}%
{{\bfseries  Continued from previous column}} \\
\toprule
First&\multicolumn{1}{c}{Name}\\ \midrule}
%
\tabletail{%
\midrule \multicolumn{2}{r}{{Continued on next column}} \\ \midrule}
\tablelasttail{%
\\\midrule
\multicolumn{2}{r}{{Concluded}} \\ \bottomrule}
\begin{xtabular}{ll}
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text comes\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text comes here too \\
    content & some text\\
    content & some text\\
    content & some text\\
    content & some text
\end{xtabular}%
\end{document}

答案2

如果您仍然想坚持使用 longtable(例如因为您通过 pandoc 生成 LaTeX),您可以重新定义该\longtable命令。

一个可能的解决方案是这样的:

\makeatletter
\let\oldlt\longtable
\let\endoldlt\endlongtable
\def\longtable{\@ifnextchar[\longtable@i \longtable@ii}
\def\longtable@i[#1]{\begin{figure}[t]
\onecolumn
\begin{minipage}{0.5\textwidth}
\oldlt[#1]
}
\def\longtable@ii{\begin{figure}[t]
\onecolumn
\begin{minipage}{0.5\textwidth}
\oldlt
}
\def\endlongtable{\endoldlt
\end{minipage}
\twocolumn
\end{figure}}
\makeatother

注意::它适用于两列,这是您在期刊文章文档类别中经常会发现的。

要将此片段与 pandoc 一起使用,你可以使用-H 开关它允许您在实际内容之前添加一些附加代码。只需创建一个名为的文件preamble.tex并插入上述代码即可。然后您可以运行pandoc -H preamble.tex,代码将自动包含在内。

答案3

另一个选项(前面的答案中没有提到)是,在 longtable 之前强制使用单列模式\clearpage,然后在之后将其重置为双列模式。如下所示:

\clearpage
\onecolumn
\begin{longtable}
...
\end{longtable}
\clearpage
\twocolumn

这可能比前面的例子更有用,因为它不需要重建太多,并且还有在 arXiv 等平台上工作的额外好处。

答案4

我也尝试使用 pandoc 中的多列,类似于Marco Torchiano 的回答longtable在序言中重新定义了环境,但就我而言,我重新定义它是为了使用环境xtabular

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Redefine longtable because it doesn't work in multicolumn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter
\def\longtable{\@ifnextchar[\newlongtable@i \newlongtable@ii}
\def\newlongtable@i[#1]{%
\renewcommand{\endhead}{\ignorespaces}
\xtabular[#1]}
\def\newlongtable@ii{%
\renewcommand{\endhead}{\ignorespaces}
\xtabular}
\def\endlongtable{\endxtabular}
\makeatother

上面的代码不是最漂亮的,但是当我使用--include-in-header(或-H) 选项调用 pandoc 时似乎工作正常:

pandoc                                    \
  --standalone                            \
  --from=markdown                         \
  --template=pandoc-template.tex          \
  --include-in-header=pandoc-preamble.tex \
  --pdf-engine=xelatex                    \
  -o out.pdf                              \
  in.md

这可以生成包含双列布局表格的 pdf,显然没有问题。

相关内容