| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
The Alignment Tool enables you to position objects with respect to each other and to adjust the spacing between selected objects. The specified alignment operations apply to all components that are selected when you press the Apply button.
Note To select multiple components, they must have the same parent. That is, they must be contained in the same figure, panel, or button group. See Selecting Components for more information. |

The alignment tool provides two types of alignment operations:
Align — Align all selected components to a single reference line.
Distribute — Space all selected components uniformly with respect to each other.
Both types of alignment can be applied in the vertical and horizontal directions. In many cases, it is better to apply alignments independently to the vertical and horizontal using two separate steps.
There are both vertical and horizontal align options. Each option aligns selected components to a reference line, which is determined by the bounding box that encloses the selected objects. For example, the following picture of the layout area shows the bounding box (indicated by the dashed line) formed by three selected push buttons.

All of the align options (vertical top, center, bottom and horizontal left, center, right) place the selected components with respect to the corresponding edge (or center) of this bounding box.
Distributing components adds equal space between all components in the selected group. The distribute options operate in two different modes:
Equally space selected components within the bounding box (default)
Space selected components to a specified value in pixels (check Set spacing and specify a pixel value)
Both modes enable you to specify how the spacing is measured, as indicated by the button labels on the alignment tool. These options include spacing measured with respect to the following edges:
Vertical — inner, top, center, and bottom
Horizontal — inner, left, center, and right
In GUIDE, as in MATLAB generally, you can see and set most components' properties using the Property Inspector. To open it from the GUIDE Layout Editor, do any of the following:
Select the component you want to inspect, or double-click it to open the Property Inspector and bring it to the foreground
Select Property Inspector from the View menu
Click the Property Inspector button
![]()
The Property Inspector window opens, displaying the properties of the selected component. For example, here is a view of a push button's properties.

Scroll down to see additional properties. Click any property value or icon to the left of one to set its value, either directly in that field or via a modal GUI such as a pop-up menu, text dialog, or color picker. Click the plus boxes on the left margin to expand multiline properties, such as BackgroundColor, Extent, and Position.
The Property Inspector provides context-sensitive help for individual properties. Right-clicking a property name or value opens a context menu item saying What's This?. Clicking it opens a Help window displaying documentation for the property you selected. For example, on the right is context-sensitive help for the push button ButtonDownFcn obtained from the Property Inspector as shown on the left.
|
|
For more information, see Accessing Object Properties with the Property Inspector in the MATLAB Graphics documentation.
The Property Inspector enables you to align components by setting their Position properties. A component's Position property is a 4-element vector that specifies the location of the component on the GUI and its size: [distance from left, distance from bottom, width, height]. The values are given in the units specified by the Units property of the component.
Select the components you want to align. See Selecting Components for information.
Select Property Inspector from
the View menu or click the Property
Inspector button
.
In the Property Inspector, scroll to the Units property and note its current setting, then change the setting to inches.
Scroll to the Position property. A null value means that the element differs in value for the different components. This figure shows the Position property for multiple components of the same size.

Change the value of x to align their left sides. Change the value of y to align their bottom edges. For example, setting x to 2.0 aligns the left sides of the components 2 inches from the left side of the GUI.
When the components are aligned, change the Units property back to its original setting.
The layout area displays a grid and rulers to facilitate component layout. Grid lines are spaced at 50-pixel intervals by default and you can select from a number of other values ranging from 10 to 200 pixels. You can optionally enable snap-to-grid, which causes any object that is moved close to a grid line to jump to that line. Snap-to-grid works with or without a visible grid.

Use the Grid and Rulers dialog (select Grid and Rulers from the Tools menu) to:
Control visibility of rulers, grid, and guide lines
Set the grid spacing
Enable or disable snap-to-grid
The Layout Editor has both vertical and horizontal snap-to guide lines. Components snap to the line when you move them close to the line.
Guide lines are useful when you want to establish a reference for component alignment at an arbitrary location in the Layout Editor.
To create a guide line, click the top or left ruler and drag the line into the layout area.

![]() | Adding Components to the GUI | Setting Tab Order | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |