有没有办法告诉multicol
在 cols > 1 的顶部留出空间?
主要的问题是表数据将被共享,我不想把它分成不同的地方,而是让编译器来解决它。
\documentclass{article}
\usepackage{multicol}
\usepackage{longtable}
\newsavebox\ltmcbox
\newcounter{entryno}
\setcounter{entryno}{1}
\begin{document}
\section*{I want this:}
\begin{multicols}{2}
\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
Data
& Data\\
{}
& {}\\
Data
& Data\\
Data
& Data\\
\end{longtable}
\unskip
\unpenalty
\unpenalty
}\unvbox\ltmcbox
\end{multicols}
\section*{Or this:}
\begin{multicols}{2}
\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
Data
& Data\\
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
\end{longtable}
\unskip
\unpenalty
\unpenalty
}\unvbox\ltmcbox
\end{multicols}
\section*{Not this:}
\begin{multicols}{2}
\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
Data
& Data\\
Data
& Data\\
Data
& Data\\
\end{longtable}
\unskip
\unpenalty
\unpenalty
}\unvbox\ltmcbox
\end{multicols}
\end{document}
答案1
利用 David Carlisle 的信息,我提出了以下环境和辅助命令。
这会不是在页面末尾很好地中断,但其行为类似于迷你页面。环境用于隐藏所有令人讨厌的内容,命令用于根据列的数量指定不同的平衡单元。
这是我的解决方法:
\documentclass{article}
\usepackage{multicol}
\usepackage{longtable}
%-------------------
% Workaround for multicols containing tables
%
% Sets \myMultiCols to \col@number
% and \col@number to 1
%-------------------
\makeatletter
\newsavebox\mtcbox
\newenvironment{myTableCols}[1]{%
\begin{multicols}{#1}%
\setbox\mtcbox\vbox\bgroup%
\edef\myMultiCols{\the\col@number}%
\col@number\@ne%
}{%
\unskip%
\unpenalty%
\unpenalty\egroup%
\unvbox\mtcbox%
\end{multicols}%
\vspace*{-.35\baselineskip}% TODO check if needed
}
\makeatother
% This fixes the horrendous layout for
\newcommand{\myBalanceColIfColums}[1]{%
\ifdefined\myMultiCols\ifnum\myMultiCols=#1%
\\%
\fi\fi%
}
\begin{document}
\begin{myTableCols}{2}
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
\myBalanceColIfColums{3}
Data
& Data\\
\myBalanceColIfColums{2}
Data
& Data\\
\myBalanceColIfColums{3}
Data
& Data\\
\end{longtable}
\end{myTableCols}
\begin{myTableCols}{3}
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
\myBalanceColIfColums{3}
Data
& Data\\
\myBalanceColIfColums{2}
Data
& Data\\
\myBalanceColIfColums{3}
Data
& Data\\
\end{longtable}
\end{myTableCols}
\end{document}