TransWikia.com

Vertically aligning the first letter of each line in a centering environment

TeX - LaTeX Asked on January 23, 2021

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}
{nopagebreakcentering}

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?

2 Answers

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}

Correct answer by David Carlisle on January 23, 2021

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}
{nopagebreakcentering}

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

Answered by Peter Wilson on January 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP