Ceci est une ancienne révision du document !
One common requirement when creating vector drawings is to align objects relative to one another. You might want a circle that's centered within a square, or a triangle that touches the top of the page. A related requirement is to distribute several objects evenly, with identical gaps between each of them. These types of arrangements are made easy with Inkscape's Align and Distribute dialog. This dialog can be opened via the Object menu, the icon to the right of the main “Commands” toolbar, or by pressing CTRL-SHIFT-A. The screenshot was taken from version 0.91 and has a few minor differences to the 0.48 version that's still in many distributions' repositories: the buttons I've outlined in red are new to 0.91, and a few of the other icons have moved to new positions. For this article, I'll be concentrating on the Align section at the top of the dialog, which hasn't significantly changed between versions. Let's start with an extremely simple alignment task: to center a circle in the middle of a page. Start by drawing a circle anywhere in the workspace – it doesn't even have to be inside the page. Now, with the circle selected, open the Align and Distribute dialog and select “Page” from the “Relative to” pop-up menu. There's no option to center both horizontally and vertically at once, so you have to click the “Center on vertical axis” button first, followed by the “Center on horizontal axis” button afterwards (or vice versa, if you prefer). These buttons can be found, one above the other, in the two rows of icons within the “Align” section of the dialog.
Une demande classique dans la création de dessins vectoriels est d'aligner des objets par rapport à un autre. Vous pouvez désirer qu'un cercle soit centré dans un carré, ou qu'un triangle touche le haut de la page. Un autre besoin du même genre est de distribuer plusieurs objets régulièrement, avec les mêmes écarts entre eux. Ces formes d'arrangements se font facilement avec la boîte de dialogue Aligner et Distribuer.
Cette boîte de dialogue peut être ouverte par le menu Objet, l'icône à droite de la barre de commandes principale ou en appuyant sur Maj-Ctrl-A. La copie d'écran a été prise avec la version 0.91 et elle a des écarts mineurs avec la version 0.48 qui est toujours dans de nombreux dépôts des distributions : les boutons que j'ai encadré en rouge sont nouveaux dans la 0.91, et quelques autres icônes ont été déplacées. Pour cet article, je vais me concentrer sur la section Aligner qui n'a pas subi de changements significatifs entre les versions.
Commençons par une tache d'alignement extrêmement simple : Centrer un cercle au milieu d'une page. Commencez par dessiner un cercle n'importe où dans l'espace de travail - il peut même se trouver à l'extérieur de la page. Maintenant, le cercle étant sélectionné, ouvrez la boîte de dialogue Aligner et distribuer et sélectionnez « Page » dans la liste déroulante « Relativement à ». Il n' y a pas d'option pour centrer horizontalement et verticalement d'un seul coup ; aussi, vous devez cliquer d'abord sur « Centrer selon un axe vertical », suivi d'un clic sur « Centrer selon un axe horizontal » (ou l'inverse, si vous préférez). Ces deux boutons, l'un au dessous de l'autre, se trouvent dans les deux lignes d'icônes de la section « Aligner » de la boîte.
That was pretty straightforward, right? Now create three or four circles of different sizes, each with a stroke but no fill. Select them all and repeat the previous steps. If all went well you should now have a series of concentric circles all centered on the page. This example image shows the “before” and “after” arrangement of some circles that were centered in this way: It's important to understand that you can align more than one object at the same time. Usually this reduces the number of steps you need to perform, but sometimes it can be confusing when an inadvertently selected object disappears behind a larger shape that you're trying to align. When dealing with multiple objects, you sometimes want to center the whole arrangement, whilst keeping the individual elements in the same relative positions. One approach is to group them all first: the buttons in the dialog will align the group, but won't descend into it to affect the individual elements. The same effect can be achieved by enabling the “Treat selection as group” checkbox in the dialog before you click on the alignment buttons, saving you the trouble of grouping and then un-grouping your objects (see illustration on following page, top left). With “Treat selection as group” unchecked, let's take a look at some other possibilities. On either side of the two centering buttons you'll find buttons for aligning the top, bottom, left or right edges of your objects. In practice, this refers to the edge of the bounding box for the objects – either the visual or the geometric bounding box, depending on how your Inkscape preferences are set. Most of the time this distinction isn't important, but it can drastically alter the results when a filter is applied to your objects and the visual bounding box is in use.
C'était plutôt rapide, n'est-ce pas ? Maintenant créez trois ou quatre cercles de différentes tailles, chacun en trait, sans remplissage. Sélectionnez-les tous et répétez les étapes précédentes. Si tout s'est bien passé, vous devriez avoir une série de cercles concentriques au centre de la page.Cette image exemple montre les arrangements « avant » et « après » de quelques cercles qui ont centrés de cette façon :
Il est important de comprendre que vous pouvez aligner plus d'un objet à la fois. Habituellement, ça réduit les nombre d'étapes que vous avez à réaliser, mais, parfois, ça peut être perturbant quand un objet sélectionné disparaît par inadvertance derrière une forme plus grande que vous essayez d'aligner.Quand vous traitez plusieurs objets, vous voulez parfois centrer un arrangement comme un tout, tout en gardant les éléments individuels dans leurs positions relatives. Une approche est de les grouper d'abord : les boutons de la boîte de dialogue aligneront le groupe, mais ne rentreront pas dedans pour affecter les éléments individuels. Le même résultat peut être obtenu en cochant « Manipuler la sélection comme un groupe : » dans la boîte de dialogue avant d'appuyer sur les boutons d'alignement, vous épargnant de grouper puis dégrouper vos objets (voir l'illustration sur la page suivante, en haut à gauche).
Avec « Manipuler la sélection comme un groupe : » décoché, regardons d'autres possibilités. Sur chaque côté des 2 boutons de centrage, vous trouverez les boutons pour un alignement sur le haut, le bas, la gauche ou la droite de de vos objets. En pratique, la référence est le côte de la boîte englobante des objets - qui peut être soit visuelle, soit géométrique, suivant les préférences D'Inkscape que vous avez choisies. La plupart du temps, cette distinction est sans importance, mais cela peut altérer fortement les résultats quand un filtre est appliqué au objets, alors qu'un la boîte englobante visuelle est active.
So far, we've only aligned things relative to the page. Using the pop-up menu you can select various other options. For now we'll look at “Drawing” and “Selection Area” (just “Selection” in 0.48). “Drawing” refers to an imaginary bounding box that encompasses everything you've drawn in your image, whether it's inside or outside the page boundary. It stretches from the left edge of the leftmost object in your drawing to the right edge of the rightmost object, and the equivalent in height. “Selection”, on the other hand, just refers to the bounding box that encompasses all of the currently selected objects. In this example, I've created a few objects and selected all of them except for the purple star. Notice the difference as I use the “Align left edges” button, first with the page, then the drawing and finally the selection. As well as aligning to the page, drawing or selection bounding boxes, objects can also be aligned relative to one another. To do this you need to select at least two objects: one of them will remain anchored in its original position, and all the other objects will be aligned to it. Inkscape offers four options for choosing which of the objects will be anchored: the first object you selected, the last one, the biggest object or the smallest.
Jusqu'à présent, nous n'avons aligné les objets que par rapport à la page. En utilisant la liste déroulante, vous pouvez sélectionner d'autres options variées. Maintenant, nous allons regarder « Dessin » et « Zone de sélection » (marquée juste « Sélection » dans la 0.48). « Dessin » fait référence à la boîte englobante imaginaire qui embrasse tout ce que vous avez mis dans votre image, que ça soit dans ou en dehors des limites de la page. Elle s'étend du bord gauche de l'objet le plus à gauche de votre dessin au bord droit de l'objet le plus à droite, et pareil dans la hauteur. « Sélection », à contrario, se réfère uniquement à la boîte englobante qui contient tous les objets sélectionnés actuellement.
Dans cet exemple, j'ai créé quelques objets et je les ai tous sélectionnés, à l'exception de l'étoile violet. Notez la différence quand j'utilise, d'abord la page, ensuite le dessin et enfin la sélection.
De même qu'on peut aligner les boîtes englobantes sur la page, le dessin ou la sélection, il est possible d'aligner les objets les uns par rapport aux autres. Pour réaliser ceci, nous devons sélectionner au moins deux objets : l'un d'eux restera ancrer dans sa position d'origine, tandis que tous les autres s'aligneront sur lui. Inkscape offre quatre options pour choisir l'objet ancré : le premier objet que vous sélectionnez, le dernier, le plus gros ou le plus petit.
Of these choices I recommend using only First Selected and Last Selected. They make it easy to determine what's going to move, and what isn't. When trying to align objects, you've usually got a good idea of the outcome you're trying to achieve, so being able to specify exactly which object is used as the anchor for alignment is more useful than some unclear definition of “bigger” or “smaller”. For example, suppose you have a rectangle that you duplicate and rotate through 90°. Which of the two is “bigger” and will be used as the anchor? They're both exactly the same area, but one is wider and the other is taller. The answer depends on what type of alignment you choose: the buttons on the top row, which move the objects horizontally, consider the object with the largest width to be the “biggest”; the buttons on the second row, which move the objects vertically, consider the tallest object to be the “biggest”. In this example the red rectangle is a rotated copy of the yellow one, and the alignment mode was set to “Biggest object” before each of the centering buttons was pressed.
Clearly the use of “Biggest object” and “Smallest object” can cause problems and confusion if multiple objects are the same size, but it can also be misleading when an optical illusion leads you to think that (for example) a dark object is bigger than a similarly sized light object. There's a similar problem when selecting multiple objects at once, then using “First selected” or “Last selected” (Inkscape bases its choice of anchor on the z-index of the items in that case), leading to my rules for aligning objects relative to each other: • Use “First selected”. • De-select everything (click in the work area, away from any objects – or use Edit > Deselect). • Select the object you want to align to (the anchor). • Hold shift and drag a rectangle over the objects you want to align. • Add or remove individual objects from the selection by holding SHIFT as you click on them. • Click on one alignment button from the top row and/or one alignment button from the second row to move the objects into place.
With that approach you'll always be in control of which objects are moved, and where they move to. The only variation that I ever use is when the objects I want to move are already selected – especially if it's a complex selection. In that case it's worth using “Last selected” and just holding SHIFT whilst clicking on the anchor object to add it to the selection. If the anchor is already selected, you can SHIFT-click to de-select it, then do the same again to re-select it, thus making it the last selected object. When using First/Last/ Biggest/Smallest you should note that the behaviour of the “Treat selection as group” checkbox changes somewhat – often in a counter-intuitive way. In these modes, the anchor object has to be part of the group, so you might expect it to move along with everything else in order to maintain the relative positions of objects (as we saw when using the Page/Drawing/Selection modes). What actually happens, however, is that the anchor object remains stationary and all the other selected objects move as though they're grouped. In other words it becomes a “treat selection as group, except for the anchor object” checkbox. Furthermore, the effect of this checkbox changes depending on the layout of your objects. In this example, I've drawn three red stars and one green circle, arranged per the top image. Using “First selected” mode I click on the circle, then hold SHIFT and drag a rectangle over the stars. Ensuring that “Treat selection as group” is checked, a click on the “Center on vertical axis” button should move the stars, keeping the circle in place. Logic might suggest that I'll end up with the second image, but actually what I get is the third one. What's going on?
It's our old friend the bounding box at play once more. Consider the bounding box of the first image – it's the total width of the stars plus the circle. When centering the selection, it's this bounding box that's used for the calculation, even though the circle won't be moved with the other objects. The result is that the stars are moved so that the center of the original bounding box is centered with the circle, even though doing so results in a smaller bounding box afterwards. There are two solutions to this dilemma: the most obvious is to group the stars then align the group to the circle with the “Treat selection as group” checkbox un-ticked. This turns a complex arrangement of four objects into a simpler problem involving just two – the circle and the group. It's the approach I used to produce the second image in the example. The other alternative is to click the “Center on vertical axis” button a second time: after the first press, the new bounding box is only as wide as the stars, so aligning again (with the checkbox enabled) results in the expected behaviour. With everything you've read so far, you should be able to understand the behaviour of most of the alignment buttons in the dialog, but there are two that defy the rules: the last button on each row is purely used to align text objects.
These buttons align text objects to the vertical or horizontal baseline of other text objects. They ignore any non-text objects in the selection, pay no attention to the state of the “Treat as group” checkbox, and don't even honour the “Relative to” pop-up. If you're using Inkscape for some simple desktop publishing work – perhaps creating a poster or flyer – then they can be used to ensure that different sections of text adhere to the same baseline (the line that runs under the text, ignoring any descenders such as the tail on a “y”). This can give a more professional appearance. An alternative approach is to drag out a guide from the ruler (see part 16), enable snapping, and activate the “Snap text anchors and baselines” option. Regardless of your method, if you use multi-line text, then it's only the baseline of the first line that is snapped or aligned to, preventing completely separate pieces of text from easily sharing the same “baseline grid” as you might in a proper DTP program such as Scribus. Perhaps the most important thing to remember about aligning in Inkscape is that, however you align your objects, if you end up with an alignment you're not happy with, simply press CTRL-Z or use Edit > Undo to reverse the action. There's logic to alignment in Inkscape – even if that logic doesn't always produce the outcome you might initially expect.