Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Formatting text to a pyramid shape

Formatting text to a pyramid shape

Scheduled Pinned Locked Moved Algorithms
questioncss
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KaptinKrunch
    wrote on last edited by
    #1

    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.

    A 1 Reply Last reply
    0
    • K KaptinKrunch

      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.

      A Offline
      A Offline
      Alan Balkany
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups