![格式化具有长参考标题和大量页码的索引](https://linux22.com/image/465321/%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%85%B7%E6%9C%89%E9%95%BF%E5%8F%82%E8%80%83%E6%A0%87%E9%A2%98%E5%92%8C%E5%A4%A7%E9%87%8F%E9%A1%B5%E7%A0%81%E7%9A%84%E7%B4%A2%E5%BC%95.png)
我正在尝试创建一个类文件来格式化美国某些法律文件所需的特定类型的索引。我想出了两种不同的方法,但都不能让我得到我想要的结果。
目标是有引文、点填充,然后是页码和范围的列表。通常引文很短,只有几页,所以我可以使用:
Example Citation \dotfill 1, 3, 6--7\\
在这种简单的情况下,点从引用之后开始一直延续到页码之前,这正是我想要的。
当引用或页面/范围列表太长而无法放在一行中时,就会出现复杂性。当引用太长时,我希望点从引用的第二行末尾开始。我想到的第一个方法是 tabularx 环境。例如:
\begin{tabularx}{\textwidth}{X r}
\textsc{TabularX (ok)}&\\
Example Citation \dotfill\rlap{\kern2\tabcolsep}& 1, 3, 6--7\\
Here is a very long citation that continues on for a while and therefore needs to have a line break \dotfill\rlap{\kern2\tabcolsep}& 5, 14
\end{tabularx}
~\\
\noindent
\begin{tabularx}{\textwidth}{X r}
\textsc{TabularX (bad)}&\\
Example Citation \dotfill\rlap{\kern2\tabcolsep}& 1, 3, 6--7\\
Here is a very long citation that continues on for a while and therefore needs to have a line break \dotfill\rlap{\kern2\tabcolsep}& 5, 14\\
And a short one with lots of pages \dotfill\rlap{\kern2\tabcolsep}& \parbox[t]{0.25\linewidth}{2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}
\end{tabularx}
但这有两个大问题。首先,页码从单元格顶部开始,与引文的第一行对齐,而不是与点填充位于同一垂直位置(与引文的最后一行对齐)。其次,包含页码的列将调整大小以适合任何引文的最长页码列表。对于出现在较少页面上的每个引文,点填充将在远离第一个页码引用的位置停止(假设页面是 \raggedleft 对齐的)。我可以使用 parboxes 或固定列宽来获取页码中的换行符,但如果引文只有一两页,我无法让点填充继续到第一个页码。有一个空白区域。
为了解决这些限制,我尝试了第二种方法。这一次,我放弃了表格,将引文和页面/范围放在 varwidth 环境中。
\begin{varwidth}{0.7\textwidth}
Example Citation
\end{varwidth}
\dotfill
\begin{varwidth}{0.2\textwidth}
\raggedleft 1, 3, 6--7
\end{varwidth}
\begin{varwidth}{0.7\textwidth}
Here is a very long citation that continues on for a while and therefore needs to have a line break
\end{varwidth}
\dotfill
\begin{varwidth}{0.2\textwidth}
\raggedleft 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30\phantom{,}
\end{varwidth}
这解决了页数较少的引文在首页页码前留有空白的问题。但是首页页码现在与 varwidth 框的顶部对齐,而不是与多行引文的最后一行对齐,并且点引号也不再与多行引文的最后一行对齐。
这就引出了我的问题。是否有某种方法可以将第二个 varwidth 环境(包含页码\范围)的点前导符和顶部与第一个 varwidth 环境(包含引文)的最后一行对齐?
答案1
这是我尝试制作的可视化模型,使用 tabularray 包作为绘图工具:
布置符合您的描述吗?(忽略颜色等)
平均能量损失
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\pagecolor{black!2!blue!3}
\begin{document}
\begin{tblr}
{
width = {\textwidth},
colspec = {X[l]X[c]X[r] },
rowspec = {X[t]X[b]X[b] },
hlines = {2pt, solid, white},
% vlines,
vline{1,4} = {2pt, solid, white},
% vline{2,3} = {1pt, solid, blue!15},
% vline{2,3} = {1}{solid, green!65},
columns = {bg=blue!15,fg=black},
column{1} = {wd=0.7\textwidth,rightsep=0pt},
column{2} = {wd=0pt,leftsep=0pt,rightsep=0pt},
column{3} = {font=\sffamily,leftsep=-2pt},
row{1} = {font=\bfseries\rmfamily, bg=green!40},
% Vborders{2} = {rightspace=10pt},
}
C & & pp \\
Example Citation
\space\dotfill
& \dotfill
& \dotfill\space
1, 3, 6--7
\\
Here is a very long citation that continues on for a while and therefore needs to have a line break
\space\dotfill
& \dotfill
& \dotfill\space
2, 4, 6
\\
And a short one with lots of pages
\space\dotfill
& \dotfill
& \dotfill\space
2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
\\
\end{tblr}
\end{document}
编辑
根据评论,这是一个可行的示例:
平均能量损失
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}
{
width = {\textwidth},
colspec = {X[l,b]X[r]},
% hlines,
% vlines,
column{1} = {wd=0.7\textwidth,rightsep=0pt},
column{2} = {leftsep=-2pt},
}
Example Citation
\space\dotfill
& \dotfill\space
1, 3, 6--7
\\
Here is a very long citation that continues on for a while and therefore needs to have a line break
\space\dotfill
& \dotfill\space
2, 4, 6
\\
And a short one with lots of pages
\space\dotfill
& \dotfill\space
2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
\\
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
\space\dotfill
& \dotfill\space
2, 4, 6
\\
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
\space\dotfill
& \dotfill\space
2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24
\\
\end{tblr}
\end{document}
答案2
索引和书目机制负责处理这些事情。
这是你想要的东西吗?如果是,我可以整理一下粗略的代码并做一个迷你教程。
独立文件中的代码,供参考:
%Toolchain:
%(pdf/xe/lua)latex with shell escape
%biber
%latex
%splitindex -s plainindexstyle.ist
%latex
%latex
\begin{filecontents*}[overwrite]{\jobname.bib}
@misc{tcpr, %misc: just for demo
title = {TCPR},
pagination = {rule}, %bibstring to apply if postnote is digits
}
@misc{auth1,
title = {A v B},
author = {{4 LR 456}},
}
@misc{auth2c,
title = {The Dog Co. v. The Cat Co.},
author = {{4 LR 458}},
}
@misc{auth3c,
title = {U.S. v. U.S.},
author = {{102 U.S.X.C. 123}},
}
@misc{long,
title = {Here is a very long citation that continues on for a while and therefore needs to have a line break},
author = {{Case Reference}},
}
@misc{short,
title = {And a short one with lots of pages},
author = {{Case Ref Short}},
}
\end{filecontents*}
%style file for index
\begin{filecontents*}{plainindexstyle.ist}
delim_0 "\\space\\dotfill\\space "
delim_1 "\\space\\dotfill\\space "
delim_2 "\\space\\dotfill\\space "
delim_n ", "
delim_r "--"
delim_t ""
encap_prefix "\\"
encap_infix "{"
encap_suffix "}"
\end{filecontents*}
\begin{filecontents*}{splitindextoa.yaml}
!config
# for Arara
identifier: splitindex
name: splitindex
authors:
- cicada
commands:
- name: splitindex
command: >
@{
base = getBasename(reference.getName());
optiona = [ '--' ];
optionb = [ '-s' ];
optionc = [ '-c' ];
return getCommand('splitindex', base, optiona, optionb, style, optionc);
}
arguments:
#- identifier: style
# flag: "@{ [ '-s', parameters.style ] }"
- identifier: style
flag: >
@{
parameters.style
}
\end{filecontents*}
\begin{filecontents*}{splitindexdefault.yaml}
!config
# for Arara
identifier: splitindexdefault
name: splitindexdefault
authors:
- cicada
commands:
- name: splitindexdefault
command: >
@{
base = getBasename(reference.getName());
optiona = [ '-m' ];
optionc = [ '' ];
return getCommand('splitindex', base, optiona, optionc);
}
\end{filecontents*}
\documentclass{article}
\newcommand\rulesep{\rule{0.4\textwidth}{.4pt}}
%------------------
\title{Creating a Table of Rules}
\author{}
\date{}
\usepackage[splitindex,noautomatic,nonewpage]{imakeidx}
\newcommand\abibname{authortitle}
\newcommand\abibstyle{style=\abibname}
\usepackage[
\abibstyle ,
indexing=cite,
citetracker=true,
ibidtracker=false,
pagetracker=true,
% idemtracker=true,
% opcittracker=true,
% loccittracker=true,
% autocite=footnote,
% datezeros=true,
]{biblatex}
\addbibresource{\jobname.bib}
\NewBibliographyString{atparagraph,rule}
\DefineBibliographyStrings{english}{%
atparagraph = {at para},
rule = {r},
}
\DeclareCiteCommand{\toacite}%
{\usebibmacro{prenote}}
{\printfield{title}%
\setunit{\addcomma\space}%
\printnames{author}%
}
{}%\multicitedelim
{\usebibmacro{postnote}}
%=================
%indexing
\newcommand\pagerefindexnote{\noindent\small\mdseries $\to$ References are to page numbers.}
\makeindex
\makeindex[name=rulesa,title=Table of TCP Rules,columns=3,columnseprule,intoc]
\makeindex[name=cases,title={\normalsize Cases},columns=1]
\makeindex[name=rules,title={\normalsize Rules},columns=1]
\usepackage[
final=true,
bookmarks,
colorlinks=true,
allcolors = black,
citecolor=blue,
hyperindex=false,
]{hyperref}
% variations instead of having \cite...\index... all the time
\newcommand{\icite}[1]{\cite[#1]{tcpr}\index[rulesa]{r~#1}}
\newcommand{\iicite}[2]{\cite[#1]{tcpr}\index[rulesa]{r~#2@r~#1}}
\newcommand{\iiicite}[3]{\cite[#1]{tcpr}\index[rulesa]{r~#3@r~#2{#1}}}
\newcommand{\ivcite}[4]{\cite[#1]{tcpr}\index[rulesa]{r~#3@r~#2{#1}|#4}}
\newcommand{\vcite}[2]{\cite[#1]{tcpr}\index[rulesa]{#2}}
%some wrapper commands for convenience
%%\imki@wrindexentry{names}{Charles}{26} - this is an imakeidx macro
\makeatletter
\newcommand{\addindexitem}[3]{%
\imki@wrindexentry{#1}{#2}{#3}}
\makeatother
\newcommand{\textformat}[1]{\textsf{\textbf{#1}}}
\newcommand\yq{\begin{quotation}}
\newcommand\yqq{\end{quotation}}
\newcommand\yc{\begin{center}}
\newcommand\ycc{\end{center}}
\newcommand\yi{\begin{itemize}}
\newcommand\yii{\end{itemize}}
\newcommand\yis{\item[\space]}
\newcommand\zzz[2]{\cite[#1]{tcpr}\index[rules]{r #2@\citetitle[#1]{tcpr}}}
%1=rule2=sortkey
%------------------
\begin{document}
\maketitle
\newpage
\tableofcontents
\newpage
\index{p} %seems general index is expected/assumed??
%\printindex
\indexprologue{\pagerefindexnote}
%\addindexitem{cases}{ @\textit{Case}|textit}{Page(s)}
%\addindexitem{rules}{ @\textit{Rule}|textit}{Page(s)}
\printindex[rulesa]
\newpage
Index the citations.
Use multiple indices, one for each category of authority.
\yc
\bfseries
TABLE OF AUTHORITIES
\ycc
\hfill\textbf{Page(s)}
\printindex[cases]
\printindex[rules]
\newpage
\section{Text}
\cite[4]{tcpr}\index[rulesa]{4}
xxx
\section{More Text}
xxx
\newpage
\cite[4]{tcpr}\index[rulesa]{4}
\cite[123]{tcpr}\index[rulesa]{123}
\iicite{5}{006}, \iicite{15}{015}, \iicite{52}{052}, \iicite{502}{502}, \iicite{12}{012}.
\cite[4556]{tcpr}\index[rulesa]{4556}
\iicite{53}{053}
\iiicite{14}{\textit}{014}
\iiicite{16}{\textbf}{016}
\iiicite{18}{}{018}{textbf}
\vcite{19}{r~019@r~19|textformat}
\vcite{19(a)}{r~019a@r~19!(a)} versus \vcite{r~19(a)}{r~019a@r~19!(a)}
\vcite{55(b)}{r~055b@r~55(b)|see{52(a)}}
\vcite{55(c)}{r~055c@r~55(c)!see{52(a)}}
\vcite{52(a)}{r~052a@r~52(a)}
\newpage
\vcite{52(a)}{r~052a@r~52(a)}
$\to$ \textbackslash index\{indexentry\}
An \verb.indexentry. is formatted as:
\yq
\yc
a@b|c
\ycc
where
\yi
\yis a = sortkey
\yis b = index display key(s), up to three levels
\yi
\item[·] level1!level2!level3
\yii
\yis c = page number format command name (without the backslash)
\yi
\item[·] can be \verb,see{...},
\yii
\yii
\yc
e.g., 052@52|textbf
\ycc
Sort the item as 052, print 52, and make the page number bold.
\textbf{References}: Do \verb.texdoc makeindex. to bring up both \verb,makeindex.pdf, and \verb,ind.pdf, manuals.
\yqq
\cite[457]{auth1}\index[cases]{avb@\citetitle{auth1}, \citeauthor[457]{auth1}}
\cite[45]{tcpr}\index[rules]{r 045@\citetitle[45]{tcpr}}
\zzz{123}{123}
\zzz{200}{200}
\cite{auth2c}\index[cases]{TheDogCo@\citetitle{auth2c}, \citeauthor{auth2c}}
\toacite{short}\index[cases]{Anda@\toacite{short}}
\newpage
\cite{auth2c}\index[cases]{TheDogCo@\citetitle{auth2c}, \citeauthor{auth2c}}
\cite{auth2c}\index[cases]{TheDogCo@\citetitle{auth2c}, \citeauthor{auth2c}}
\cite{auth3c}\index[cases]{us@\citetitle{auth3c}, \citeauthor{auth3c}}
\zzz{123}{123}
\zzz{200}{200}
\zzz{201}{201}
\zzz{r 212(a)}{212(a)}
versus
\cite[r 212(a)]{tcpr}\index[rules]{r 212(a)@\citetitle [r 212(a)]{tcpr}}%note the space
\newpage
\cite{auth3c}\index[cases]{us@\citetitle{auth3c}, \citeauthor{auth3c}}
\zzz{123}{123}
\newpage
\cite{auth3c}\index[cases]{us@\citetitle{auth3c}, \citeauthor{auth3c}}
\zzz{85}{085}
\zzz{85}{085}
\toacite{short}\index[cases]{Anda@\toacite{short}}
\newpage
\cite{auth2c}\index[cases]{TheDogCo@\citetitle{auth2c}, \citeauthor{auth2c}}
\cite{auth3c}\index[cases]{us@\citetitle{auth3c}, \citeauthor{auth3c}}
\newpage
\cite{auth2c}\index[cases]{TheDogCo@\citetitle{auth2c}, \citeauthor{auth2c}}
\zzz{123}{123}
\zzz{85}{085}
\citetitle[r 45(a)]{tcpr}\index[rules]{r 045@\citetitle[r 45(a)]{tcpr}}
\toacite{short}\index[cases]{Anda@\toacite{short}}
\newpage\citetitle{long}, \citeauthor{long}\index[cases]{Hereis@\citetitle{long}, \citeauthor{long}}
\newpage text
\newpage\citetitle{long}, \citeauthor{long}\index[cases]{Hereis@\citetitle{long}, \citeauthor{long}}
\newpage text
\newpage text
\newpage\citetitle{long}, \citeauthor{long}\index[cases]{Hereis@\citetitle{long}, \citeauthor{long}}
\newpage text
\newpage\citetitle{long}, \citeauthor{long}\index[cases]{Hereis@\citetitle{long}, \citeauthor{long}}
\newpage\toacite{short}\index[cases]{Anda@\toacite{short}}
\newpage text \newpage text\toacite{short}\index[cases]{Anda@\toacite{short}}
\newpage text\newpage text\newpage text
\newpage text\newpage text\newpage text\newpage text
\newpage text
\toacite{short}\index[cases]{Anda@\toacite{short}}
\newpage\citetitle{long}, \citeauthor{long}\index[cases]{Hereis@\citetitle{long}, \citeauthor{long}}
\newpage text
\newpage text\newpage text\newpage text\newpage text
\newpage text
\toacite{short}\index[cases]{Anda@\toacite{short}}
\newpage text
\toacite{short}\index[cases]{Anda@\toacite{short}}
\newpage text
\newpage text\newpage text\newpage text\newpage text
\toacite{short}\index[cases]{Anda@\toacite{short}}
%\citetitle{short}\index[cases]{\citetitle{short}, \citeauthor{short}}
\toacite{long}\index[cases]{Hereis@\citetitle{long}, \citeauthor{long}}
\bigskip
\hfill\rulesep\hfill\ %\hrule%{0.8\linewidth}
\bigskip
%===============================================
\end{document}