Control label appearance - MATLAB (2024)

Table of Contents
Text Interpreter — Label text interpreter 'none' (default) | 'tex' | 'latex' | 'html' HorizontalAlignment — Horizontal alignment of text 'left' (default) | 'right' | 'center' VerticalAlignment — Vertical alignment of text 'center' (default) | 'top' | 'bottom' WordWrap — Word wrapping to fit component width 'off' (default) | on/off logical value Font and Color BackgroundColor — Background color 'none' (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ... Interactivity Enable — Visual appearance of label 'on' (default) | on/off logical value Tooltip — Tooltip '' (default) | character vector | cell array of character vectors | string array | 1-D categorical array ContextMenu — Context menu empty GraphicsPlaceholder array (default) | ContextMenu object Position InnerPosition — Inner location and size of label [100 100 31 22] (default) | [left bottom width height] OuterPosition — Outer location and size of label [100 100 31 22] (default) | [left bottom width height] Layout — Layout options empty LayoutOptions array (default) | GridLayoutOptions object Callbacks Callback Execution Control Parent/Child Parent — Parent container Figure object (default) | Panel object | Tab object | ButtonGroup object | GridLayout object Identifiers Type — Type of graphics object 'uilabel' Version History R2021a: Style text and display equations R2020b: Wrap label text See Also Functions Tools MATLAB Command Americas Europe Asia Pacific References

Control label appearance

expand all in page

Labels are UI components that contain static text for labelling parts of an app. Properties control the appearance and behavior of a label. Use dot notation to refer to a specific object and property.

fig = uifigure;tlabel = uilabel(fig);tlabel.Text = 'Options';

Text

expand all

Label 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 Label font properties. For example, the following code results in red text.

lbl = uilabel('Interpreter','html');lbl.Text = '<p style="color: red;">Text</p>';lbl.FontColor = 'blue';

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.

Horizontal alignment of the text, specified as:

  • 'right' — Text aligns on the right side of the area specified by the Position property.

  • 'left' — Text aligns on the left side of the area specified by the Position property.

  • 'center'— Text centers horizontally in the area specified by the Position property.

Aligning label text is useful when the text spans multiple lines.

Vertical alignment of the text, specified as one of the following:

  • 'center' — Text centers vertically in the area specified by the Position property.

  • 'top' — Text aligns on the top of the area specified by the Position property.

  • 'bottom' — Text aligns on the bottom of the area specified by the Position property.

Aligning label text is useful when the text spans multiple lines.

Word wrapping to fit component width, specified as 'off' or 'on', or as numeric or logical 0 (false) or 1 (true). A value of 'off' is equivalent to false, and 'on' is equivalent to true. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

Use this property to prevent text from getting clipped horizontally when the width of the component is smaller than the text you want to display.

  • 'off' — Text does not wrap.

  • 'on' — Breaks text into new lines so that each line fits within the width of the component and avoids breaking words when possible.

Setting the WordWrap property to 'on' does not prevent text from getting clipped vertically when the height of the component is too small to display all the lines of text.

Font and Color

expand all

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

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • 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 string scalar or character vector 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. Therefore, 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"

Control label appearance - MATLAB (1)

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

Control label appearance - MATLAB (2)

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

Control label appearance - MATLAB (3)

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

Control label appearance - MATLAB (4)

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

Control label appearance - MATLAB (5)

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

Control label appearance - MATLAB (6)

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

Control label appearance - MATLAB (7)

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

Control label appearance - MATLAB (8)

"none"Not applicableNot applicableNot applicableNo color

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"

Control label appearance - MATLAB (9)

[0.8500 0.3250 0.0980]"#D95319"

Control label appearance - MATLAB (10)

[0.9290 0.6940 0.1250]"#EDB120"

Control label appearance - MATLAB (11)

[0.4940 0.1840 0.5560]"#7E2F8E"

Control label appearance - MATLAB (12)

[0.4660 0.6740 0.1880]"#77AC30"

Control label appearance - MATLAB (13)

[0.3010 0.7450 0.9330]"#4DBEEE"

Control label appearance - MATLAB (14)

[0.6350 0.0780 0.1840]"#A2142F"

Control label appearance - MATLAB (15)

Data Types: double | char

Interactivity

expand all

Visual appearance of the label, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Label appears normal

    Control label appearance - MATLAB (16)

  • 'off' — Label appears dimmed

    Control label appearance - MATLAB (17)

Tooltip, specified as a character vector, cell array of character vectors, string array, or 1-D categorical array. Use this property to display a message when the user hovers the pointer over the component at run time. The tooltip displays even when the component is disabled. To display multiple lines of text, specify a cell array of character vectors or a string array. Each element in the array becomes a separate line of text. If you specify this property as a categorical array, MATLAB uses the values in the array, not the full set of categories.

Context menu, specified as a ContextMenu object created using the uicontextmenu function. Use this property to display a context menu when you right-click on a component.

Position

expand all

Inner location and size of label, specified as [left bottom width height]. Position values are relative to the parent container. All measurements are in pixel units. This property value is identical to Position property.

This property is read-only.

Outer location and size of label, returned as [left bottom width height]. Position values are relative to the parent container. All measurements are in pixel units. This property value is identical to Position.

Layout options, specified as a GridLayoutOptions object. This property specifies options for components that are children of grid layout containers. If the component is not a child of a grid layout container (for example, it is a child of a figure or panel), then this property is empty and has no effect. However, if the component is a child of a grid layout container, you can place the component in the desired row and column of the grid by setting the Row and Column properties on the GridLayoutOptions object.

For example, this code places a label in the third row and second column of its parent grid.

g = uigridlayout([4 3]);tlabel = uilabel(g);tlabel.Layout.Row = 3;tlabel.Layout.Column = 2;

To make the label span multiple rows or columns, specify the Row or Column property as a two-element vector. For example, this label spans columns 2 through 3:

tlabel.Layout.Column = [2 3];

Callbacks

expand all

Callback Execution Control

expand all

Parent/Child

expand all

Parent container, specified as a Figure object created using the uifigure function, or one of its child containers: Tab, Panel, ButtonGroup, or GridLayout. If no container is specified, MATLAB calls the uifigure function to create a new Figure object that serves as the parent container.

Identifiers

expand all

This property is read-only.

Type of graphics object, returned as 'uilabel'.

Version History

Introduced in R2016a

expand all

Use the Interpreter property to enable HTML or LaTeX markup for the label text.

Use the WordWrap property to prevent text from getting clipped horizontally when the width of the UI component is smaller than the text you want to display. Setting the WordWrap property to 'on' breaks the text into new lines so that each line fits within the component. It avoids breaking words when possible. When the property is set to 'off', the text does not wrap.

See Also

Functions

  • uilabel | uifigure

Tools

  • App Designer

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Control label appearance - MATLAB (18)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Control label appearance - MATLAB (2024)

References

Top Articles
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated:

Views: 5827

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.