• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to shortcut the increase add space after and increase space before a paragraphi

Explorer ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

I want to use two shortcuts to improve my work.

I think it is possible by scripting but i don't know how so i ask here.
 i want to create a shortcut to increase space after paraprgaph as the button in palette and one to increase the space before the paragraph.

 

my left mouse button and relative finger will thank you forever.

TOPICS
How to , Scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 03, 2021 Jun 03, 2021

For many years I have used small scripts to add or remove space before or after paragraphs. That's much easier than creating separate paragraph styles.

 

Two scripts below: the first adds 1 pt to the space before the currently selected paragraph, the second one adds half a line of white before the current paragraph. 'Selected' means: just click somewhere in the paragraph.

 

I use slight variants of these script to decrease the space by 1 point (simple change += with -=), and to add/remove space

...

Votes

Translate

Translate
Community Expert ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

I don't know anything about scripting but why don't you simply use paragraph styles?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

For many years I have used small scripts to add or remove space before or after paragraphs. That's much easier than creating separate paragraph styles.

 

Two scripts below: the first adds 1 pt to the space before the currently selected paragraph, the second one adds half a line of white before the current paragraph. 'Selected' means: just click somewhere in the paragraph.

 

I use slight variants of these script to decrease the space by 1 point (simple change += with -=), and to add/remove space after the selected paragraph (simply replace spaceBefore with spaceAfter).

 

Then assign these scripts to keyboard shortcuts. On my keyboard I use these keys:

F1: add 1 pt space before

Shift+F1: add half a line of white before

Ctrl+F1: remove 1 pt space before

F2: add 1 pt space after

Shift+F2: add half a line of white after

Ctrl+F2: remove 1 pt space after

 

These very simple scripts have saved me an enormous amount of time over the years.

 

P.

 

// Add 1 pt space before (to add e.g. 1 mm, use '1mm')

try {
  app.selection[0].spaceBefore += 1;
} catch (e) {
  alert (e.message);
}

 

// Add half a line of white before

function leading (p) {
  if (p.leading == Leading.AUTO) {
    return (app.selection[0].pointSize * p.autoLeading) / 100;
  }
  return p.leading;
}


try {
  par.spaceBefore += leading (par) / 2;
} catch (e) {
  alert (e.message);
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

Mr Peter Kahrel, You are a lifesaver!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 17, 2021 Oct 17, 2021

Copy link to clipboard

Copied

Mr. Kahrel, thank you for this amazing script. It is wonderful! How useful !!!
And adding, as you suggest, a keyboard shortcut to run it, is the perfect solution I was looking for.

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

I agree, this is very useful Peter! Way to solve what I see as an oversight by the InDesign team. I have packaged the scripts as rtf files (this msg board doesn't support posting .jsx). So change the suffix to .jsx and put into the 'Scripts Panel' folder... they should probably be a part of any power users install.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Thanks, David. In the meantime I put the scripts on CreativePro's website:

https://creativepro.com/files/kahrel/indesign/fine-tune-paragraph-spacing.html

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 26, 2023 Oct 26, 2023

Copy link to clipboard

Copied

Super helpful, as I have to basealign everything for a publisher client. 

I see the scripts on CPro lead with "app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS".
When I first ran it, it added 1p, since my default unit was 1p. I changed my default unit to Points, and now it works. It doesn't work for me to do this as noted above:

(to add e.g. 1 mm, use '1mm')

 I tried putting 1pt in the script and it errored on the pt.

If I select a range of paragraphs, it doesn't apply to all, just the one where the cursor is. A range would be nice.

What I'd really love to do is search the selection for a specific paragraph style and increment only that style. My text alternates like H1, P, H1, P, and I can only add space above the H1s. I know I could search the H1s and change to a different style, like H1+p1, but that's impractical for many reasons.

 Scripts and GREP are always a lifesaver!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2023 Oct 26, 2023

Copy link to clipboard

Copied

If your styles are all base-aligned, why would you use this override tweaking at all?


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

Hi James,

Not sure I understand your question... my styles do not result in base-align automatically, unfortunately. I have to tweak every page to hit the base-align (both columns and spreads) and that means addeing equal space above, say, all 5 H1s in a column to try to hit base-align. This is hard with the intervening paragraphs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

Perhaps I'm misreading this topic. I meant enabling a baseline grid, then mapping the styles to align to it. With that setup, there's no need to micro-tweak spacing to 'hit the baseline' (which I take to mean the bottom margin).

 

I'm just not a fan of "fixing on the fly" for long layout, but few of my projects are "one and done"; I need them to be stable for future revisions and editions. (I'm even less a fan of local-override tweaking, for that and more general reasons.)


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

I don't have that option, since I am not the publisher/designer. If I were starting from scratch and creating book specs for my client, yes, I would design my styles that way.  This is what my client requires, unfortunately. They have detailed specs for above and below all styles, then tell me to override them all on a page by page basis to base-align the pages. It's not wise, for sure, but I am the production grunt here, not the one setting the specs. This is freelance book production life, and I believe even the famous Peter Kahrel experiences this, as his great script suggests. 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

All understood. I usually have the luxury of controlling production specs and tend to pass on ones where such things are dictated to me against best professional judgment. 🙂


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

I could be wrong, but I think James might be suggesting a use of baseline-grid, (and possibly object-styles) which might more effectively solve things in an automated manner. But of couse, I have no idea as to the exact challenges you might be facing in the layout/pieces that might prohibit that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 26, 2023 Oct 26, 2023

Copy link to clipboard

Copied

I am using this:

https://youtu.be/P28LMcaRspk?si=De_UkMb1v8NFGloy

Can be adapt for paragraphs spacing, or combined with script what was posted here. 

Amazing useful btw 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

That is an interesting video. I don't really need anything but what I said above, adding 1pt or 2pt to selected paragraphs, but ideally exclusive by style. That's a lot to control, I realize. And I'm on a Mac, which makes so many things more difficult.  I would probably prefer to use a keyboard shortcut instead of mouse wheel, but it does sound interesting.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

The script you mentioned was designed for a purpose. What you're after is to balance certain headings so that the baseline of the text frame's last line is on the frame's bottom. For that, too, I used a script. Here it is.

 

You specify the paragraph style names to target in the second line of the script.

 

To use the script, select the text frame and run the script. It determines the space between the bottom of the text frame and the last line's baseline, divides it by the number of headings on the page, and adds that to each paragraph's space-before. If a heading is at the top of the page it's ignored (because setting spaceBefore on the frame's first paragraph has no effect).

 

(function () {
    
  var headingStyles = ['SecA', 'SecB', 'SecC'];

  function findHeadings (p) {
    var a = [];
    var re = new RegExp ('^(' + headingStyles.join('|') + ')$');
    for (var i = p.length-1; i >= 0; i--) {
      if (p[i] != app.selection[0].paragraphs[0]
          && re.test (p[i].appliedParagraphStyle.name)) {
        a.push (p[i]);
      }
    }
    return a;
  }

  if (app.selection.length === 0 
      || !(app.selection[0] instanceof TextFrame)) {
    exit();
  }

  var headings = findHeadings (app.selection[0].paragraphs.everyItem().getElements());
  if (headings.length === 0) {
    exit();
  }

  var gap = app.selection[0].geometricBounds[2] 
              - app.selection[0].lines[-1].baseline;
  var delta = gap / headings.length;

  for (var i = 0; i < headings.length; i++) {
    headings[i].spaceBefore += delta;
  }
}());

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 29, 2023 Oct 29, 2023

Copy link to clipboard

Copied

Thanks, Peter! That's very interesting. It may motivate me to re-do some documents with two separate text frames for columns, so I can run it separately for each column. I look forward to further experimentation with this.

Best Regards,

Carol

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 29, 2023 Oct 29, 2023

Copy link to clipboard

Copied

I'm late to the party and maybe I'm also missing the point - but TextFrame can be justified vertically... 

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

Vertically justifying a text frame is almost always problematic. You can't specify where the space should be added; it often adds leading, which is a mortal sin; and it usually slows down InDesign.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

Indeed, @Robert Tkaczyk , that is so indiscriminate, the text would be a mess. 

"My text alternates like H1, P, H1, P, and I can only add space above the H1s."

Client has very strict rules about where space above is allowed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

That's why I've started my sentence from "I'm late to the party and maybe I'm also missing the point "... 

 

In some circumstances it wouldn't be a problem - in your situation - it won't work. 

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

@bracewell4213 

Hold your horses, Carol. The script is very easy to change so that it targets a column rather than the whole frame.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

@Peter Kahrel , that's excellent to hear. I have homework to do. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

@bracewell4213 

Don't bother. Below is an upgraded version of the script. It has two modes:

1. Select a text frame and all text columns are targeted.

2. Click in a text column, and only that column is targeted.

 

I also added something I remember I had in the script I used to have (but can't find), namely, a limit to the space to be added before the designated paragraphs. In the script you see the line

 

var maxAdd = 6;

 

which stipulates that not more than 6 points can be added to headings. Change that to any value you that meets your customer's specs.

 

 

// Select a frame to fill all columns in the frame
// Click in a text column to target just that column

(function () {

  app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
  
  // Specify the names of the paragraph styles to target
  var headingStyles = ['SecA', 'SecB', 'SecC'];
  
  // Specify the maximum amount (in points)
  // that can be added before a style
  var maxAdd = 6;
  
  var re = new RegExp ('^(' + headingStyles.join('|') + ')$');
  var columns = [];
  var i, j;
  var frame, headings, gap, delta;

  // Return the headings in a column
  
  function findHeadings (column) {
    var a = [];
    var p = column.paragraphs.everyItem().getElements();
    for (var i = p.length-1; i >= 0; i--) {
      if (p[i] != column.paragraphs[0] 
          && re.test (p[i].appliedParagraphStyle.name)) {
        a.push (p[i]);
      }
    }
    return a;
  }

  if (app.selection.length === 0) {
    exit();
  }
  
  if (app.selection[0] instanceof TextFrame) {
    columns = app.selection[0].textColumns.everyItem().getElements();
    frame = app.selection[0];
  } else if (app.selection[0].hasOwnProperty ('baseline')) {
    columns = [app.selection[0].textColumns[0]];
    frame = app.selection[0].parentTextFrames[0];
  } else {
    exit();
  }

  for (i = 0; i < columns.length; i++) {
    
    headings = findHeadings (columns[i]);
    if (headings.length === 0) {
      continue;
    }

    gap = frame.geometricBounds[2] - columns[i].lines[-1].baseline;
    delta = gap / headings.length;
    if (delta <= maxAdd) {
      for (j = 0; j < headings.length; j++) {
        headings[j].spaceBefore += delta;
      }
    }
  }
}());

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines