Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

align

Align UI components and graphics objects

Syntax

align(HandleList,'HorizontalAlignment','VerticalAlignment')
Positions = align(HandleList, 'HorizontalAlignment', 'VerticalAlignment')
Positions = align(CurPositions, 'HorizontalAlignment', 'VerticalAlignment')

Description

align(HandleList,'HorizontalAlignment','VerticalAlignment') aligns the uicontrol and axes objects in HandleList, a vector of handles, according to the options HorizontalAlignment and VerticalAlignment. The following tables show the possible values for HorizontalAlignment and VerticalAlignment.

HorizontalAlignment

Definition

'None'

No horizontal alignment

'Left'

Aligns the left edges of the objects with the left edge of the bounding box that encloses the objects

'Center'

Shifts objects to center their positions to the average of the extreme x-values of the group

'Right'

Aligns the right edges of the objects with the right edge of the bounding box that encloses the objects

'Distribute'

Equalizes x-distances between all objects within the span of the extreme x-values

'Fixed'

Spaces objects to have a specified number of points between them in the x-direction

VerticalAlignment

Definition

'None'

No vertical alignment

'Top'

Aligns the top edges of the objects with the top edge of the bounding box that encloses the objects

'Middle'

Shifts objects to center their positions to the average of the extreme y-values of the group

'Bottom'

Aligns the bottom edges of the objects with the bottom edge of the bounding box that encloses the objects

'Distribute'

Equalizes y-distances between all objects within the span of the extreme y-values

'Fixed'

Spaces objects to have a specified number of points between them in the y-direction

Aligning objects does not change their absolute sizes. All alignment options align the objects within the bounding box that encloses the objects. Distribute and Fixed align objects to the bottom left of the bounding box. Distribute evenly distributes the objects while Fixed distributes the objects with a fixed distance (in points) between them. When you specify both horizontal and vertical distance together, the keywords 'HorizontalAlignment' and 'VerticalAlignment' are not necessary.

If you use Fixed for HorizontalAlignment or VerticalAlignment, you must also specify the distance, in points, where 72 points equals 1 inch. For example:

align(HandleList,'Fixed',Distance,'VerticalAlignment')

distributes the specified components Distance points horizontally and aligns them vertically as specified.

align(HandleList,'HorizontalAlignment','Fixed',Distance)

aligns the specified components horizontally as specified and distributes them Distance points vertically.

align(HandleList,'Fixed',HorizontalDistance,...
      'Fixed',VerticalDistance)

distributes the specified components HorizontalDistance points horizontally and distributes them VerticalDistance points vertically.

Positions = align(HandleList, 'HorizontalAlignment', 'VerticalAlignment') returns updated positions for the specified objects as a vector of Position vectors. The position of the objects on the figure does not change.

Positions = align(CurPositions, 'HorizontalAlignment', 'VerticalAlignment') returns updated positions for the objects whose positions are contained in CurPositions, where CurPositions is a vector of Position vectors. The position of the objects on the figure does not change.

Examples

collapse all

Create a UI window containing three buttons that are roughly in a row.

f = figure('Position',[100 100 350 200]);
u1 = uicontrol('Parent',f,'Position',[43 50 75 30],'String','Yes');
u2 = uicontrol('Parent',f,'Position',[143 75 75 30],'String','No');
u3 = uicontrol('Parent',f,'Position',[233 40 75 30],'String','Cancel');

Align the bottom edges of the buttons, and equalize the horizontal spacing between the buttons.

align([u1 u2 u3],'distribute','bottom');

Create a UI window containing a vertical stack of buttons.

f = figure('Position',[100 100 350 200])
u1 = uicontrol(f,'Position',[10 80 60 30],'String','One');
u2 = uicontrol(f,'Position',[50 50 60 30],'String','Two');
u3 = uicontrol(f,'Position',[30 10 60 30],'String','Three');

Align the button centers and set the space between buttons to seven points.

align([u1 u2 u3],'Center','Fixed',7);

See Also

|

Was this topic helpful?