【问题标题】:Automagically generating notebooks with collapsed sections自动生成带有折叠部分的笔记本
【发布时间】:2011-05-12 02:32:21
【问题描述】:

下面的代码块

CreateDocument[{
  TextCell["Title", "Title"],
  TextCell["Subtitle", "Subtitle"],
  TextCell["Section 1", "Section"],
  TextCell["Section 1.1", "Subsection"],
  TextCell["Section 1.2", "Subsection"],
  TextCell["Section 1.3", "Subsection"],
  TextCell["Section 2", "Section"],
  TextCell["Section 2.1", "Subsection"],
  TextCell["Section 2.2", "Subsection"],
  TextCell["Section 2.3", "Subsection"],
  TextCell["Section 3", "Section"],
  TextCell["Section 2.1", "Subsection"],
  TextCell["Section 2.2", "Subsection"],
  TextCell["Section 2.3", "Subsection"]}
 ]

将创建一个骨架笔记本。

是否可以创建该笔记本以折叠部分?这样笔记本将显示为好像(例如)已单击覆盖第 1 部分的单元格关闭器。第 2 节和第 3 节同上。

【问题讨论】:

    标签: wolfram-mathematica creation


    【解决方案1】:

    使用 CellGroup 打开或关闭特定单元格 - 请参阅 http://reference.wolfram.com/mathematica/ref/CellGroup.html

    CreateDocument[{
      TextCell["Title", "Title"],
      TextCell["Subtitle", "Subtitle"],
      CellGroup[{
        TextCell["Section 1", "Section"],
        TextCell["Section 1.1", "Subsection"], 
        TextCell["Section 1.2", "Subsection"], 
        TextCell["Section 1.3", "Subsection"]
      }, Closed],
      TextCell["Section 2", "Section"],
      TextCell["Section 2.1", "Subsection"], 
      TextCell["Section 2.2", "Subsection"], 
      TextCell["Section 2.3", "Subsection"],
      TextCell["Section 3", "Section"],
      TextCell["Section 2.1", "Subsection"], 
      TextCell["Section 2.2", "Subsection"], 
      TextCell["Section 2.3", "Subsection"]}]
    

    或者您可以将整个 TextCell 集合包装在一个高级 CellGroup 中,并使用 CellGroup 的可选第二个参数。例如,这将只打开前三个单元组:

    CreateDocument[{
      CellGroup[{
        TextCell["Title", "Title"],
        TextCell["Subtitle", "Subtitle"],
        TextCell["Section 1", "Section"],
        TextCell["Section 1.1", "Subsection"], 
        TextCell["Section 1.2", "Subsection"], 
        TextCell["Section 1.3", "Subsection"],
        TextCell["Section 2", "Section"],
        TextCell["Section 2.1", "Subsection"], 
        TextCell["Section 2.2", "Subsection"], 
        TextCell["Section 2.3", "Subsection"],
        TextCell["Section 3", "Section"],
        TextCell["Section 2.1", "Subsection"], 
        TextCell["Section 2.2", "Subsection"], 
        TextCell["Section 2.3", "Subsection"]
      }, {1, 2, 3}]
    }]
    

    【讨论】:

    • 感谢@Bill White!第一个例子正是我所追求的。
    • 感谢您接受我的回答。顺便说一句,使用 Closed 作为 CellGroup 的第二个参数似乎没有记录,除非我忽略了一些东西。在以编程方式生成笔记本时,我一直使用 CellGroupData[{...}, Closed],并且 Closed 在这里似乎也可以正常工作。
    猜你喜欢
    • 2014-12-25
    • 2016-01-14
    • 2016-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 2019-06-07
    相关资源
    最近更新 更多