在固定大小页面(多列)上布局目录的算法
我正在将目录写入标准 8.5 英寸 x 11 英寸页面。方向(横向与纵向)是一个变量。当 x 英寸边距应用于页面时(其中 x 是可变的),我可以将目录写入内部区域。
原始数据是一个包含两列的表格:主题和页面(即 { "Animals" , 1 } , { "Big Plants" , 2 } , { "Small Plants" , 2 } )。这不是嵌套目录 - 没有“子主题”。所有主题都具有相同的重要性级别,并且所有文本的字体大小都是固定的。
我希望每页允许 1 列或多列目录,并且如果需要,我允许多页目录。布局完全取决于主题栏中的文本。如果主题很短,您可以想象将 2 列纵向放置,或将 3 列横向放置。如果主题名称很长,那么可能只适合 1 列(如果很长,那么可以为一个主题使用多行)。如果主题很多,那么我可能会扩展到多个页面。目标是在每个页面上放置尽可能多的目录信息。
我意识到这是一个难题。有许多细节我还没有探索过(即所有页面都必须具有相同的列数吗?)。我只是在寻找一个开始......一些足够简单的东西,可以在一两个小时内完成这项工作。任何半智能的东西都比强制使用带有字符计数的 1 列 TOC 来确定页面上放置多少行要好。
I'm writing a table of contents to a standard 8.5in x 11in page. Orientation (landscape versus portrait) is a variable. I can write my TOC to an inner region when x-inch margins are applied to the page (where x is variable).
The raw data is a table with two columns: Topic and Page (i.e. { "Animals" , 1 } , { "Big Plants" , 2 } , { "Small Plants" , 2 } ). This is not a nested TOC - there are no "subtopics". All topics are at the same level of importance and font size is fixed for all text.
I want to allow for 1 or more columns of TOC per page and I'm allowing multiple pages of TOC if needed. The layout is completely dependent on text in the Topic column. If the topics are short, you can imagine putting 2 columns in portrait orientation, or 3 columns in landscape orentation. If there are long topic names, then maybe only 1 column will fit (if very long, then its ok to use multiple lines for a topic). If there are many topics, then I might spill over to multiple pages. The goal is to put as much TOC info as possible on each page.
I realize this is a hard problem. There's a number of details that I haven't explored (i.e. do all pages have to have the same number of columns?). I'm just looking for a start...something simple enough to implement in an hour or two that does the job. Anything semi-intelligent is better than forcing a 1-column TOC with character counts to determine how many rows to place on a page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要一些变量:
然后就很容易计算了。
仅供参考:Floor( ) 表示向下舍入到最接近的整数。楼层(5.9) = 5, 楼层(0.1) = 0
First you need a few variables:
Then it's pretty easy to calculated.
FYI: Floor( ) means round down to the nearest integer. Floor(5.9) = 5, Floor(0.1) = 0
假设您希望所有列的宽度相同:
数学稍微复杂一些,因为您需要考虑列之间的“排水沟”。通过填充最宽的值可以轻松实现这一点。
Assuming you want all columns to be the same width:
The math is slightly more complicated, since you need to account for a "gutter" between the columns. This is easily accomplished by padding your widest value.