Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'll try to illustrate what I want to accomplish. I want an enviroment/page style for poems that works like this -- the title (if present) is placed in the title placeholder (purple).

The body of the poem is placed at the center of the page (gray).

enter image description here

That should work independently of how the poem is wide or long, up until until the distance from the title to poem reaches some length (green). After that, the center is moved below so that the poem fills the page up to the lower margin (blue).

For poems without title, I should be able to choose either filling them to the title placeholder bottom - greenlinelength or up to the title placeholder top.

Basically I should be able to measure the widest line in the poem, and then how long will it be if placed in a box as wide as the widest line. The positioning calculations should are simple enough. I guess I could then position my boxes using textpos. Do you have any suggestions?

enter image description here

share|improve this question
1  
a simple \vfill doesn't solve your problem? You can do something like \newenvironment{verticalcenteredverse}{\vfill\begin{verse}}{\end{verse}\vfill}‌​... It will get your poem vertically centered, except for those too long for one single page... –  henrique Jun 15 '11 at 13:48
1  
@henrique This will solve the vertical centering, but not the horizontal centering. (And \centering) wont solve that part, since you don't want to make the individual lines of the poem centred. –  Alan Munn Jun 15 '11 at 14:30
    
@Alan: I would be satisfied with individual lines centered. –  ipavlic Jun 15 '11 at 14:34
1  
Usually poems are formatted quite specifically by their authors, so I don't think that centring every poem is actually a wise choice. I've posted an answer that gets most of what you want. Maybe others will suggest a better way of dealing with the vertical centring for long poems. –  Alan Munn Jun 15 '11 at 14:50

2 Answers 2

up vote 6 down vote accepted

Without any package other than geometry

This lacks many of the features of the verse environment, but has all the properties you need. Some adjustment might be necessary, the dimensions I set are a bit arbitrary. The pass option to geometry makes it accept the default class setting, but allows us to use its features, particularly \newgeometry.

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[pass]{geometry}

\newsavebox\poembox
\newsavebox\poemtitlebox
\newcommand{\settitle}[1]{%
  \vbox{\let\\\cr\halign{\hfil##\hfil\cr#1\crcr}}}
\newenvironment{poem}[1]
  {\newpage\newgeometry{margin=0pt}%
   \sbox\poemtitlebox{\settitle{#1}}%
   \setbox\poembox=\vbox\bgroup
     \obeylinescr\halign\bgroup##\hfil\cr}
  {\crcr\egroup\egroup
   \ifdim\dimexpr\ht\poemtitlebox+\ht\poembox>.7\pdfpageheight\relax
     \displacedpoem
   \else
     \centeredpoem
   \fi
   \clearpage\restoregeometry}

\def\obeylinescr{\catcode`\^^M=13
  \begingroup\lccode`\~=`\^^M\lowercase{\endgroup\let~}\cr}

\def\centeredpoem{\vbox to 0pt{\vspace*{1cm}\centerline{\box\poemtitlebox}\vss}
  \vfill\centerline{\box\poembox}\vfill}

\def\displacedpoem{\vspace*{1cm}\centerline{\box\poemtitlebox}
  \vfill\centerline{\box\poembox}\vspace*{1cm}}

\usepackage{lipsum}

\begin{document}

\lipsum[1-2]

\begin{poem}{La vispa Teresa\\\emph{Luigi Sailer}}
La vispa Teresa
avea tra l’erbetta
A volo sorpresa
gentil farfalletta
E tutta giuliva
stringendola viva
gridava distesa:
``L'ho presa! L'ho presa!''.

A lei supplicando
l'afflitta gridò:
``Vivendo, volando
che male ti fo?
Tu sì mi fai male
stringendomi l'ale!
Deh, lasciami! Anch'io
son figlia di Dio!''.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.
\end{poem}

\lipsum[3-4]

\begin{poem}{La vispa Teresa\\\emph{Luigi Sailer}}
La vispa Teresa
avea tra l’erbetta
A volo sorpresa
gentil farfalletta
E tutta giuliva
stringendola viva
gridava distesa:
``L'ho presa! L'ho presa!''.

A lei supplicando
l'afflitta gridò:
``Vivendo, volando
che male ti fo?
Tu sì mi fai male
stringendomi l'ale!
Deh, lasciami! Anch'io
son figlia di Dio!''.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.
\end{poem}

\begin{poem}{La vispa Teresa\\\emph{Luigi Sailer}}
La vispa Teresa
avea tra l’erbetta
A volo sorpresa
gentil farfalletta
E tutta giuliva
stringendola viva
gridava distesa:
``L'ho presa! L'ho presa!''.

A lei supplicando
l'afflitta gridò:
``Vivendo, volando
che male ti fo?
Tu sì mi fai male
stringendomi l'ale!
Deh, lasciami! Anch'io
son figlia di Dio!''.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.
\end{poem}

\begin{poem}{La vispa Teresa\\\emph{Luigi Sailer}}
La vispa Teresa
avea tra l’erbetta
A volo sorpresa
gentil farfalletta
E tutta giuliva
stringendola viva
gridava distesa:
``L'ho presa! L'ho presa!''.

A lei supplicando
l'afflitta gridò:
``Vivendo, volando
che male ti fo?
Tu sì mi fai male
stringendomi l'ale!
Deh, lasciami! Anch'io
son figlia di Dio!''.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.

Teresa pentita
allenta le dita:
``Va', torna all'erbetta,
gentil farfalletta''.
Confusa, pentita,
Teresa arrossì,
dischiuse le dita
e quella fuggì.
\end{poem}

\end{document}

Using the verse package

\usepackage{verse}
\newenvironment{versepoem}[2]
  {\newpage\newgeometry{margin=0pt}%
   \sbox\poemtitlebox{\settitle{#1}}%
   \settowidth{\versewidth}{#2}
   \setbox\poembox=\vbox\bgroup\hsize=\versewidth
     \begin{verse}[\versewidth]}
  {\end{verse}\egroup\showthe\wd\poembox
   \ifdim\dimexpr\ht\poemtitlebox+\ht\poembox>.7\pdfpageheight\relax
     \displacedpoem
   \else
     \centeredpoem
   \fi
   \clearpage\restoregeometry}

...
\begin{versepoem}{La vispa Teresa (versepoem)\\\emph{Luigi Sailer}}{``L'ho presa! L'ho presa!''.}
La vispa Teresa\\
avea tra l’erbetta\\
A volo sorpresa\\
gentil farfalletta\\
E tutta giuliva\\
stringendola viva\\
gridava distesa:\\
``L'ho presa! L'ho presa!''.

A lei supplicando\\
l'afflitta gridò:\\
``Vivendo, volando\\
che male ti fo?\\
Tu sì mi fai male\\
stringendomi l'ale!\\
Deh, lasciami! Anch'io\\
son figlia di Dio!''.\\

Teresa pentita\\
allenta le dita:\\
``Va', torna all'erbetta,\\
gentil farfalletta''.\\
Confusa, pentita,\\
Teresa arrossì,\\
dischiuse le dita\\
e quella fuggì.
\end{versepoem}

The versepoem environment needs two arguments: the title and the widest verse. All the preceding code is needed, except for the definition of the poem environment. Of course also \usepackage{verse} is required.

share|improve this answer
    
Would there be a way to combine our two answers? (Adapt your solution to the verse package?) –  Alan Munn Jun 15 '11 at 15:30
1  
@Alan: yes, by using the verse environment instead of the \halign. This has the defect that the length has to be stated in advance, which is not needed with my code. I'll add this version later (now I've to catch a train). –  egreg Jun 15 '11 at 15:35
1  
@Alan: I've added the version with verse –  egreg Jun 16 '11 at 10:59

The verse package provides extensive methods for setting poetry. So for setting the poems themselves, you should probably use that. verse deals with horizontal centring by explicitly setting the verse width to the length of the longest line. It doesn't do this automatically.

Here's a sample document to get you going. The vertical spacing for long poems is tricky though; simply wrapping the verse in \vfill gets you part of the way, but not in the case of a long poem where you need a minimum gap.

For very short poems, this sort of formatting looks a bit odd, IMO, in which case you might want to use \vfil for the first vfill.

\documentclass{article}

\usepackage{verse}
\renewcommand{\poemtoc}{subsection}

\begin{document}
\poemtitle{A Limerick}
\settowidth{\versewidth}{There was an old party of Lyme}
\vfill
\begin{verse}[\versewidth]
There was an old party of Lyme \\ 
Who married three wives at one time. \\
    \vin When asked: `Why the third?' \\
    \vin He replied: `One’s absurd, \\ 
And bigamy, sir, is a crime.'
\end{verse}
\vfill
\end{document}
share|improve this answer
    
How does \vfil differ from \vfill? –  BeSlayed Jun 16 '11 at 11:58
    
@BeSlayed This isn't easy to explain in a comment. But it's a really good question, so I would recommend asking it as a regular question. (And there are plenty of people here who would give a better answer to it that I probably would.) –  Alan Munn Jun 16 '11 at 13:23
    
@BeSlayed: it's an order of infinity larger. If you put \vfil above and \vfill below the text will be at the top of the page. In fact, if you put \vskip 100fil at the top and \vskip 0.0001fill at the bottom the text will still be at the top of the page. –  Matthew Leingang Jun 16 '11 at 13:24
    
For good answers to the fil vs. fill distinction, see What is the difference between 'fil' and 'fill' –  Alan Munn Aug 18 '11 at 19:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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