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

Centering Left-aligned Text On Longest Line Per Page

Participant ,
Aug 13, 2017 Aug 13, 2017

Copy link to clipboard

Copied

I am working on a book of poems. I need to make sure that the (left aligned) text running within each page is centred on the longest line. As far as I am aware there is no mechanism for doing this automatically in inDesign and besides, the optical centre will always be different from the actual centre.

So I need to manually add an indent to every page to indent the text until it feels centred on the page. My problem is that some of the stanzas/paragraphs run between two pages which each need different indentation. I can only apply indent to a whole paragraph, meaning it will effect the beginning of the paragraph on one page and the end on another. If the second page requires a different indent this means the end of the paragraph that has run over from the previous page will indented correctly for the previous page and not the current page or vice-versa.

Is there any sensible solution to this problem?

Views

2.7K

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 , Aug 13, 2017 Aug 13, 2017

I've had some good fun setting poetry in the past. Most of it can be scripted. As Ariel and Bill mentioned, each line should be a separate paragraph. Then you can left-align the lines and centre the page on the longest line using the following script:

Select a text frame, then run the script

if (app.selection.length && app.selection[0] instanceof TextFrame) {

  frame = app.selection[0];

  longest = Math.max.apply (null, frame.lines.everyItem().endHorizontalOffset);

  indent = (frame.geometricBounds[3

...

Votes

Translate

Translate
New Here ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

LATEST

I can't figure out how to delete this double comment—sorry, folks!

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 ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

Hi there! I'm trying to use this script for a memoir I'm typesetting (with mixed content—some normal paragraph styles, with poems intersperced throughout). 

 

I changed the paragraph style to my own, but when I try to run the script, I'm getting a JavaScript Error:

Screen Shot 2022-05-31 at 12.25.28 PM.png

It seems like something in line 9 is causing the issue and it's probably a simple fix... but this is the ceiling of my JavaScript knowledge. Please help—thank you SO much!

 

Thanks! Pasting full code below:

/*

    0190_PoetryLines_MichelAllio.jsx
    based on an orginal code written by Peter Kahrel | See: https://forums.adobe.com/thread/2370094
    Written 2017/08/13

*/

app.doScript(main, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Poetry Lines! …" );

function main()      
{
    var myDoc = app.activeDocument,
    myPages = myDoc.pages,
    P = myPages.length,  p;    

    for ( p = 0; p < P; p++ )
	{  
        var myFrames = myPages[p].allPageItems,
        F = myFrames.length,  f;

        for ( f = 0; f < F; f++ ) {
            var myFrame = myFrames[f];
			
            if ( myFrame instanceof TextFrame && myFrame.contents.length > 0 )
			{
               var longest = Math.max.apply (null, myFrame.lines.everyItem().endHorizontalOffset); 
               var indent = (myFrame.geometricBounds[3]/2) - (longest/2);
                myFrame.lines.everyItem().leftIndent = indent;
            }   
        }
    }

    var myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
    var P = myParas.length,  p;    
    for ( p = 0; p < P; p++ ) myParas[p].appliedParagraphStyle != myDoc.paragraphStyles.item("Poem Body–A (Ljust) START") && myParas[p].clearOverrides();
};

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 ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

FWIW: I marked Peter Kahrel's post from Aug 13, 2017 as the Correct one.

Why? It contains the core code for solving this issue.

 

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