我正在尝试创建歌本文档类。每首歌曲都在自己的页面上。如果歌曲是常规大小(适合一页一列),我想实现歌曲页面为一列,但如果歌曲太长而无法适合一页一列,则歌曲页面为两列(所有这些都必须自动发生,无需歌本作者交互)。可以实现吗?如果可以,如何实现?
附言:请不要向我推荐其他歌曲集风格和类别,我已经搜索过但它们不能满足我的需求。
答案1
您可以先使用单列模式在里面排版歌曲\savebox
,然后测量最终的大小。如果太大,则再次以双列模式排版。据我所知,没有用于此目的的软件包,但这可以很容易地进行编程。您可以使用例如包来收集环境内容environ
。
environ
这里有一个使用和 的示例实现multicol
。请根据您的需要进行调整。我提供了两个带有虚拟文本的示例用法。
\documentclass{article}
\usepackage{environ}
\usepackage{multicol}
\newsavebox{\songbox}
\NewEnviron{song}{% can also have arguments
\clearpage
% Add song title, at as argument etc.
%
% The content is \BODY
% Let's save it in normal single column mode:
\savebox{\songbox}{%
\begin{minipage}{\linewidth}%
\BODY
\end{minipage}%
}%
% To high? (Replace \textheight if required)
% \ht = hight, \dp = depth, both together is the total height
\ifnum\dimexpr\ht\songbox+\dp\songbox > \textheight
% Typeset again in two column mode:
\begin{multicols}{2}%
\BODY
\end{multicols}%
\else
% Size is already OK, so use the content of the saved box:
\usebox{\songbox}%
\fi
}
\begin{document}
\begin{song}
A short song\\
La la la la la \\
A very short song indeed\\
But this is a very long line to demonstrate that we are still in single column mode. In fact it is so long that it will be broken into two lines.
\end{song}
\begin{song}
This is a long song\\
This is a long song\\
And this is a long line to show the two column mode.
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
\end{song}
\end{document}