## Align Shape - Top to Bottom or Left to Right

Started by caveman, August 20, 2019, 07:25:00 AM

0 Members and 1 Guest are viewing this topic.

#### caveman

Hi, I've been looking for a quick way to align shapes top to bottom and not found an easy way other than painstaking zoom and drag.

I've stumbled onto a (I think) an easier way. Last post about this I found was a few years back so thought I'd start a new thread.

Using the size and position X & Y coordinates.
For example
E
A  B
D
If Box A (central you want to alight next to):
X = 72.5mm
Y = 210mm
Width = 45mm
Height = 20mm

Align left of box B to right of box A:
72.5mm (x) + 45mm (width) x = 117.5mm

Align right of box C to left of box A:
72.5mm (x) -45mm (width) x = 27.5mm

Align top of box D to bottom of box A:
210 (y) -20mm (height) y = 190mm

Align bottom of box E to top of box A:
210 )y) + 20mm (height) y = 230mm

Hopefully this makes sense to someone.

#### Yacine

Hi caveman,
I don't really understand the problem.

If there are only 5 shapes like in your example, best would be to use proper snapping settings.
If there are a lot of shapes, where automation begins to make sense, then you would need to define more restrictions (same heigth and width? , how to define the central shape, ....)
Yacine

#### caveman

Yacine,

I only used the example of 5 shapes to show how it can be done from each side.

Problem is how to align two shapes off centre of each other i.e. left hand of one shape with the right hand of another.

Please let me know an easier way if you know it.

Cheers

#### Yacine

#3
There are different ways to do that.

1) Edit manually the shapesheet
You would define a master. Say "A"
Then you write the dependencies in the slave shapes.
Pseudoformula : B.pinX = A.PinX - A.LocPinX + A.Width + B.LocPinX
Formula: =GUARD(Sheet.1!PinX-Sheet.1!LocPinX+Sheet.1!Width+LocPinX)

2) Use a macro
check the tools from Wapperdude and myself.
http://visguy.com/vgforum/index.php?topic=5534.0

3) Use a generic tool
http://visguy.com/vgforum/index.php?topic=6914.15

4) There's a positioning feature in the GUI
which allows you to distribute the gap evenly through a selection. You can use it trying to minimize the gap.
Yacine

#### vojo

Unless you are planning on a 1000 shapes or looking to do this 100 times a day, option 4 is the easiest/quickest way to do this (can even add buttons to the menu to make it a 8 click exercise)
1 select B A D
2 align top
3 distribute horizontally (gap or otherwise)
4 group
5 C group E
6 align middle
7 distribute vertically (gap or otherwise)
8 group or ungroup then group all

#### Croc

In simple cases, guides can help.

#### wapperdude

#6
Note:  my alignment tool has been updated to include more universal shape application.  It uses a User Form which needs to be in place for the alignment macros to work.  http://visguy.com/vgforum/index.php?topic=8870.0.  It would do exactly what you want...you could do the following:

1) select shape A, then a 2nd shape, e.g., B, select direction, e.g., left to right.  Shapes A & B are butted up to each other.
2) continue same process with remaining shape.

Note:  you could use my Visio file as basis for a template, not have copy all the coding.
Visio 2019 Pro

#### Visio Guy

Or better yet:

• Copy the code to the stencil
• Save the stencil to My Shapes
• Whenever you need the functionality, open My Shapes/VBA Code Stencil or whatever you named it

This way, you don't need code in every document - just open "tool stencils" as needed to get access to automation.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

#### Visio Guy

FYI: I've just added the code-containing stencil to wapperdude's original post. Get it here:

http://visguy.com/vgforum/index.php?topic=8870.msg38972#msg38972
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010