2011-05-12 8 views
8

bloku kodu poniżejAutomagicznie generowania notebooki z odcinków zwiniętych

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

utworzy notatnik szkielet.

Czy można utworzyć ten notatnik, aby sekcje zostały zwinięte? Aby notebook był wyświetlany tak, jakby (np.) Kliknięto sekcję 1 z przykrywaniem komórki. Ditto dla sekcji 2 & 3.

Odpowiedz

11

Zastosowanie CellGroup na otwieranie i zamykanie poszczególnych komórek - patrz 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"]}] 

Albo można owinąć całą kolekcję TextCells w jednym CellGroup wysokim poziomie i grać z CellGroup opcjonalnym sekundę argument. Na przykład otworzy to tylko pierwsze trzy grupy komórek:

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

Dzięki @Bill White! Pierwszy przykład był po prostu tym, za czym byłem. – dwa

+1

I dziękuję za zaakceptowanie mojej odpowiedzi. Nawiasem mówiąc, użycie drugiego argumentu Closed as CellGroup wydaje się być nieudokumentowane, chyba że coś przeoczyłem. Używam CellGroupData [{...}, Closed] przez cały czas podczas programowego generowania notatników, a Closed również działa tutaj dobrze. –

Powiązane problemy