Journal home page
General information
Submit an item
Download style files
Copyright
Contact us
logo for The PracTeX Journal TUG logo

Ask Nelly:
      How do I center only the last line of a paragraph?
      How do I get the first and last entry of each index page in its header?

The Editors

Abstract


Ask Nelly is a question and answer column. Nelly is the quiet person who sits at the back corner desk, who knows a lot, and when asked any question is always ready with a patient answer. If Nelly doesn't know the answer, Nelly will know an expert who has the answer. Feel free to Ask Nelly about any aspect of LaTeX, TeX, Context, etc.


tpjlogo

Q: Dear Nelly: Sometimes I need to write centered paragraphs of text. I want the paragraph to be fully justified, but the last line to be centered. How do I achieve that? I work in Plain TeX.

A: Normally centering a paragraph is achieved by setting equal stretch and shrink amounts for \leftskip and \rightskip and setting \parindent and \parfillskip to zero.

A slight variation on this theme fully justifies all lines except the last one, which will be centered.

        \leftskip = 0cm plus 0.5fil
        \rightskip = 0cm plus -0.5fil
        \parfillskip = 0cm plus 1fil
        
The stretch components for all lines of a paragraph except the last one are 0, so zero space is inserted by \leftskip and \rightskip. On the last line of the paragraph the \parfillskip adds 1fil of stretch, bringing the total for both ends of the line to 0.5fil and thus centering the line.


The above question was answered by Yuri Robbers, a member of the editorial board of this journal. He can be reached at

tpjlogo

Q: Dear Nelly: I'd like to have the page headers for my index list the first and last entry on the page, for easier reference. Dictionaries and encyclopaedias tend to do this too. How can I do this in LaTeX?

A: To achieve this, we will use the fancyhdr package by Piet van Oostrum and makeindex by Pehong Chen, both available on most TeX systems and all CTAN mirrors.

First we define a page style specifically for the index:

        \pagestyle{index}
        \fancyhead{}
        \fancyhead[RO,LE]{\rightmark -- \leftmark}
        
Then we define a new command
        \newcommand{\indexmark}[1]{#1\markboth{#1}{#1}}
        
Then we add the following lines to the configuration file for makeindex
        item_0 "\n\\item \\indexmark{"
        delim_0 "},"
        
And if you ever upgrade to encyclopaedias or dictionaries you may run into a definition that spans more than one page. In that case you may want to replace the last line op the page style definition with
        \fancyhead[RO,LE]{%
          \ifthenelse{\equal{\leftmark}{\rightmark}}%
            {\rightmark}%
            {\rightmark -- \leftmark}%
        }
        
And then of course do not forget to issue a
        \pagestyle{index}
        
at the beginning of your index.


The above question was answered by Yuri Robbers, a member of the editorial board of this journal. He can be reached at

tpjlogo


Page generated June 9, 2010 ;

TUG home page; webmaster; facebook; twitter; mastodon;   (via DuckDuckGo)