Formatting text to a pyramid shape
-
So I have a project that I've been working on, its a simple form that takes some input, then formats the text on a Word document. I've come close to being able to format the text in a pyramid shape, but it fails when the text is not pre-canned to fit in that shape. Pre-canned text might contain 4 paragraphs, with each paragraph containing more text than the previous. This has been fairly easy to set using constant values for right & left gutters, margins and so forth. Non-canned text is unknown, might have 2 paragraphs, might have 8 paragraphs and the first one containing more than the 3rd but less than the 5th. Its completely unknown. I've searched google and did not find an answer. Question: Is there a formula that can be used to format an unknown amount of text into a pyramid shape? Thanks
Just because we can; does not mean we should.
-
So I have a project that I've been working on, its a simple form that takes some input, then formats the text on a Word document. I've come close to being able to format the text in a pyramid shape, but it fails when the text is not pre-canned to fit in that shape. Pre-canned text might contain 4 paragraphs, with each paragraph containing more text than the previous. This has been fairly easy to set using constant values for right & left gutters, margins and so forth. Non-canned text is unknown, might have 2 paragraphs, might have 8 paragraphs and the first one containing more than the 3rd but less than the 5th. Its completely unknown. I've searched google and did not find an answer. Question: Is there a formula that can be used to format an unknown amount of text into a pyramid shape? Thanks
Just because we can; does not mean we should.
One approach: 1. Put all the text into an array of words (assuming you don't want to split words to fit the pyramid). 2. Write a function that takes a row number and gives the width of the pyramid at that row. (This will depend on the vertex angle of your pyramid.) 3. For each row, construct a string out of the next words that haven't been used yet that minimizes the difference between the string length and that pyramid row width. (It could go over or under the row width.) 4. Center this string at the pyramid row. 5. Repeat until all the words have been used.