2

In a book project, I'm using \centering to place verses in the center of the page. As expected, the text is laid out such that each line of the verse is centered. I would like to retain the centering for line #1 while forcing the first character of the line #2 to be vertically aligned with the first character of the line #1 of the verse. My MWE is below:

\documentclass{book}
\usepackage{fontspec}

\newenvironment{myverse}
{\nopagebreak\centering}

\begin{document}
% Will replace period with unicode । and ॥ later
\begin{myverse}
dharmakṣetre kurukṣetre samavetā yuyutsavaḥ .\\ 
māmakāḥ pāṇḍavāścaiva kimakurvata sañjaya . 1-1.\\
\end{myverse}

\end{document}

Ouput

In the output, I would like the first letter of line #2 i.e m to be placed directly below d - the first letter of line #1.

Is this possible? If \centering is not the best environment, what can be done to get the desired layout?

3
  • 1
    I think you mean horizontal alignment not vertical, you could just use a verse enviornment, or if you want to centre on the longest line, use a a tabular. Commented Jan 2, 2021 at 16:22
  • 1
    you are also missing the end definition of your enviornment, just avoiding an error as the blank line is taken as the argument to \newenvironment Commented Jan 2, 2021 at 16:25
  • I wasn't aware of this error at all.
    – linuxfan
    Commented Jan 2, 2021 at 16:36

2 Answers 2

3

This is horizontal alignment, not vertical.

You want to left align the text block while centering the block as a whole, so here I use an l column in a centred tabular.

enter image description here

\documentclass{book}
\usepackage{fontspec}

\newenvironment{myverse}
{\begin{center}\begin{tabular}{l}}
{\end{tabular}\end{center}}

\begin{document}
% Will replace period with unicode । and ॥ later
\begin{myverse}
dharmakṣetre kurukṣetre samavetā yuyutsavaḥ .\\ 
māmakāḥ pāṇḍavāścaiva kimakurvata sañjaya . 1-1.\\
\end{myverse}

\end{document}
1
  • thanks for the quick solution!
    – linuxfan
    Commented Jan 2, 2021 at 16:33
2

Try the verse package which lets you control many aspects of typesetting verses. Here is a revision of your MWE, for which thank you.

% verseprob.tex  SE 577265
\documentclass{book}
\usepackage{fontspec}
\usepackage{comment}
\usepackage{verse}
\usepackage{lipsum}
\newlength{\mylength}  % just as a convenience

\newenvironment{myverse}
{\nopagebreak\centering}

\begin{document}
\begin{comment}
% Will replace period with unicode । and ॥ later
\begin{myverse}
dharmakṣetre kurukṣetre samavetā yuyutsavaḥ .\\ 
māmakāḥ pāṇḍavāścaiva kimakurvata sañjaya . 1-1.\\
\end{myverse}
\end{comment}

\lipsum[1]

% the length of a typical line
\settowidth{\mylength}{dharmakṣetre kurukṣetre samavetā yuyutsavaḥ .}

\begin{verse}[\mylength]
dharmakṣetre kurukṣetre samavetā yuyutsavaḥ .\\ 
māmakāḥ pāṇḍavāścaiva kimakurvata sañjaya . 1-1.\\
\end{verse}

\lipsum[2]
\end{document}

With the verse package providing the optional length argument to \begin{verse}[<length>], where <length> is the average length of the verse lines, then the verse lines will be typeset with the mid point of <length> centered in the page.

enter image description here

1
  • Super! thanks for the pointer to the verse package.
    – linuxfan
    Commented Jan 2, 2021 at 20:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .