0

I would like to format paragraphs as shown in the picture below, i. e. paragraphs such that the last n lines of the paragraph are centered and of linearly decreasing width. (n is constant from paragraph to paragraph.)

Paragraph shape

The paragraph does not have a predefined total number of lines and may a priori extend over several pages.

\documentclass{article}

\begin{document}

\parshape=9
0.40\linewidth  0.2\linewidth
0.35\linewidth  0.3\linewidth
0.30\linewidth  0.4\linewidth
0.25\linewidth  0.5\linewidth
0.2\linewidth   0.6\linewidth
0.15\linewidth  0.7\linewidth
0.1\linewidth   0.8\linewidth
0.05\linewidth  0.9\linewidth
0\linewidth     1\linewidth
\noindent
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam mollis fermentum nisi vitae luctus. Vestibulum libero tellus, facilisis et ultricies sed, pretium quis eros. Nunc hendrerit lacinia augue, eu placerat nisi efficitur quis. Sed sed auctor sapien. Donec mattis fermentum mauris, vel maximus orci porta eu. Pellentesque ornare odio at massa facilisis, quis consectetur massa volutpat. Morbi tempus hendrerit lorem id luctus. Nulla id tellus cursus, sagittis neque et, sagittis ipsum. Donec gravida lorem velit, at congue odio tristique condimentum. Nulla sed semper arcu, id fringilla erat. Fusce eleifend, risus vel molestie fermentum, mi mi rhoncus leo, finibus sollicitudin augue lorem et ex. Nam pellentesque massa et mauris consectetur, sed aliquet metus pretium. Nam sed urna id mi fermentum consectetur ut in lacus. Donec laoreet nunc ac diam ornare, sit amet interdum nulla porta. Curabitur lectus sem, rhoncus sit amet mattis ac, lobortis vel dolor. Donec dignissim vitae mauris et iaculis. Sed porta lectus eu eros convallis, ut vulputate mauris vestibulum. Nunc quis pretium ante. Nam dapibus leo et felis molestie, quis posuere purus aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin tristique ut ipsum ac facilisis. Etiam suscipit magna tellus. In ornare quam id accumsan tincidunt. Vivamus cursus quam vitae neque tempus tempor. Mauris scelerisque lacinia nisl a mollis. Quisque vestibulum, mauris non semper volutpat, ante quam ultrices ligula, id vulputate mi felis eu leo. Integer commodo iaculis nulla. Etiam ut luctus ipsum, nec feugiat lectus. Mauris erat sapien, eleifend viverra ante sed, efficitur porta enim. Nam nec arcu ante. Mauris auctor tincidunt molestie. Praesent non sem blandit, pretium metus a, condimentum felis. Nunc rutrum volutpat mi nec pharetra. Duis ultricies sollicitudin sagittis. Curabitur vitae dui tempor, egestas enim eu, eleifend libero. Aliquam ac congue felis. Curabitur tristique ex sed augue imperdiet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam mollis fermentum nisi vitae luctus. Vestibulum libero tellus, facilisis et ultricies sed, pretium quis eros. Nunc hendrerit lacinia augue, eu placerat nisi efficitur quis. Sed sed auctor sapien. Donec mattis fermentum mauris, vel maximus orci porta eu. Pellentesque ornare odio at massa facilisis, quis consectetur massa volutpat. Morbi tempus hendrerit lorem id luctus. Nulla id tellus cursus, sagittis neque et, sagittis ipsum. Donec gravida lorem velit, at congue odio tristique condimentum. Nulla sed semper arcu, id fringilla erat. Fusce eleifend, risus vel molestie fermentum, mi mi rhoncus leo, finibus sollicitudin augue lorem et ex. Nam pellentesque massa et mauris consectetur, sed aliquet metus pretium. Nam sed urna id mi fermentum consectetur ut in lacus. Donec laoreet nunc ac diam ornare, sit amet interdum nulla porta. Curabitur lectus sem, rhoncus sit amet mattis ac, lobortis vel dolor. Donec dignissim vitae mauris et iaculis. Sed porta lectus eu eros convallis, ut vulputate mauris vestibulum. Nunc quis pretium ante. Nam dapibus leo et felis molestie, quis posuere purus aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin tristique ut ipsum ac facilisis. Etiam suscipit magna tellus. In ornare quam id accumsan tincidunt. Vivamus cursus quam vitae neque tempus tempor. Mauris scelerisque lacinia nisl a mollis. Quisque vestibulum, mauris non semper volutpat, ante quam ultrices ligula, id vulputate mi felis eu leo. Integer commodo iaculis nulla. Etiam ut luctus ipsum, nec feugiat lectus. Mauris erat sapien, eleifend viverra ante sed, efficitur porta enim. Nam nec arcu ante. Mauris auctor tincidunt molestie. Praesent non sem blandit, pretium metus a, condimentum felis. Nunc rutrum volutpat mi nec pharetra. Duis ultricies sollicitudin sagittis. Curabitur vitae dui tempor, egestas enim eu, eleifend libero. Aliquam ac congue felis. Curabitur tristique ex sed augue imperdiet.

\end{document}

The command \parshape would be fine, however, it applies to the first line of the paragraph and the (n-1) following lines (as in MWE). Ideally, \parshape should be applied to the last line as well as to the (n-1) previous lines.

After researching the subject, I did not see anywhere that it was possible to do that. I discovered the shapepar package, but this one is not very appropriate.

Do you have any idea how to do this?

3
  • You can pre-format the paragraph in a savebox and measure the height, but changing the width will change the height non-linearly due to line breaking. Somewhat related, tex.stackexchange.com/questions/476474/… – John Kormylo Jul 12 '20 at 19:45
  • Thank you for your message. The problem with the shapepar package is that it does not allow a fixed decrease in line width since it depends on the total length of the paragraph in question. In addition, it does not allow page breaks. – Bastien Jul 13 '20 at 18:09
  • 1
    Have you seen tex.stackexchange.com/q/19833 ? – Thérèse Jul 13 '20 at 22:45
1

Now if you want the last line to end perfectly at the end, that is a whole other problem.

\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}

\newcommand{\weirdpar}[1]% #1 = a single paragraph
{\bgroup% use local definitions
  \def\parshapeargs{9
  0.40\columnwidth 0.2\columnwidth 
  0.35\columnwidth 0.3\columnwidth 
  0.30\columnwidth 0.4\columnwidth 
  0.25\columnwidth 0.5\columnwidth 
  0.2\columnwidth  0.6\columnwidth 
  0.15\columnwidth 0.7\columnwidth 
  0.1\columnwidth  0.8\columnwidth 
  0.05\columnwidth 0.9\columnwidth
  0pt \columnwidth}%
  \setbox0=\vbox{\parshape\parshapeargs #1}% get approximate height
  \dimen0=\dimexpr \ht0+\dp0\relax
  \count1=\numexpr \dimen0 / \baselineskip\relax
  %\unvbox0
  %\the\count1
  \dimen0=0pt
  \dimen1=\columnwidth
  \dimen2=0.05\columnwidth
  \edef\parshapeargs{\the\count1}%
  \loop
    \ifnum\count1<9
      \advance\dimen0 by \dimen2
      \advance\dimen1 by -2\dimen2
    \fi
    \edef\parshapeargs{\parshapeargs\space\the\dimen0\space\the\dimen1}%
    \advance\count1 by -1
  \ifnum\count1>0 \repeat
  \parshape\parshapeargs #1\par
\egroup}

\begin{document}
\weirdpar{\LipsumPar{1}}
\end{document}

demo

2
  • Thank you, the page break problem is solved. But what bothers me a bit is that the number n of lines that make up the "_/"-shape is not constant from one paragraph to the next. Ideally the last line should occupy the whole width, yes. But that's not very important. Maybe adding \parfillskip=0pt can work? – Bastien Jul 14 '20 at 16:18
  • I left room for 8 lines of taper, but ran out of text in the middle of the 7th line. If you replace the <9 with <10 you will fill the rest of the taper and still have text left over. \parfillskip=0pt helps, but can't expand THAT much. You will need to adapt the taper to how much text your have. – John Kormylo Jul 15 '20 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.