4

I am typesetting a manually created author index. I want to put the name in the left margin and the page number in the right. I manage to right align the second line in cases where a linebreak is inserted because of long names.

The problem is that I would like to \flushleft the first line. But using \flushleft breaks the alignment of the page number.

(To run with xelatex)

\documentclass{article}
\usepackage{fontspec}

\newfontfamily{\defaultfont}{Times New Roman}
\newfontfamily{\latinfont}{Times New Roman}
\usepackage[Latin]{ucharclasses}
\setDefaultTransitions{\defaultfont}{}
\setTransitionsForLatin{\latinfont}{}

\usepackage{multicol}

\begin{document}
\pagestyle{empty}
\begin{multicols*}{2}
  %%% Right align second line
  %%% https://tex.stackexchange.com/a/43239/2483
  \leftskip=0pt plus 0.5fil%
  \rightskip=0pt plus -0.5fil%
  \parfillskip=0pt plus 0fil%
  \noindent Lasserre, Jean\hfill{}Vol. 3, 3743\par
  \noindent Logunov, Alexander (Александр Логунов)\hfill{}Vol.~2,~2361\par
\end{multicols*}

\end{document}

enter image description here

TeXtnik
  • 5,853

1 Answers1

5

A variant of the “Bourbaki trick” in the TeXbook:

\documentclass{article}
\usepackage{fontspec}
\usepackage{ragged2e}
\usepackage{multicol}

\setmainfont{Times New Roman}

\newcommand{\entry}[2]{% #1 = author, #2 = ref
  \par\noindent{\RaggedRight
    #1%
    \nobreak\hfill\penalty50\hskip1em\null\nobreak
    \hfill\mbox{\normalfont(#2)}%
    \parfillskip=-\rightskip\par}%
}

\begin{document}

\begin{multicols*}{2}
\entry{Lasserre, Jean}{Vol. 3, 3743}
\entry{Logunov, Alexander (Александр Логунов)}{Vol.~2,~2361}
\end{multicols*}

\end{document}

The entry is typeset ragged right, but the \parfillskip will neutralize \rightskip in the last or unique line.

At least 1em is left between the name and the reference.

enter image description here

egreg
  • 1,121,712