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

Automatically change line spacing depending on total line count in text frame

New Here ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

I need to fill a text frame with a fixed height with text that needs to be vertically centered and, depending on the amount of text (lines), automatically have a different line spacing (leading).

Let’s say the text frame height is 100mm, font size is 12pt, leading 20pt and we only have text for 1 line. Then the line spacing is not important, it will just align vertically centered. Then we add more text so it fill’s to 2 lines. Now the leading need’s to down to 18pt. We add more text so it fill’s to 3 lines, now the leading need’s to go down to 14pt. etc.

 

I think it could be done with GREP…

TOPICS
How to , Scripting

Views

450

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 2 Correct answers

Community Expert , Jul 15, 2020 Jul 15, 2020

GREP is probably totally out of the question, it does not handle "x number of lines".

It sounds you just need Vertical Justification for that text frame.

Votes

Translate

Translate
Enthusiast , Jul 15, 2020 Jul 15, 2020

How the text will be entered? Do you want this as a live behaviour?

Or just want to enter text using script and then change the leading based on the text?

 

To enter text using javascript and change the leading, you can use something like:

var doc = app.activeDocument;
var sel = app.selection[0];
var st = sel.parentStory;

sel.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
st.justification = Justification.CENTER_ALIGN;

st.pointSize = 12;

if (st.contents == "") {
	
...

Votes

Translate

Translate
Community Expert ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

GREP is probably totally out of the question, it does not handle "x number of lines".

It sounds you just need Vertical Justification for that text 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
Enthusiast ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

How the text will be entered? Do you want this as a live behaviour?

Or just want to enter text using script and then change the leading based on the text?

 

To enter text using javascript and change the leading, you can use something like:

var doc = app.activeDocument;
var sel = app.selection[0];
var st = sel.parentStory;

sel.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
st.justification = Justification.CENTER_ALIGN;

st.pointSize = 12;

if (st.contents == "") {
	st.contents = "One line of text.";
	st.leading = 20;
	}
else {
	st.contents += "\rAnother line of text.";
	st.leading -= 2;
	}

 

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 ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

I wan't to have it as a "live" behaviour. So as you start typing (our copy paste) into the text-frame it will change the leading if it jumps to the next line, and the next etc... Mabye I want somthing that isn't possible in InDesign. I think the problem is that InDesign can't give feedback on how many line's a text-frame contains (apart from line breaks '\r'). Any ideas...

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 ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

Do as Jongware said: set the text frame's vertical justification to justify and you get exactly the behaviour that you want.

P.

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 ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

Hi martv26823449,

I still can't see the whole picture. At some point, very soon, the lines of text will overlap.

When exactly this would happen will depend on the typeface and the contents of the text.

Can you do a screenshot what you do expect when?

 

FWIW: What's the purpose decreasing the leading?

Is there an overall maximum height of text that should not or never be met?

 

Regards,
Uwe Laubender

( ACP )

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
LEGEND ,
Jul 25, 2020 Jul 25, 2020

Copy link to clipboard

Copied

LATEST

Hi there,

 

Thanks for reaching out. I hope your issue is resolved now. We'd appreciate if you can mark the appropriate answer correct.

If you used any other method, please share it here. It'll help other users having similar concern.

If you still have issues, let us know. We'll be happy to help.

 

Regards,

Ashutosh

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