3
$\begingroup$

I'm writing code that generates a report notebook using a defined style. I would like to display an image (a logo) in the title cell along with the title itself. How can this be done?

Example:

CreateDocument[
{
TextCell["Results Summary", "Title"],
TextCell["Some test", "Text"],
TextCell["This is a test", "Subtitle"],
TextCell["First section", "Section"]
},
StyleDefinitions -> Notebook@
 {
 Cell[StyleData[StyleDefinitions -> "Default.nb"]],
 Cell[StyleData["Title"], FontColor -> Blue, 
  CellDingbat -> {Cell[GraphicsData[img]]}],
 Cell[StyleData["Section"], FontColor -> Green, 
  CellDingbat -> {Cell[TextData[{CounterBox["Section"]}]]}],
 Cell[StyleData["Subsection"], FontColor -> Red, 
  CellDingbat -> {Cell[
     TextData[{CounterBox["Section"], ".", 
       CounterBox["Subsection"]}]]
    }
  ]
 }
];
$\endgroup$
4
$\begingroup$

Try creating the Cell expression using ToBoxes. First an example image:

image = Thumbnail[
    ExampleData[{"TestImage", "Lena"}],
    30
]

enter image description here

Then, use BoxData @ ToBoxes @ image to create the cell:

CreateDocument[
    {
    TextCell["Results Summary", "Title"],
    TextCell["Some test", "Text"],
    TextCell["This is a test", "Subtitle"],
    TextCell["First section", "Section"]
    },
    StyleDefinitions -> Notebook@
        {
        Cell[StyleData[StyleDefinitions -> "Default.nb"]],
        Cell[StyleData["Title"],
            FontColor -> Blue, 
            CellDingbat -> {Cell[BoxData @ ToBoxes @ image]}
        ],
        Cell[StyleData["Section"],
            FontColor -> Green, 
            CellDingbat -> {Cell[TextData[{CounterBox["Section"]}]]}
        ],
        Cell[StyleData["Subsection"],
            FontColor -> Red, 
            CellDingbat -> 
            {
            Cell[TextData[{CounterBox["Section"], ".", CounterBox["Subsection"]}]]
            }
        ]
        }
];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.