手作業で目次を作る

Re: 手作業で目次を作る

- 匿 名 の投稿
返信数: 0
> 「手作業で目次を作るためのパッケージ」などというものがあるのかどうかは,残念ながら存じ上げません.

検索をしてみましたところ,easylistという箇条書き用パッケージには“Predefined Style”としてbooktocやarticletocというものが用意されているようですが,日本語のj(s)bookやj(s)articleの目次の体裁に合わせるのは簡単ではないようです.

仮に箇条書きの利用を考えるとしますと,例えばjsclassesのdescription環境を真似して,次のようなことも可能ではあります(場当たり的ですので,使い物になるかどうかは相当怪しい代物ですが).

%
% mock tableofcontents using jsclasses' description-env
%

\documentclass{jsbook}

\makeatletter
\newcommand{\tocfont}{\gtfamily\sffamily\large}
\newcounter{Chap}
\newenvironment{ChapEntry}{%
  \list{\normalfont\tocfont\@chapapp\theChap\@chappos}{%
    \usecounter{Chap}
    \labelwidth=\leftmargin
    \labelsep=1zw
    \advance \labelwidth by -\labelsep
    \let\makelabel=\ChapEntryLabel}}{\endlist}
\newcommand*\ChapEntryLabel[1]{\normalfont\tocfont #1\hfil}
\newcounter{Sec}[Chap]
\newenvironment{SecEntry}{%
  \list{\normalfont\theChap.\theSec}{%
    \usecounter{Sec}
    \labelwidth=\leftmargin
    \labelsep=1zw
    \advance \labelwidth by -\labelsep
    \let\makelabel=\SecEntryLabel}}{\endlist}
\newcommand*\SecEntryLabel[1]{\normalfont #1\hfil}
\newcommand{\DotFill}
  {\leaders\hbox{$\m@th \mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}\hfill}
\newcommand{\ChapLine}[2]{{\normalfont\tocfont #1\hfill#2}\par}
\newcommand{\ChapLineP}[1]{\hfill{\normalfont\tocfont #1}\par}
\newcommand{\SecLine}[2]{#1\DotFill\makebox[\@pnumwidth][r]{#2}}
\newcommand{\TocLineSkip}{\vspace{\baselineskip}}
\makeatother

\begin{document}

\chapter*{\contentsname}

\begin{ChapEntry}
\item[まえがき] \ChapLineP{iii}
  \TocLineSkip
\item \ChapLine{\TeX}{1}
  \begin{SecEntry}
  \item \SecLine{\TeX の誕生}{2}
  \item \SecLine{\TeX で何ができるか}{6}
  \end{SecEntry}
  \TocLineSkip
\item \ChapLine{インストール}{25}
  \begin{SecEntry}
  \item \SecLine{インストールのまえに}{26}
  \item \SecLine{インストーラの起動}{27}
  \end{SecEntry}
  \TocLineSkip
\item[付録A] \ChapLine{より高度な\LaTeX の利用に備えて}{467}
  \TocLineSkip
\item[付録B] \ChapLine{\TeX の環境設定}{485}
  \TocLineSkip
\item[参考文献] \ChapLineP{539}
  \TocLineSkip
\item[索引] \ChapLineP{544}
\end{ChapEntry}

\end{document}

※ こんな小手先の対応をするよりも,上の [3] に書いた,tocファイルを手書きする方法のほうが,簡単・確実なように思います.なお,上の [3] ではsample.texで\tableofcontentsを使っているために両ファイル名を揃えて,tocファイルの拡張子も“.toc”としていますが,\tableofcontentsを使わずに直接手書きtocファイルを\inputするようにすれば,tocファイルのファイル名や拡張子も任意で構いません(それどころか,\input出来るわけですから,そもそもファイルを2つに分ける必要性も実はなかったということに事後的に気付きました・・・).