4

I have a Sanskrit Verse that I want to appear at the center of the page. I am using verse environment as shown below.

\begin{verse}
तपः स्वाध्याय निरतम् तपस्वी वाग्विदाम् वरम् | \\
नारदम् परिपप्रच्छ वाल्मीकिः मुनि पुंगवम् ||
\end{verse}

This does not appear at the center of the page, it appears more to the left of the page. Is there a way to make it appear at the center. I attached the screenshot of the output.

enter image description here

Aku
  • 11,026

2 Answers2

5

Run the example with xelatex or lualatex or use the definition of Verse if you want to run it with pdflatex

\documentclass{article}
\usepackage{fontspec}
\newfontface\Devangari{Devanagari MT}
\usepackage{varwidth}
\newenvironment{Verse}[1][\Devangari]
  {\center#1\varwidth{\linewidth}}
  {\endvarwidth\endcenter}

\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{Verse}
तपः स्वाध्याय निरतम् तपस्वी वाग्विदाम् वरम् | \\
नारदम् परिपप्रच्छ वाल्मीकिः मुनि पुंगवम् ||    
\end{Verse}

\begin{Verse}[]
foo bar\\
baz
\end{Verse}

\end{document}

enter image description here

Without defining the Devangari font:

\documentclass{article}
\usepackage{fontspec}
\usepackage{varwidth}
\newenvironment{Verse}
  {\center\varwidth{\linewidth}}
  {\endvarwidth\endcenter}    
\usepackage{lipsum}
\begin{document}

\lipsum[1]
\begin{Verse}
foo bar\\
baz
\end{Verse}

\end{document}
  • I am using XeLatex, this example as it is working however its not working with my file. I am not sure if any of the packages I am using are in conflict with each other. Can you help me that please. – Aku Aug 22 '11 at 14:30
  • Have you installed the Devangari font? I edited my answer for a run without the special font setting. –  Aug 22 '11 at 14:42
  • Yes I did define the Devanagari font. your example is working like a charm. but not in the file I am working with and could not figure it out whats wrong with it. if you are ok to take a look at then I can upload on google docs and share the link here. – Aku Aug 22 '11 at 14:46
  • ok, let's try it –  Aug 22 '11 at 14:54
  • @Herbet, Balakanda.tex is where all the packages are and 01_Balakanda_009 is where all the verse and actual text is. https://docs.google.com/leaf?id=0B2ORRM7gQAXeM2FiYzJiZjMtYjRkNC00YjkxLTlmMjMtZmE1ODRiMjhiZjE2&hl=en_US
    https://docs.google.com/leaf?id=0B2ORRM7gQAXeMmE3YjBiYmEtNjM2My00YTMxLWJlNTctMjQ5YzM2NmY4ZGNk&hl=en_US
    – Aku Aug 22 '11 at 14:55
  • I get: "Sorry, the page (or document) you have requested is not available." –  Aug 22 '11 at 15:07
  • Sorry for the trouble gmail security. https://docs.google.com/leaf?id=0B2ORRM7gQAXeMmE3YjBiYmEtNjM2My00YTMxLWJlNTctMjQ5YzM2NmY4ZGNk&hl=en_US https://docs.google.com/leaf?id=0B2ORRM7gQAXeM2FiYzJiZjMtYjRkNC00YjkxLTlmMjMtZmE1ODRiMjhiZjE2&hl=en_US – Aku Aug 22 '11 at 15:12
  • I have no problem when using Devanagari MT for the font name. Here you'll find all files and the generated pdf: http://archiv.dante.de/~herbert/Verse.tgz –  Aug 22 '11 at 15:37
  • I uploaded the output screenshot from your method and my method. The Devanagari rendering is different. I want it to appear like the second one but center like yours does. Thanks for your time. https://docs.google.com/leaf?id=0B2ORRM7gQAXeZmVjOGUzMDAtY2QxMC00NGJlLWEyNDMtODljNmQ5YjMyNmU0&hl=en_US – Aku Aug 22 '11 at 16:20
  • then always use the second definition in example above where the Devanagari is not defined. I suppose that I used another type of the font. But your are already using Sanskrit then you do not need the definition of another font for environment Verse –  Aug 22 '11 at 16:28
  • I tried that but as soon as I change it to \begin{Verse} the output changes to first image shown in the previous attachment. The only way it comes correctly is when I change to \begin{verse} it comes correctly but aligned to left. Seems something is not working right in Verse environment with Capital "V". I am new to tex so can not understand this mystery. sorry for so many messages. – Aku Aug 22 '11 at 16:34
  • Thanks a million, it finally worked without the font definition. I deleted everything and started all over based on your example and it worked. Once again thanks for your help. – Aku Aug 22 '11 at 16:43
  • 1
    BTW, the Sanskrit text in your image is incorrectly typeset: it has messed up ligatures and complex script positioning (where a later Unicode character must be displayed to the left of an earlier Unicode character). Compare with the OP's image, which is fine. Presumably he/she has got it working, so it's not important now; just pointing it out. – ShreevatsaR Sep 21 '11 at 16:07
2

You could define a new length to store the width of the longest verse and use this length as a \parbox's width to be centered using a center environment:

\documentclass{article}
\usepackage{lipsum}

\newlength\mylen
\settowidth\mylen{bbbbbbbbbbbbbbbbbbbbb}

\begin{document}

\lipsum[1]
\begin{center}
\parbox{\mylen}{aaaa \\
bbbbbbbbbbbbbbbbbbbbb}
\end{center}

\end{document}

enter image description here

Another option would be to use the verse package and its facilities:

\documentclass{article}
\usepackage{verse}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\settowidth\versewidth{bbbbbbbbbbbbbbbbbbbbb}
\begin{verse}[\versewidth]
aaaa \\
bbbbbbbbbbbbbbbbbbbbb
\end{verse}

\end{document}

If you want each verse to appear centered in its own line, you could simply use a center environment:

\begin{center}
तपः स्वाध्याय निरतम् तपस्वी वाग्विदाम् वरम् | \\
नारदम् परिपप्रच्छ वाल्मीकिः मुनि पुंगवम् ||    
\end{center}
Moriambar
  • 11,466
Gonzalo Medina
  • 505,128