4

When I change the stroke width of a rectangle the width and and height change also. How can I prevent this from happening?

  • 1
    The answer by stanm is of course no answer to the actual question. What is asked is a way to change the stroke width without changing the object size, not vice versa. I think there's no way to do this in Inkscape which is unfortunate because like this it is impossible to draw precise diagrams and later change the design. I recently stumbled upon this difficulty and haven't found a solution. – user51470 Sep 25 '15 at 9:22
  • 1. Use the option I suggested 2. Change the stroke -> the height and width change 3. Restore the original height and width -> the stroke doesn't change. Result: you have changed the stroke, but not the width and height. Does it not work for you? – stanm Oct 2 '15 at 18:16
4

In my opinion, "width of a rectangle" in your question can mean two things, leading to two different answers; it is not clear for me which one you actually ask for. Which one do you want to have constant:

  1. The visual size of the rectangle, i.e. from the outer line edge left to the outer line edge right.
  2. The nominal (geometric) size of the rectangle, i.e., from the center of the left line to the center of the right line.

You might rather care for (1) if you do graphic design and for (2) if you do technical drawings. Inkscape by default seems to show (1) as the width of an object (e.g., in the "W:" field in the toolbar). The answers already given here indicate on how to keep this visual size (1) constant.

However, if you are actually interested in (2), Inkscape can also to show this as the width. For this, go to Preferences -> Tools and set "Bounding box to use" to "Geometric bounding box" instead of "Visual bounding box". Now the geometric size (2) will be indicated by Inkscape. You can now change the line width as you like, and the indicated rectangle width is not affected.

3

Assuming that you are talking about a relatively small change:

The reason for this is that a rectangle with a stroke is based on a set of infinetely small lines (red), which are then equipped with a stroke (black) such that those lines are in the middle of the stroke.

rectangle

If you increase the size of the stroke, the position of the lines (red) is fixed and thus you also slightly increase the size of the total object (by half the increase of the stroke width).

I am not aware of a way to directly prevent this, but you can manually reset the size of the rectangle after changing the stroke width. The easiest way to do this is as follows:

  1. Select the rectangle.
  2. Copy it (Ctrl + C).
  3. Change the stroke width.
  4. Paste → Paste Size (if you care about preserving the size to the last digit, you may have to repeat this once or twice).
  • Inkscape also has a feature for changing the path to "inset" that is very awkward to use. Your technique is most more flexible and easier to use though. – Scribblemacher Sep 25 '15 at 11:56
2

In Inkscape while in Scaling and transform objects (F1) mode there are four toggle buttons on the top toolbar after a label Affect:. The first one has tooltip stating When scaling objects, scale the stroke width by the same proportion. Turn it off and then you can resize the rectangle without changing the stroke width.

  • I agree with some others that this isn't the specific answer, but I think it's the best workaround we have in inkscape for the time being. – DA01 May 9 '16 at 16:21
  • It may not have answered to OP's question, but since I came here looking for "scale image constant line width" I was glad to find it! – holdenweb Apr 18 at 8:47
0

It sounds like what you are asking for is similar to box-sizing:border-box in CSS. There is no analog for this property in SVG.

Inkscape does have a built-in work around for this problem. The work around attempts to re-size your object so that result is as though the stroke moved inward. This is a one-time only function so you'd have to do it again any time you size your object. It also requires you to plan ahead your sizes.

  1. Draw a rectangle with a stroke width of 5px.
  2. Duplicate it with Ctrl+D and move it off to the size.
  3. In your duplicate, change your border to 10px.
  4. With the duplicate selected, click Path > Inset.

If you compare the size of the two rectangles, you'll see that it didn't work! The reason is for the imaginary border box. So when you change to inset for a 10px border, it reducing the object's size by (w / 2) + 1 px.

In other words, to expand the border of a 5px box, could change it to 9px and use inset once, change it to 13px and use inset twice, change it to 17px and use inset 3 times, etc. You can't just pick an arbitrary value, you have to grow the border based on the current border size.

This is obviously really awkward to use. A more reliable technique is described in Wrzlprmft's answer.

-1

In the stroke panel you can adjust whether the stroke aligns to the center, outside or inside of the path. Create the perfect size rectangle and then Align the stroke to the inside. As you make the stroke bigger, it will grow towards the inside thus maintaining the size of the rectangle. Note you can only adjust the path stroke alignment on closed paths - so it will work for the rectangle but something to know if you try to apply it to an open path it won't let you.

  • 1
    what you describe would be ideal, but, how do you align the stroke to the inside? I cannot see an option to do this in the stroke panel. Are you referring to the fill and stroke panel invoked by pressing shift+Ctrl+F? Where in the panel is the alignment set? – user18962 Dec 31 '14 at 18:44
  • 3
    I believe this answer may be referring to Adobe Illustrator, not Inkscape. – Scott Dec 31 '14 at 19:41
  • Yes, this would solve the problem if i were actually a feature in inkscape but, alas, it is not. This is something inkscape needs to hopefully address in the future. – DA01 May 9 '16 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy