Main Content

Style Properties

Style for table or tree UI component

Since R2019b

Use Style objects to create visual styles for cells in table UI components or nodes in tree UI components. The component must be one that is parented to a figure created with the uifigure function, or to one of its child containers. You can create a Style object using the uistyle function, specify its properties, and then apply it to the component using the addStyle function. You can remove styles from a component using the removeStyle function.

Style objects that you add to a UI component take visual precedence over properties you set on the component object, no matter the order in which you created them. For example, in this code the blue font color displays in the table even though red foreground color was set on the Table object last.

uit = uitable(uifigure,'Data',rand(100,10)); 

s = uistyle; 
s.FontColor = 'blue'; 
addStyle(uit,s); 

uit.ForegroundColor = 'red';
Table UI component with blue font color

Color

expand all

Background color, specified as an RGB triplet, a hexadecimal color code, or one of the color options listed in the table.

RGB triplets and hexadecimal color codes are useful for specifying custom colors.

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7].

  • A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Thus, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Sample of the color red

"green""g"[0 1 0]"#00FF00"

Sample of the color green

"blue""b"[0 0 1]"#0000FF"

Sample of the color blue

"cyan" "c"[0 1 1]"#00FFFF"

Sample of the color cyan

"magenta""m"[1 0 1]"#FF00FF"

Sample of the color magenta

"yellow""y"[1 1 0]"#FFFF00"

Sample of the color yellow

"black""k"[0 0 0]"#000000"

Sample of the color black

"white""w"[1 1 1]"#FFFFFF"

Sample of the color white

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Font color, specified as an RGB triplet, a hexadecimal color code, or one of the options listed in the table.

RGB triplets and hexadecimal color codes are useful for specifying custom colors.

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7].

  • A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Thus, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Sample of the color red

"green""g"[0 1 0]"#00FF00"

Sample of the color green

"blue""b"[0 0 1]"#0000FF"

Sample of the color blue

"cyan" "c"[0 1 1]"#00FFFF"

Sample of the color cyan

"magenta""m"[1 0 1]"#FF00FF"

Sample of the color magenta

"yellow""y"[1 1 0]"#FFFF00"

Sample of the color yellow

"black""k"[0 0 0]"#000000"

Sample of the color black

"white""w"[1 1 1]"#FFFFFF"

Sample of the color white

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Text

expand all

Font name, specified as a system-supported font name. The default font depends on the specific operating system and locale.

If the specified font is not available, then MATLAB uses the best match among the fonts available on the system where the app is running.

Font weight, specified as one of these values:

  • 'normal' — Default weight as defined by the particular font

  • 'bold' — Thicker character outlines than 'normal'

Not all fonts have a bold font weight. For fonts that do not, specifying 'bold' results in the normal font weight.

Font angle, specified as 'normal' or 'italic'. Not all fonts have an italic font angle. For fonts that do not, specifying 'italic' results in the normal font angle.

Horizontal alignment of table cell text, specified as one of the values in the table.

ValueExample
'left'

Table cell with text aligned with the left cell border

'right'

Table cell with text aligned with the right cell border

'center'

Table cell with text centered in the cell

If you add a Style object that specifies horizontal alignment to a table UI component, it takes precedence over the justifications associated with cell format values that you specify for the ColumnFormat property on the Table object. The ColumnFormat property still converts values as it normally would.

Note

If you add a Style object that specifies horizontal alignment to a tree UI component, the HorizontalAlignment value has no effect on the component appearance.

Side on which long text is clipped, specified as one of the values in the table.

ValueExample
'left'

Table cell with long text. The text is cut off on the left with an ellipsis.

'right'

Table cell with long text. The text is cut off on the right with an ellipsis.

Note

If you add a Style object that specifies horizontal clipping to a subset of nodes of a tree or a subset of items of a list box or drop-down UI component, the HorizontalClipping value has no effect on the component appearance. You can still add the style to the entire tree, list box, or drop-down UI component.

Text interpreter, specified as:

  • 'none' — Display literal characters.

  • 'tex'— Interpret text using a subset of TeX markup.

  • 'latex'— Interpret text using a subset of LaTeX markup.

  • 'html'— Interpret text using a subset of HTML markup.

TeX Markup

Use TeX markup to add superscripts and subscripts and to include special characters in the text.

Modifiers remain in effect until the end of the text. Superscripts and subscripts are an exception because they modify only the next character or the characters within the curly braces. When you set the interpreter to 'tex', the supported modifiers are as follows.

ModifierDescriptionExample
^{ }Superscript'text^{superscript}'
_{ }Subscript'text_{subscript}'
\bfBold font'\bf text'
\itItalic font'\it text'
\slOblique font (usually the same as italic font)'\sl text'
\rmNormal font'\rm text'
\fontname{specifier}Font name — Replace specifier with the name of a font family. You can use this in combination with other modifiers.'\fontname{Courier} text'
\fontsize{specifier}Font size —Replace specifier with a numeric scalar value in point units.'\fontsize{15} text'
\color{specifier}Font color — Replace specifier with one of these colors: red, green, yellow, magenta, blue, black, white, gray, darkGreen, orange, or lightBlue.'\color{magenta} text'
\color[rgb]{specifier}Custom font color — Replace specifier with a three-element RGB triplet.'\color[rgb]{0,0.5,0.5} text'

This table lists the supported special characters for the 'tex' interpreter.

Character SequenceSymbolCharacter SequenceSymbolCharacter SequenceSymbol

\alpha

α

\upsilon

υ

\sim

~

\angle

\phi

ϕ

\leq

\ast

*

\chi

χ

\infty

\beta

β

\psi

ψ

\clubsuit

\gamma

γ

\omega

ω

\diamondsuit

\delta

δ

\Gamma

Γ

\heartsuit

\epsilon

ϵ

\Delta

Δ

\spadesuit

\zeta

ζ

\Theta

Θ

\leftrightarrow

\eta

η

\Lambda

Λ

\leftarrow

\theta

θ

\Xi

Ξ

\Leftarrow

\vartheta

ϑ

\Pi

Π

\uparrow

\iota

ι

\Sigma

Σ

\rightarrow

\kappa

κ

\Upsilon

ϒ

\Rightarrow

\lambda

λ

\Phi

Φ

\downarrow

\mu

µ

\Psi

Ψ

\circ

º

\nu

ν

\Omega

Ω

\pm

±

\xi

ξ

\forall

\geq

\pi

π

\exists

\propto

\rho

ρ

\ni

\partial

\sigma

σ

\cong

\bullet

\varsigma

ς

\approx

\div

÷

\tau

τ

\Re

\neq

\equiv

\oplus

\aleph

\Im

\cup

\wp

\otimes

\subseteq

\oslash

\cap

\in

\supseteq

\supset

\lceil

\subset

\int

\cdot

·

\o

ο

\rfloor

\neg

¬

\nabla

\lfloor

\times

x

\ldots

...

\perp

\surd

\prime

´

\wedge

\varpi

ϖ

\0

\rceil

\rangle

\mid

|

\vee

\langle

\copyright

©

LaTeX Markup

To use LaTeX markup, set the interpreter to 'latex'. Use LaTeX markup to format and display mathematical expressions, equations, and special characters. Use dollar symbols around the marked up text. For example, use '$\int_1^{20} x^2 dx$' for inline mode or '$$\int_1^{20} x^2 dx$$' for display mode.

The displayed text uses the default LaTeX font style. The FontName, FontWeight, and FontAngle label properties do not have an effect. To change the font style, use LaTeX markup.

MATLAB supports most standard LaTeX math mode commands. For more information, see Supported LaTeX Commands.

HTML Markup

To use HTML markup, set the interpreter to 'html'. Setting font styles via HTML overrides any equivalent Style font properties. For example, the following code results in red text.

fig = uifigure;
s1 = uistyle("Interpreter","html");
s2 = uistyle("FontColor","blue");

t = uitable(fig);
t.Data = ["<p style='color: red;'>Cell 1</p>"; "<p style='color: red;'>Cell 2</p>"];
addStyle(t,s1)
addStyle(t,s2)

The interpreter supports a subset of HTML markup. As a general guideline, the interpreter supports text-related tags and styles. Unsupported tags and styles are ignored.

This table lists the supported elements and element attributes.

HTML ElementAttributesDescription
astyle, target, href, titleHyperlink
abbrstyle, titleAbbreviation or acronym
addressstyleContact information
articlestyleSelf-contained, independent content
asidestyleContent indirectly related to the main content
bstyleBold text
bdistyle, dirContent formatted in a different direction from surrounding text
bdostyle, dirContent formatted in a different direction from surrounding text
bigstyleText one font size level larger than surrounding text (obsolete in HTML5)
blockquotestyle, citeExtended quotation
brn/aLine break
captionstyleCaption or title of a table
centerstyleContent centered horizontally
citestyleTitle of a creative work
codestyleFragment of code
colstyle, align, valign, span, widthColumn within a table
colgroupstyle, align, valign, span, widthGroup of columns within a table
ddstyleTerm or value in a description list
delstyle, datetimeText that was deleted from a document
detailsstyle, openInteractive widget with text visible only when toggled to 'open' state
dlstyleDescription list
dtstyleTerm or value in a description list
emstyleEmphasized text (typically displayed in italic)
fontstyle, color, size, faceText with specified font properties (obsolete in HTML5)
footerstyleFooter
h1. h2, h3, h4, h5, h6styleSection heading — <h1> is the highest level of heading and <h6> is the lowest
headerstyleIntroductory content
hrstyleThematic break
istyleText offset from the surrounding content — by default rendered as italic
insstyle, datetimeText inserted into a document
listyleItem in a list
markstyleMarked or highlighted text
olstyleOrdered list
pstyleParagraph
prestylePreformatted text
sstyleText with a strikethrough
strikestyleText with a strikethrough (obsolete in HTML5)
sectionstyleStandalone section
smallstyleText one font size level smaller than surrounding text (obsolete in HTML5)
substyleSubscript
supstyleSuperscript
strongstyleText with strong importance
tablestyle, width, border, align, valignTable
tbodystyle, align, valignTable body
tdstyle, width, rowspan, colspan, align, valignTable data cell
tfootstyle, align, valignSet of table rows that summarize the table columns
thstyle, width, rowspan, colspan, align, valignTable data cell specified as a header of a group of cells
theadstyle, align, valignSet of table rows that specify the column heads
trstyle, rowspan, align, valignRow of table cells
ttstyleMonospace text (obsolete in HTML5)
ustyleText with an unarticulated annotation — by default rendered as an underline
ulstyleUnordered list

For more information about these elements, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element.

To use HTML markup to create a hyperlink that runs MATLAB code, see Create Hyperlinks that Run Functions.

You can use HTML style attributes to format HTML content. A style attribute is a string of CSS attributes and their values.

These CSS attributes are supported:

  • background-color

  • border-bottom

  • border-bottom-color

  • border-bottom-left-radius

  • border-bottom-right-radius

  • border-bottom-style

  • border-bottom-width

  • border-left

  • border-left-color

  • border-left-style

  • border-left-width

  • border-radius

  • border-right

  • border-right-color

  • border-right-style

  • border-right-width

  • border-spacing

  • border-style

  • border-top

  • border-top-color

  • border-top-left-radius

  • border-top-right-radius

  • border-top-style

  • border-top-width

  • border-width

  • color

  • direction

  • font-family

  • font-size

  • font-style

  • font-weight

  • height

  • hidden

  • line-height

  • margin

  • margin-bottom

  • margin-left

  • margin-right

  • margin-top

  • max-height

  • max-width

  • min-height

  • min-width

  • overflow

  • overflow-wrap

  • overflow-x

  • overflow-y

  • padding

  • padding-bottom

  • padding-left

  • padding-right

  • padding-top

  • text-align

  • text-anchor

  • text-decoration

  • text-indent

  • text-overflow

  • text-shadow

  • text-transform

  • title

  • translate

  • white-space

  • width

For more information about these attributes, see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference.

Icons

expand all

Predefined or custom icon, specified as a character vector, string scalar, or truecolor image array.

Predefined Icon

This table lists the values to specify the predefined icons.

ValueIcon
'question'

Question icon

'info'

Info icon

'success'

Success icon

'warning'

Warning icon

'error'

Error icon

'none'No icon displays.

Custom Icon

Specify a custom icon as one of these values:

  • A character vector or string scalar that specifies the file name of an SVG, JPEG, GIF, or PNG image that is on the MATLAB path. Alternatively, you can specify a full path to the image file.

  • A truecolor image array. See Working with Image Types in MATLAB for more information.

Alignment of table cell icon, specified as one of the values in the table. The examples in the table show the result of specifying each IconAlignment value for a table UI component with a HorizontalAlignment style of 'center'.

ValueDescriptionExample
'left'The icon is displayed directly to the left of the text.

Table cell with centered text and a green check mark icon directly to the left of the text

'right'The icon is displayed directly to the right of the text.

Table cell with centered text and a green check mark icon directly to the right of the text

'center'The icon is displayed in the center of the cell, behind the text.

Table cell with centered text and a green check mark icon centered behind the text

'leftmargin'

The icon is displayed on the far left of the cell, regardless of the text position.

This value is equivalent to 'left' when the value of HorizontalAlignment is 'left'.

Table cell with centered text and a green check mark icon on the far left side of the cell

'rightmargin'

The icon is displayed on the far right of the cell, regardless of the text position.

This value is equivalent to 'right' when the value of HorizontalAlignment is 'right'.

Table cell with centered text and a green check mark icon on the far right side of the cell

Note

If you add a Style object that specifies icon alignment to a tree UI component, the property has no effect on the tree appearance.

Version History

Introduced in R2019b

expand all