自动生成具有折叠部分的笔记本

时间:2011-05-12 02:32:21

标签: wolfram-mathematica creation

下面的代码块

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"]}
 ]

将创建一个骨架笔记本。

是否可以创建该笔记本以便折叠部分?因此,笔记本将显示为好像(例如)单击Cell 1更接近第1部分。同样适用于第2节和第2节3。

1 个答案:

答案 0 :(得分:11)

使用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}]
}]