In order to use section numbers instead of page numbers it is necessary to redefine the way, the index entry is written to \jobname.idx
. That is basically easy, if the package imakeidx
is used.
In its manual, imakeidx
the author writes, that \imki@wrindexentry
should be redefined to apply for other styles. Looking into the package, there is a similar command used with \thepage
as argument, so redefined it, using \thesection
.
However, makeindex
as external processor complains about the new format if \thesection
writes its numbers as 1.1
etc., i.e. with dots. Using xindy
solves this problem, by applying a new alphabet or location-class, this is done in sectionindex_xindy.xdy
, as well as removing the ,
separator and inserting -----
instead.
Content of sectionindex_xindy.xdy
(markup-locclass-list :open " ----- " :sep "")
( define-location-class "numericsections"
("arabic-numbers" :sep "." "arabic-numbers"))
( define-location-class "numericchapteralphasections"
("arabic-numbers" :sep "." "ALPHA"))
\documentclass[paper=a4,12pt]{scrbook}
\usepackage{letltxmacro}
\usepackage[xindy]{imakeidx}
%\usepackage{hyperref}% Leads to linking to wrong positions%
\makeatletter
% Global redefinition of indexentry to section instead of page%
\renewcommand{\imki@wrindexentrysplit}[3]{%
\expandafter\protected@write\csname#1@idxfile\endcsname{}%
{\string\indexentry{#2}{\thesection}}%
}%
\LetLtxMacro{\LaTeXStandardFigure}{\figure}
\let\LaTeXStandardEndFigure\endfigure%
\renewenvironment{figure}[1][tpb]{%
%redefine the index write command to use figure number instead of section number
\renewcommand{\imki@wrindexentrysplit}[3]{%
\expandafter\protected@write\csname##1@idxfile\endcsname{}%
{\string\indexentry{##2}{\thefigure}}
}%
\LaTeXStandardFigure[#1]%
}{%
\LaTeXStandardEndFigure%
}%
\LetLtxMacro{\LaTeXStandardTable}{\table}
\let\LaTeXStandardEndTable\endtable%
\renewenvironment{table}[1][tpb]{%
%redefine the index write command to use table number instead of section number
\renewcommand{\imki@wrindexentrysplit}[3]{%
\expandafter\protected@write\csname##1@idxfile\endcsname{}%
{\string\indexentry{##2}{\thetable}}
}%
\LaTeXStandardTable[#1]%
}{%
\LaTeXStandardEndTable%
}%
\makeatother
\makeindex[options=-M sectionindex_xindy.xdy]
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}%
\renewcommand{\thesection}{\arabic{chapter}.\Alph{section}}%
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}%
\begin{document}
\listoffigures
\listoftables
\chapter{First}
\begin{figure}
\caption{A first figure with index entry, say Figure\index{Figure!First}}
\end{figure}
\section{First section of chapter~\arabic{chapter}}
Here is a table (well, the environment actually)
\begin{table}
\centering
\begin{tabular}{lll}
\hline
A & dummy & table \tabularnewline
\hline
\end{tabular}
\caption{A table with some index entry in it: \index{Table}{First}}
\end{table}
See also the keyword Index\index{Index}
\chapter{Two}
\section{First}
Index\index{Index} and its usage\index{usage}
\begin{figure}
\caption{A dummy figure with an index entry, say DummyFigure\index{Figure!DummyFigure}}
\end{figure}
\printindex
\end{document}
In order to make this work for figures/tables, I just redefined the command again within wrappers for figure
and table
environment. You have redefine \thefigure
and \thetable
explicitly, since it seems, that they introduce a trailing \relax
command just before the figure/table number.
Please note, that this does not work correctly with hyperlinks so far,regarding the figure/table index entries.
Enabling --shell-escape is mandatory.
In order to make use of things like the \medievalpage[]
layout, you need to follow memoir
's documentation. On their own, such commands will either have no effect or cause havoc. Moreover, combining them with geometry
won't work. You must use memoir
's commands to layout the page.
It will also be better to avoid the conflict with fancyhdr
by not using it. Since you only want a centred page number in the footer, this is easily done using plain
. Fancier headers and footers can be configured using the layouts provided by memoir
.
Finally, memoir
offers significant support for hanging paragraphs. This includes a hangparas
environment. If you wish, your entire document can be nestled within such an environment.
The following example assumes you want:
- stock size of 6"x9"
- zero trims i.e. the final, trimmed paper size will also be 6"x9"
- the medieval layout specified in your MWE
- hanging paragraphs with a .2" indentation
All of this is easy to tweak if I've misunderstood your intent. memoir
offers extremely detailed documentation covering every aspect of this.
To set up the layout, we need to tell memoir
:
- the stock size
- the trims / paper size
- the layout
and then we must tell memoir
to adjust the layout accordingly before proceeding. That is, we have to tell memoir
to do the calculations required to layout the pages according to our instructions. This must be done after all tweaking to the layout is complete.
So:
\documentclass{memoir}
\setstocksize{9in}{6in}% sets the stock paper to this size
\settrimmedsize{9in}{6in}{*}% sets the trimmed paper to this size (i.e. no trimming)
\medievalpage[10]% sets the page layout
\checkandfixthelayout% implements the above - without this, nothing doing
\pagestyle{plain}% equivalent to the setup with fancyhdr but avoid conflicts
\usepackage{kantlipsum}
\begin{document}
\begin{hangparas}{.2in}{1}
\kant[1-20]
\end{hangparas}
\end{document}
Best Answer
Following the example you give, using the
memoir
class, here is a simple way to implement what you want.Memoir
may be a good option if you have precise, complex needs, because it is very comprehensive, especially for long documents.Because
memoir
's\frontmatter
,\mainmatter
and friends alter the way section numbering is done, I suggest you create a whole new counter, since you are not really using it as a sectioning command anyway. If you need to add the paragraphs to the table of contents, it is possible too, so no worries there (just ask).Here is the example document:
Note that you can tell memoir to index things based on any counter, you just need to specify it in the
\specialindex{\jobname}{<counter>}{#1}
line.Now, all you need to do is run LaTeX, then MakeIndex, then LaTeX again.