2011-05-12 10 views
8

Il blocco di codice sottoAutomagicamente generando notebook con sezioni collassate

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

creerà un notebook scheletro.

È possibile creare quel blocco in modo che le sezioni siano compresse? In modo che il notebook venga visualizzato come se (ad esempio) la cella più vicina che copre la sezione 1 fosse stata cliccata. Idem per le sezioni 2 & 3.

risposta

11

Usa CellGroup per aprire o chiudere cellule specifiche - vedi 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"]}] 

Oppure si potrebbe avvolgere l'intera collezione di TextCells in una CellGroup di alto livello e giocare con la seconda opzione di CellGroup discussione. Ad esempio, si apriranno solo i primi tre gruppi di celle:

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

Grazie a @Bill White! Il primo esempio era proprio quello che stavo cercando. – dwa

+1

E grazie per aver accettato la mia risposta. A proposito, usare il secondo argomento di Closed as CellGroup sembra non documentato, a meno che non trascuri qualcosa. Io uso CellGroupData [{...}, Closed] sempre durante la generazione di notebook a livello di codice, e Closed sembra funzionare bene anche qui. –

Problemi correlati