1

In the index of my Japanese document, I want each entry to consist of:

  1. The English name of the Japanese character (left-aligned)
  2. The Japanese character itself (left-aligned)
  3. The page number on which the associated entry can be found (right-aligned)

The information inside the parentheses above gives the horizontal alignment of each entry.

After fiddling with the code provided in this solution, I made some progress but stumbled into other problems:

  • The index is not splitting over 4 columns as stipulated in the \makeindex command.
  • There is a pagebreak between the index title and contents.

I'm not very fluent in constructing style files, and would really appreciate a solution accompanied with clear explanations (as far as possible). I also find the bottom table in this link a bit difficult to interpret.

In the code block below is my MWE. For the sake of thoroughness, I included many index entries to test the robustness of my code.

\documentclass[10pt, a4paper]{ltjbook}
\usepackage{luatexja}
\usepackage[left=1.9cm,right=1.9cm,bottom=1.5cm,top=1.5cm]{geometry}
\usepackage{array,longtable,supertabular,booktabs,multicol,multirow}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage{multicol}
\usepackage{blindtext}

\usepackage{imakeidx}
\setlength{\columnseprule}{0.4pt}

\begin{filecontents*}{general.ist}
headings_flag 5
heading_prefix "\n\\rmfamily\\textbf{"heading_suffix "} "
preamble "\\chapter*{\\indexname}%
\\newcommand\\ignoreNL[1]{}%
\\begin{tabular}{llr} "
postamble " \\end{tabular} "
item_0 "\\\\\n "
delim_0 "&"
delim_1 "\\hfill "
group_skip "\n \\\\[5pt] \\ignoreNL "
\end{filecontents*}

\makeindex[name=gen, title={Index of Kanji}, columns=4, columnseprule, options=-s general.ist]

\newcommand{\gindex}[2]{\index[gen]{#1 & #2}}

\begin{document}
\Blindtext
\gindex{One}{一}

\gindex{Two}{二}

\gindex{Three}{三}

\Blindtext
\gindex{Four}{四}

\gindex{Five}{五}

\gindex{Six}{六}

\gindex{Seven}{七}

\gindex{Eight}{八}

\gindex{Nine}{九}

\blindtext
\gindex{Ten}{十}

\gindex{Eleven}{十一}

\gindex{Twelve}{十二}

\gindex{Thirteen}{十三}

\gindex{Fourteen}{十四}

\gindex{Fifteen}{十五}

\gindex{Sixteen}{十六}

\gindex{Seventeen}{十七}

\gindex{Eighteen}{十八}

\gindex{Nineteen}{十九}

\gindex{Twenty}{二十}

\gindex{Mouth}{口}

\gindex{Neck}{首}

\gindex{Head}{頭}

\gindex{Lips}{唇}

\gindex{Arms}{腕}

\gindex{Feet}{足}

\gindex{Sunday}{日曜日}

\gindex{Monday}{月曜日}

\gindex{Tuesday}{火曜日}

\gindex{Wednesday}{水曜日}

\gindex{Thursday}{木曜日}

\gindex{Friday}{金曜日}

\gindex{Saturday}{土曜日}

\gindex{Wind}{風}

\gindex{Water}{水}

\gindex{Fire}{火}

\gindex{Flower}{花}

\blindtext
\gindex{East}{東}

\gindex{South}{南}

\gindex{North}{北}

\blindtext
\gindex{West}{西}


\printindex[gen]

\end{document}

Image showing Index inserting unwanted pagebreak, and not splitting over multiple columns

>>EDIT: 29 January 2022<<

After working with the entire document, the first page of the index is producing an anomaly as seen below. Any help? enter image description here

1 Answer 1

3

Your index is inside a tabular, which won't break across pages, and neither across columns. So you must use a breakable table, like longtable. To get a longtable inside multicols you must use a trick, like in this answer.

This brings me to this solution (for some reason I have to do the multicols myself; it seems \makeindex is not doing it.

EDIT: I fiddled a bit with general.ist to prevent a column/page break between the group letter and the next entry.

EDIT 2: I added a \\makeatother for safety.

EDIT 2022/01/30 It appears that longtable ruins the internal LaTeX parameter \@colroom, which multicols needs to break the text into columns, at least when the text doesn't fit on the page. \@colroom is calculated right at the beginning of the multicols environment, before any text has been processed inside it. For following pages it is calculated again, so these are not affected. I solved this by saving \@colroom before the longtable and restoring it after. I also made some other minor improvements. I made \tabcolsep a bit smaller to better fit the index in the columns.

\documentclass[10pt, a4paper]{ltjbook}
\usepackage{luatexja}
\usepackage[left=1.9cm,right=1.9cm,bottom=1.5cm,top=1.5cm]{geometry}
\usepackage{array,longtable,supertabular,booktabs,multicol,multirow}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage{blindtext}
\usepackage{imakeidx}
\setlength{\columnseprule}{0.4pt}
\newsavebox\ltmcbox
\newlength\mysavecolroom
% This command inhibits a column break after a group letter in the index
% It also swallows the following \\, because the \\ is here before the \nopagebreak.
\newcommand{\dontbreak}[1]{\\\nopagebreak} % Swallow the following \\
\begin{filecontents*}{general.ist}
headings_flag 5
heading_prefix "\n\\rmfamily\\textbf{"
heading_suffix "}\\dontbreak "
preamble "\\chapter*{\\indexname}%
\\newcommand\\ignoreNL[1]{}%
\\begin{multicols}{4}
\\makeatletter\\mysavecolroom=\\@colroom\\makeatother
\\setbox\\ltmcbox\\vbox{
\\makeatletter\\col@number\\@ne\\makeatother
\\setlength\\tabcolsep{4pt}
\\begin{longtable}[l]{@{}llr@{}}"
postamble "\n\\end{longtable}
\\unskip
\\unpenalty
\\unpenalty}
\\makeatletter\\@colroom=\\mysavecolroom\\makeatother
\\unvbox\\ltmcbox
\\end{multicols}
"
item_0 "\\\\\n "
delim_0 "&"
delim_1 "\\hfill "
group_skip "\n \\\\[5pt] \\ignoreNL "
\end{filecontents*}

\makeindex[name=gen, title={Index of Kanji}, columns=4, columnseprule, options=-s general.ist]

\newcommand{\gindex}[2]{\index[gen]{#1 & #2}}

\begin{document}
\Blindtext
\gindex{One}{一}

\gindex{Two}{二}

\gindex{Three}{三}

\Blindtext
\gindex{Four}{四}

\gindex{Five}{五}

\gindex{Six}{六}

\gindex{Seven}{七}

\gindex{Eight}{八}

\gindex{Nine}{九}

\blindtext
\gindex{Ten}{十}

\gindex{Eleven}{十一}

\gindex{Twelve}{十二}

\gindex{Thirteen}{十三}

\gindex{Fourteen}{十四}

\gindex{Fifteen}{十五}

\gindex{Sixteen}{十六}

\gindex{Seventeen}{十七}

\gindex{Eighteen}{十八}

\gindex{Nineteen}{十九}

\gindex{Twenty}{二十}

\gindex{Mouth}{口}

\gindex{Neck}{首}

\gindex{Head}{頭}

\gindex{Lips}{唇}

\gindex{Arms}{腕}

\gindex{Feet}{足}

\gindex{Sunday}{日曜日}

\gindex{Monday}{月曜日}

\gindex{Tuesday}{火曜日}

\gindex{Wednesday}{水曜日}

\gindex{Thursday}{木曜日}

\gindex{Friday}{金曜日}

\gindex{Saturday}{土曜日}

\gindex{Wind}{風}

\gindex{Water}{水}

\gindex{Fire}{火}

\gindex{Flower}{花}

\blindtext
\gindex{East}{東}

\gindex{South}{南}

\gindex{North}{北}

\blindtext
\gindex{West}{西}

  \printindex[gen]

\end{document}

EDIT 4 (Jan 31, 2022):

Here is another solution for general.ist that I find cleaner. It doesn't need \newlength\mysavecolroom.

headings_flag 5
heading_prefix "\n\\rmfamily\\textbf{"
heading_suffix "}\\dontbreak "
preamble "\\chapter*{\\indexname}%
\\newcommand\\ignoreNL[1]{}%
\\setbox\\ltmcbox\\vbox{
\\setlength\\tabcolsep{4pt}
% \\hsize=(\\linewidth-(n-1)\\columnsep)/n
% where n = number of columns
\\setlength{\\hsize}{\\dimexpr(\\linewidth-3\\columnsep)/4}
\\begin{longtable}[l]{@{}llr@{}}"
postamble "\\end{longtable}
\\unskip
\\unpenalty
\\unpenalty}
\\begin{multicols}{4}
\\unvbox\\ltmcbox
\\end{multicols}
"
item_0 "\\\\\n "
delim_0 "&"
delim_1 "\\hfill "
group_skip "\n \\\\[5pt] \\ignoreNL "

enter image description here

5
  • The output looks awesome. Thank you very much! @Pieter, if possible, may I ask you to edit your post and unpack the contents of the .ist file step by step. I'd like to enhance my understanding on what the commands do/mean... :-) Apr 27, 2021 at 11:09
  • A last thought @Pieter van Oostrum, if you could help solve a related problem on this post (see Edit 1 on 2021/04/29) it would be of great help! Apr 29, 2021 at 14:46
  • @Pieter van Oostrum, would you perhaps know how to solve the problem of my latest edit above. Would be great to borrow your expertise again :-) Jan 29, 2022 at 17:59
  • @HenriBranken, It appears that longtable ruins the internal LaTeX parameter \@colroom, which multicols needs to break the text into columns. So save \@colroom before the longtable and restore it after. See my update. Don't forget to delete general.ist before running this otherwise you will still use the old version. Jan 30, 2022 at 18:53
  • @Pieter van Oostrum, thank you for your insights. However, I'm not getting the expected output. If you're keen on the following idea, you may clone this GitHub link and work with the tuttle.tex file... Please give met your GitHub profile name so that I may add you as a collaborator. Jan 31, 2022 at 7:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .