Ceci est une ancienne révision du document !
Last time I introduced the Align and Distribute dialog, but went only as far as describing the Align part. This time I'll continue – not only onto the Distribute section, but down through the remaining sections of the dialog as well. Let's start with a reminder of what the dialog looks like, noting that there's been a little rearrangement of the buttons between 0.48 and 0.91, and the ones outlined in red are new to 0.91.
Much like the Align section, the Distribute part of the dialog is split into two rows of buttons, governing horizontal and vertical distribution, respectively. Using these, you can distribute a number of objects so that they're spaced evenly along the horizontal axis or the vertical axis. If you want to distribute along both axes – to create a staircase effect – you'll need to press a button from each row in turn.
As you might expect, the objects to be distributed are the ones that are selected on the canvas. Selection order doesn't matter, and you can't choose the anchor objects: everything is calculated implicitly from the positions of the elements. When distributing horizontally, for example, the objects furthest to the left and right will be left in place, with all the others being distributed between them. For vertical distribution, the rules are the same, except with the highest and lowest (by y coordinates) being left in place.
What this means, in practice, is that you need to get your first and last objects into the right place before trying to use these buttons. Often that involves snapping to the grid, or aligning to another object as described last time. Only once those are in the right locations should you select all the objects you want to distribute – including the first and last ones – and then click on one of the buttons.
The difference between each of the buttons is quite well represented by their icons. Considering each of the five buttons in the first row (I'm sure you can infer the equivalent functions for the second row), the buttons move your selected objects so that: • The left edges of their bounding boxes are evenly distributed • The centers of their bounding boxes are evenly distributed • The right edges of their bounding boxes are evenly distributed • The space between each bounding box is evenly distributed • The space between baseline anchors of text objects is evenly distributed
That last one probably needs a little more explanation. Much like the text alignment buttons mentioned in the previous instalment, these two text distribution buttons work only with a selection of text objects. When you edit text in Inkscape, you may notice a small square below the text you enter. This is the baseline anchor, and its position varies depending on the text justification. These buttons move your text objects so that the baseline anchors are evenly distributed. Before rushing to use these buttons to distribute your text, however, do consider whether that's really what you want: usually the previous button (even spaces between objects) gives a better result.
Often you'll find that the difference between distribution options is negligible, especially when the objects are all similarly sized. When you start to distribute differently sized elements, however, the differences can be significant, as you can see from the image shown below.
Continuing downwards, the layout of the dialog diverges between versions 0.48 and 0.91. For the latter, the next section of the dialog is labelled as “Rearrange”, and consists of six icons of varying provenance: • Arrange Connector Network: Moved from the “Connector network layout” section in 0.48 • Exchange positions, selection order: New to 0.91 • Exchange positions, stacking order: New to 0.91 • Exchange positions, clockwise rotate: New to 0.91 • Randomise centers: Moved from the “Distribute” section in 0.48 • Unclump objects: Moved from the “Distribute” section in 0.48
The first of these works only if your selected objects form a network that was created with the Connector tool (see part 27 of this series for more details). It's just a duplicate of the same button in the Connector tool controls – except that this one offers fewer settings. My advice is to use the dedicated connector toolbar if you need this functionality, but really you're better off using a different application altogether for anything more than a trivial connector layout.
Have you ever wanted to swap the positions of two objects? To move the left one to the right, and the right one to the left, for example? In that case the three new buttons in 0.91 are for you. With two objects selected, their positions will be swapped, but if you have more than two things selected then the first moves to the position of the second, the second to the third, the third to the fourth, and so on. The last moves to the position of the first.
But what determines which object is first, second or third? That's simply down to which button you click. The first button bases it on which order the objects were selected in – so it's best to hold shift and click on each one individually to ensure you know the selection order. The second button uses the stacking order, or z-index, of the selected objects. The one on top is moved to the position of the one beneath it. That moves to the position of the one beneath that, and so on down the stack. The bottom object is moved to the position of the topmost item. Note, however, that it's just the positions that are changed, not the z-indexes, so the stacking order remains the same. The final button swaps the positions of the selected objects in a “clockwise” direction, based on the x and y coordinates of each object.
Whilst these buttons are a welcome addition, I hope that their functionality will be expanded further in a future release. There's no option to reverse the order, for example. If you want to rotate 100 objects one step anti-clockwise you currently have to do it by clicking the clockwise button 99 times!
The “Randomise centers” button does exactly as its name suggests. Click it and your selected objects are randomly moved around. This may be useful if you've used the Spray tool or Tiled Clones dialog to create a lot of objects that you then want to randomly distribute – but the same effect can often be better achieved by using the Randomise fields in the Tiled Clones dialog, or with the Tweak tool (see part 22).
The final button in this section is described as “Unclump objects”. In practice, it moves your objects a little in order to more evenly space the edge-to-edge distances. You can apply it repeatedly, but it will eventually reach equilibrium. It can be useful for neatly arranging objects in two dimensions – think of it as a 2D equivalent to the “equidistant spacing” buttons in the Distribute section. Be careful if your objects overlap too much, as it can tend to pull them all together into a single pile rather than separating them out – the exact opposite of “unclumping” in my book!
In fact, separating objects out is really the job of the last section in this dialog: Remove overlaps. The spinboxes allow you to specify the minimum distance between bounding boxes in both horizontal and vertical directions, whilst clicking the button at the right will actually perform the operation. You can use the H and V parameters to push your objects further apart by setting them to values greater than 0 (in pixels). You can also enter negative values, but doing so won't pull your objects closer together: because this is the minimum spacing, it simply means that already overlapping objects can continue to overlap to some degree. Do note that the calculations are based on the rectangular bounding boxes, though, so if you're working with objects such as circles you can sometimes find that their movements aren't what you expected. Take a look at the bounding boxes to see what really happened.
If you look again at the screenshot of this dialog, you might be forgiven for thinking that I've covered all of it, but that's only because you've been misled by a slight oddity in this dialog. On first opening it, there's a section at the bottom labelled “Nodes”, with four additional buttons – as seen in last month's screenshot. As you start to select objects, however, that section disappears from sight. In practice, it's still available, but only when you switch to the Node tool in the main toolbar. On doing so, the dialog changes completely to just show this: To use this mode, you must first select some nodes using the Node tool. You can even select nodes from multiple different paths, if you wish. Clicking on the first button will align the nodes along a single horizontal line that lies halfway between the top and bottom of the nodes' bounding box . The second button does the same trick along the vertical axis. There's no option to align to the top, bottom, left or right of the box, nor to the first node selected. If you need a specific alignment then the best approach is to set a guide at the right place, align horizontally or vertically, then drag the still selected nodes to the guide, preferably with snapping enabled.
Clicking both of the alignment buttons in succession is a quick way to collapse all the nodes down to a single point, and can be particularly useful for ensuring that nodes from different paths are co-located, such as when trying to fake the appearance of a connection between more than two paths at a single point. Unfortunately all the selected nodes move, with no option to use one as an anchor point, so, whilst it's a quick way to co-locate them, it's not so useful if you need them at a specific position. It's also important to note that this is just a visual effect – there's no native support for co-located nodes in SVG – so you have to take care to select all the relevant nodes if you need to move them later.
The last two buttons in Node mode distribute the selected nodes evenly. Like the equivalent tool for objects, they are distributed between the nodes that are positioned furthest to the left and right (or top and bottom for vertical distribution). That concludes our tour of the Align and Distribute dialog. It may not offer all the options of a fully-fledged CAD application, but once you get used to the features it does have, it can quickly become an invaluable addition to your toolbox. If you want to produce good looking diagrams with evenly spaced, neatly-aligned content, it's well worth spending a little time becoming familiar with its capabilities.