is now part of CreativePro.com!

Setting Poetry, Flush Left, Center on Longest Line

35

Every so often I hear a cry for help on the subject of setting poetry. The request is usually something like “how do I set a poem on a page so that the longest line is centered.”

It’s easy to center all the lines on the page, but that’s rarely what publishers want. So how can you keep your text flush-left (left aligned, ragged right) and center that longest line?

My favorite trick is:

  1. Place the whole poem inside a text frame. Make sure no extra blank lines are in there. (The last line should not end with a return.)
  2. Double-click the lower-right text frame handle with the Selection tool. This resizes the frame to fit the text along the right and bottom edges.
  3. Cut the frame to the clipboard with the Selection tool.
  4. Paste the frame into a larger text frame (probably the main text frame that spans from margin to margin on the page) with the Type tool. This pastes the frame in as an inline object on its own paragraph.
  5. Click outside the poem frame, in the larger frame, and choose Horizontal Alignment to center it.

Once you do it two or three times, it goes much faster than it takes to read the above instructions.

Here it is in pictures… first the original text frame:

Poem1

Then, after the poems cut out and paste into their own frames, we double-click the bottom-right handles to Fit Frame to Content:

Poem2

Finally, we paste the frames in as inline objects, and add some headings:

Poem3

Are there other clever ways you have achieved this same result?

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Eugene Tyson says:

    Why not select the paragraphs and then choose Table>Convert to Table and in the Row Separator choose (or something other than so that all the text goes into one cell.

  • Creating a one-celled table is an interesting idea, Eugene. However, getting the width of the cell right is kind of a pain, no? Setting the width with the fit to content double-click trick just seems far easier than trial-and-error dragging.

  • Eugene Tyson says:

    Perhaps dragging the table edge from the right to the length of the longest line would be nearly the same as double clicking. The table length will increase automatically (unless set to Exactly, you’d need it set to At Least).

    If you had lots of poems to set out and inserting them all into a frame and then anchoring could also be rather time-consuming.

    I suppose another issue with the anchored text frame would be that if the font or leading increased the text would become overset – where a tables length could change automatically.

    But you’d have the same issue with the length of the text line in a Table too, if the font size or leading increased – oh why they didn’t give an At Least or Exactly for the width is beyond me :-p

    Both would have some pros and cons. I suppose if you used AutoFit or something with the anchored text frames you could some of these issues?

    Awaits Harbs or Jongware scripting genius…

  • Fred Goldman says:

    I would think the correct way to do this would be to center align the longest line and the set a left aligned tab stop for the other lines positioned at the beginning of the center aligned paragrpah and insert a tab at the beginning of the other paragraphs, or simply set a left indent for the other lines.

  • Richard Groff says:

    The main problem with this is that the text in the separate text frame won’t go along with the rest of the text when output as an epub. What I do in this situation is this: Each poem stanza is a separate paragraph with each line (except the last) ending with a forced line break. I center the stanza with the longest line and place a guide line at the beginning of the longest line. Then I revert to flush left (and select all stanzas if there’s more than one) and set a left indent equal to where the guide line is.

    I think this could be scripted fairly easily. I’ll play with that.

  • rsanders says:

    I never knew about the double-click on the bottom-right-handle! Jeez! How cool!

  • Fred and Richard, I like you suggestions! Instead of placing guides there, however, you can place your cursor at the beginning of the centered-longest-line and look at the Control panel:

    Write down that value (I wish you could Copy it!), then set the horizontal indent back to Left. Now select all the lines of the poem and set a Left Indent equal to that number you just wrote down!

  • Richard Groff says:

    Thanks, David! That’s even faster than MY method. Now I wonder if that’s a variable that can be plucked and used in an Applescript.

  • Fred Goldman says:

    In javascript you would be looking for the character.horizontalOffset, I am not sure what it is called it Applescript.

  • Harbs says:

    Here’s a script I wrote some time back. To get the effect above, you would need to make the lines end in soft returns…
    https://in-tools.com/downloads/indesign/scripts/CenterParagraphIndent.jsx

    Check out the rest of our scripts here: https://in-tools.com/products/scripts/

  • Jongware says:

    Poetry In Javascript.

    p = app.selection[0].paragraphs[0];
    s = p;
    pos = 1e9;
    do
    {
    p.leftIndent = 0;
    l = p.insertionPoints[0].horizontalOffset;
    p.justification = Justification.CENTER_ALIGN;
    if (p.insertionPoints[0].horizontalOffset-l < pos)
    pos = p.insertionPoints[0].horizontalOffset-l;
    p.justification = Justification.LEFT_ALIGN;
    } while ((p = p.parentStory.paragraphs.nextItem(p)) != null && p.contents.length > 1);
    do
    {
    s.leftIndent = pos;
    } while ((s = s.parentStory.paragraphs.nextItem(s)) != null && s.contents.length > 1);

    Run with cursor in first line, runs up to blank line or end of story.

  • Wow! very impressive.

    Now I just need to find some poetry to set …

  • Jongware says:

    Solar flare about to flame.
    The Sun acts up, technology fails.
    My phone goes dead.

  • Richard Groff says:

    @Jongware:

    EXCellent! (on the script AND the haiku)

  • Jeremy says:

    Though Jongware’s script is grand
    It’s hard to understand.
    While “do-while” loops impress,
    The code looks quite a mess.
    Perhaps I’m just brain dead —
    I’d go for “for” instead.
    For “for” loops I can follow —
    But “do-while”s I can’t swallow.
    I’ve one more small complaint
    And call for some restraint!
    A double paragraph?
    C’mon! — Don’t make me laugh!
    What method could be worse
    To demarcate the verse?
    When scripts just work on text
    Do nothing but select!
    That way we can replace
    Blank lines with extra space.
    Try this one out for fun:
    Just select verse, and run.

    var myParagraphs = app.selection[0].paragraphs;
    var mySmallestSoFar = 1000000; //Any number bigger than greatest width in smallest units
    myParagraphs[0].justification = Justification.LEFT_ALIGN;
    myParagraphs[0].leftIndent = 0;
    var myLeftMargin = myParagraphs[0].insertionPoints[0].horizontalOffset;
    for (var i = 0; i < myParagraphs.length; i++) {
    myParagraphs[i].justification = Justification.CENTER_ALIGN;
    myCurrent = myParagraphs[i].insertionPoints[0].horizontalOffset;
    if (myCurrent < mySmallestSoFar) mySmallestSoFar = myCurrent;
    }
    var myIndent = mySmallestSoFar – myLeftMargin;
    myParagraphs.everyItem().justification = Justification.LEFT_ALIGN;
    myParagraphs.everyItem().leftIndent = myIndent;

    //If it works, it's all "borrowed" from Jongware!

  • Jeremy says:

    But lest you think I’m smug
    My “new” one’s got a bug!
    It seems to work first time
    From then on, it’s a crime!
    Can someone please explain
    Why this one’s such a pain?

    (And if you cut and paste to try it out, make sure the minus sign in the third last line is a hyphen. But I wasn’t able to say that in rhyming couplets.)

  • Mike Rankin says:

    I nominate Jeremy for the InDesignSecrets Comment Hall of Fame.

  • Jeremy says:

    But not for the Hall of Competent Scripting!

    Sigh… Why o why, do I ever take on Jongware? My Friday afternoon off is turning into an amateur scripter’s damage limitation exercise…

    I think this one works if you just highlight the verse and run it (no need for a blank paragraph at the end):


    var myParagraphs = app.selection[0].paragraphs;
    var myMax = 0;
    var myCounter = 0;
    for (var i = 0; i < myParagraphs.length; i++) {
    var myWidth =
    myParagraphs[i].characters.lastItem().horizontalOffset -
    myParagraphs[i].characters.firstItem().horizontalOffset;
    if (myWidth > myMax) {
    myCounter = i;
    myMax = myWidth;
    }
    }
    myParagraphs[myCounter].justification = Justification.LEFT_ALIGN;
    myParagraphs[myCounter].leftIndent = 0;
    myMargin = myParagraphs[myCounter].characters.firstItem().horizontalOffset;
    myParagraphs[myCounter].justification = Justification.CENTER_ALIGN;
    myIndent = myParagraphs[myCounter].characters.firstItem().horizontalOffset-myMargin;
    myParagraphs.everyItem().justification = Justification.LEFT_ALIGN;
    myParagraphs.everyItem().leftIndent = myIndent;

  • Harbs says:

    Jeremy,

    What about my script? I’m not much of a poet, but I think it words pretty well. (It’s also legible.) The first one I uploaded had an error (I had not tried it before I uploaded it). It should work correctly now…

    The advantage of my script is that it works with inline frames and works with both right-to-left and left-to-right text…

  • Jeremy says:

    Yes, that’s very nice — I particularly like the use of forced line breaks instead of paragraph returns within verses, as it enables gaps between separate verse to be managed by space before/after in the paragraph style.

    But be clear I wasn’t seriously criticizing anyone’s script (apart from my own first attempt) — I was just trying to be funny (and to rhyme at the same time).

  • Evgeny Trefilov says:

    Unfortunately, longest line is easiest option, but it’s not the perfect way to go. Poetry is centered by optical center, and this is not half of longest line, rather “mass center”. It should take into account not only lines lenghts, but their positions and neighbours.

    I have written a script for this long ago, but anyway it serves only as raw formatting. Further manual adjustments are required in almost any cases.

  • Evgeny Trefilov says:

    ^ If we take last example in article (Lord the air..) I would increase indent and shift it to the right a bit more.

  • Dave Saunders says:

    I come to this a tad late, but I am always so frustrated when InDesign displays a useful number in a panel somewhere, a number that you might very likely want to copy and paste somewhere else and it won’t let you copy it.

    David’s illustration of the Control Panel triggered this little rant.

    Dave

  • I’ve always set the lines of a stanza with line breaks, using a return only after the last line (in fact, I can’t imagine why you’d want to do it any other way), so Harbs’ script fits my workflow perfectly.

    I have to agree with Evgeny, though: manual adjustment will always be required. The same is true when setting almost any text, though. We’re still a very long way from software that can set a book or an article perfectly on its own.

  • Edward Cook says:

    Can anyone give advice on how to style poetry in InDesign in such a way that it looks correct when exported to ePub? Or point me to some resources? Thanks.

  • Edward, you need to use paragraph styles for the different indents, and you may need to edit the CSS after.

    Here’s a great post about it:
    https://bencrowder.net/blog/2011/06/formatting-poetry-epub-kindle/

  • Edward Cook says:

    Thanks Anne-Marie. I’ll do some experimenting with using paragraph styles for this. I’d like to have a workflow where the indents work for ePub and also .mobi after conversion without having to edit the .mobi file.

    By the way, your Lydna.com course on InDesign CS5 to ePub and Kindle has been SO HELPFUL to me. Awesome! One thing: you had us download KindleGen from Amazon but gave no instructions what to do with it after downloading.

  • Valerie says:

    I’ve been designing and setting poetry books for eons now. In poetry, the approach I use is that each line is a paragraph, not each stanza. This is because long lines of poetry need to wrap and form hanging indents — essential to those of you trying to port poetry to mobile devices and Kindles.

    Is there anyone who can write a script that will work with a group of paragraphs, not just one?

    ——
    My strategy for centered formats has long been:
    1. draw a text box from the end of the longest line to the right margin
    2. Divide the box width in half by putting your cursor in the width measurement box and typing “/2”
    3. Move the box to the left margin and turn on runaround.

    Too bad InDesign ignores tabs and indents against a runaround. But that strategy works with many forms of verse. Also you can quickly optically adjust.

  • @Valerie, have you tried Jeremy’s script, above? It seems to work well. Just select all the paragraphs in the poem (even blank ones between verses) and run the script. I’ve uploaded the script here for convenience.

    (You may have to remove the .txt from the end of the file name… it should end with .jsx. To install it, open the Scripts panel in InDesign, then right-click the User folder you see and choose Reveal in Finder/Explorer. Then put the script inside the Scripts Panel folder. You should see it when you return to InDesign.)

  • Valerie says:

    Hello David, and thank you for your speedy reply. I did try that script. It works, but doesn’t work with indents.

    Alas, poets like to indent lines. “Sing me an indent,” I like to say to them, but poetry is now a visual as well as spoken medium, so indents are part of poetry.

    The good news is that the script will take care of a majority of verse.

    Also, regarding this style of setting poetry — I’m convinced, looking at older books, that this style was actually easier to do in the days of lead. It looks very good! But it sure adds to the comp time in the digital age.

  • Valerie says:

    It might work if it could be changed to calculate the difference between the end of the longest line and the column width and then add half of that to the indent for each line rather than resetting the indent for each line . . .

  • Debralea says:

    Old thread, I know, but Jeremy’s script works perfectly for a children’s book I’m setting, in which the text on each page is aligned left but centered on the longest line on that page. A lifesaver.

  • Jayson Mena says:

    How do I locate the longest line?

  • shayari says:

    Hey, I didn’t know about the double-click on the bottom-right-handle.
    This is Awesome, thanks a million.

  • Nigel says:

    Didn’t read through all the replies, but what about putting a guide in the centre of a master page and just aligning the text box centre handle on the guide

  • >