2011-05-12 20 views
8

El bloque de código de abajoautomágicamente generar cuadernos con secciones colapsadas

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

creará un cuaderno esqueleto.

¿Es posible crear ese cuaderno para que las secciones se colapsen? Para que el cuaderno se muestre como si (p. Ej.) Se hubiera hecho clic en la tapa de la celda que cubre la sección 1. Lo mismo ocurre con las Secciones 2 & 3.

Respuesta

11

Uso CellGroup para abrir o células específicas cercanos - ver 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"]}] 

O usted podría envolver toda la colección de TextCells en una CellGroup alto nivel y jugar con el segundo opcional de CellGroup argumento. Por ejemplo, esto abrirá solo los primeros tres grupos de celdas:

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}] 
}] 
+0

¡Gracias @Bill White! El primer ejemplo fue justo lo que buscaba. – dwa

+1

Y gracias por aceptar mi respuesta. Por cierto, usar Closed como el segundo argumento de CellGroup parece estar indocumentado, a menos que esté pasando por alto algo. Yo uso CellGroupData [{...}, Closed] todo el tiempo cuando genero cuadernos programáticamente, y Closed parece funcionar bien aquí, también. –

Cuestiones relacionadas