How can I add bulleted list in Matlab annotation textbox

6 views (last 30 days)
I am trying to add a bulleted list in a Matlab annotation textbox. I've tried using LaTex commands but all I get is: Unable to interpret latex string, such as
str = '\begin{itemized} \item First Line \item Second Line \end{itemized}';
figure;
ha = annotation('textbox', [0.5 0.5 0.4 0.2], 'Interpreter', 'latex');
set(ha, 'String', str)
This is similar to the way you put a table in an annotated textbox:

Answers (1)

Nina
Nina on 14 Jul 2025
You can create bulleted lists in a textbox annotation by setting the string to be a cell array:
plot(1,1)
an = annotation('textbox', [0.40 0.40 0.20 0.15]);
an.Interpreter = 'latex';
an.String = {
["$\bullet$ \ First item"]
["$\bullet$ \ Second item"]
["$\bullet$ \ Third item"]
};
  2 Comments
Stephen23
Stephen23 on 16 Jul 2025
Edited: Stephen23 on 16 Jul 2025
Note that square brackets around scalar strings are completely superfluous:
["$\bullet$ \ First item"]
^ ^ !!! These do absolutely nothing !!!
The MATLAB documentation recommends to avoid storing scalar strings in a cell array: "When you have multiple strings, store them in a string array, not a cell array. Create a string array using square brackets, not curly braces. String arrays are more efficient than cell arrays for storing and manipulating text."
One much better approach is to simply use a string array:
plot(1,1)
an = annotation('textbox', [0.40,0.40,0.20,0.15]);
an.Interpreter = 'latex';
an.String = [...
"$\bullet$ \ First item",...
"$\bullet$ \ Second item",...
"$\bullet$ \ Third item"];
or at the time this question was asked, by using a cell array of character vectors.

Sign in to comment.

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!