![如何调整 ConTeXt 目录中条目的位置?](https://linux22.com/image/249016/%E5%A6%82%E4%BD%95%E8%B0%83%E6%95%B4%20ConTeXt%20%E7%9B%AE%E5%BD%95%E4%B8%AD%E6%9D%A1%E7%9B%AE%E7%9A%84%E4%BD%8D%E7%BD%AE%EF%BC%9F.png)
我有一个定义如下的目录:
\setuphead[part][number=no]
\setuphead[chapter][number=no]
\setuphead[section][number=no]
\setuplist[part][alternative=a, margin=0em]
\setuplist[chapter][alternative=a, margin=0em]
\setuplist[section][alternative=d, margin=0em]
\starttext
\startfrontmatter
\completecontent
\stopfrontmatter
\startbodymatter
\part{This is a part title}
\chapter{This is a chapter title}
\section{This is a section title}
\section{This is another section title}
\stopbodymatter
\stoptext
编译后显示如下:
Contents
This is a part title 2
This is a chapter title 3
This is a section title 3 This is another section title 3
这有三个问题:
- 各个部分级别没有水平对齐。
alternative=a
和的章节标题条目和页码之间的水平距离不同alternative=d
。- 垂直行距不一致。
我想创建这样的结果:
Contents
This is a part title 2
This is a chapter title 3
This is a section title 3 This is another section title 3
- 为什么
alternative=a
和alternative=d
看起来如此不同? - 我怎样才能使条目沿左侧排列、一致地设置页码的位置以及调整行距以使所有条目都相同?
答案1
我怎样才能使条目沿左侧排列、一致地设置页码的位置以及调整行距以使所有条目都相同?
distance
可以通过设置列表的和参数来控制左对齐,通过下一个较低类别(尝试)的和键来控制width
行距。before
after
blank[line]
但是,章节列表中页码的间距在 listalternative 中是固定的。要解决这个问题,您可以定义自己的替代命令。
\setuphead [part] [number=no]
\setuphead [chapter] [number=no]
\setuphead [section] [number=no]
%% Set the spacing left of the page number.
\newdimen \mypagenumdistance \mypagenumdistance .7em
\def\fillercmd{\nobreak\hskip\mypagenumdistance}
%% Install the spacing handler for use with alternative “a” in the part
%% and chapter list.
\setuplistalternative [a] [width=\zeropoint,filler=\fillercmd,]
%% Define a list alternative for the section list; we drop the structure
%% number (arg #1) as in the question.
\definelistplacement[my_list_placement][command]#1#2#3%
{#2\fillercmd#3\hskip1.5em}
%% Part and chapter lists need their distance and width dimensions
%% nil’ed.
\setuplist [part] [alternative=a, distance=\zeropoint, width=\zeropoint,before=,]
\setuplist [chapter] [alternative=a, distance=\zeropoint, width=\zeropoint,before=,]
%% Hook our list placement into the section list.
\setuplist [section] [alternative=my_list_placement]
%% Section list hook.
\startsetups toc:section
\noindentation\placelist[section]
\stopsetups
%% Chapter list hook, with transition to the section list.
\startsetups toc:chapter
\noindentation\placelist[chapter][after=\setups{toc:section}]
\stopsetups
\starttext
\startfrontmatter
%% \completecontent is imprecise, we’ll do it ourselves.
\title{Contents}
%% Part list is the top level structure, contains the chapter hook.
\placelist [part] [criterium=text,after=\setups{toc:chapter}]
\stopfrontmatter
%% Testing section.
\startbodymatter
\dorecurse{3}{%
\part{This is a part title}
\dorecurse{5}{%
\chapter{This is a chapter title}
\dorecurse{10}{\section{some section title}}%
}
}
\stopbodymatter
\stoptext
使用最新版本的 mkiv 会产生以下输出:
(您确实应该在邮件列表中询问这些问题。)