如何制作书中人物索引(附页码)

如何制作书中人物索引(附页码)

我正在写一本书,书中有很多人物,其中一些人的名字相同。我构造了一个新的 documentCommand: \createPerson,它为人物的一些基本属性生成设置,并构建相关引用,可用于获取人物的全名或称呼。它还返回人物的唯一 ID,以便识别人物。输出的示例如下:

\nameref{CarlWilhelmLarsen1867} --> 输出 --> 卡尔威廉拉森(315)

该人的最终输出可能如下所示: enter image description here

现在的问题是,是否可以创建书中提到 CarlWilhelmLarsen1867 的索引,如果可以,那么如何创建?

这里是我创建人员的最小示例。我知道它有点长。但是,我希望你能理解。我创建了命令:createPerson 和 textlabel。我希望这些命令可能可以用来创建索引的基础。但无论如何,你可能有一个好的解决方案。

\documentclass{article}
\usepackage{tikz}
\usepackage{datetime}
\usepackage[danish]{varioref}
\usepackage{hyperref}
\usepackage{xifthen}
\RequirePackage[framemethod=TikZ]{mdframed}
\usepackage{multirow, tabularx}
\usepackage[]{units}
\usepackage{xparse}
\usepackage{adjustbox}

%=========================================================================
%                             CREATE PERSON NEW
%=========================================================================
%Arguments: 
%   1)  MANDATORY   - Image destination
%   2)  [OPTIONAL]  - Called name
%   3)  MANDATORY   - Reference to the current full name
%   4)  [OPTIONAL]  - Full birth name
%   5)  MANDATORY   - Uniqueue Reference number
%   6)  [OPTIONAL]  - Birth date in the format of dd. mmm. yyyy
%   7)  <OPTIONAL>  - Death date in the format of dd. mmm. yyyy
\NewDocumentCommand\createPerson{r<>omomo+d<>}
{
    \begin{mdframed}[style=whiteBox]%
        \profileImage[width=0.25\textwidth]{Images/People/ProfileImages/#1}
        \begin{tabularx}{0.75\textwidth}[t]{lXrc}%
            % Row one
            Navn:   &   \nameref{#3}    & \textlabel{#5}{PERSON_ID:#3}    & $\Re$%
            %Create new row if needed
            \IfNoValueTF{#2}%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}}%
                        {\\}}%
                    {\\}}%
                {\\}%
            % Row two
            \IfNoValueTF{#4}%
                % If no birth name
                {\IfNoValueTF{#2}%
                    % If no called name
                    {&&}%
                    % If a called name
                    {Kaldenavn: & \textlabel{#2}{KN:#3} &}}%
                %If a birth name
                {Fødenavn: & #4 &}%
                %
                \IfNoValueTF{#6}%
                       % If no birth date
                       {\IfNoValueTF{#7}{}{\textlabel{#7}{DD:#3} & \cross}}%
                       {\textlabel{#6}{FD:#3} & $\star$}%
            % Create new row if needed    
            \IfNoValueTF{#2}%
                {%
                \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                }%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                    }%
                    {\\}%
                }%
            % Row three
            \IfNoValueTF{#2}%
                % If no called name
                {%
                    \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {&&}%
                        }%
                }%
                % If a called name
                {\IfNoValueTF{#4}%
                    % If no birth name
                    {
                        \IfNoValueTF{#6}%
                            {}%
                            {\IfNoValueTF{#7}%
                                {}%
                                {&&}%
                            }%
                    }%
                    %If birth name
                    {Kaldenavn: & \textlabel{#2}{KN:#3} &}%
                }%
            %
            \IfNoValueTF{#7}%
                       % If no death date
                       {}%
                       {\IfNoValueTF{\textlabel{#6}{FD:#3}}{}{\textlabel{#7}{DD:#3} & \cross}}%
        \end{tabularx}%
    \end{mdframed}%
}

%=========================================================================
%                               TEXT LABEL
%=========================================================================
\makeatletter%
% Arguments:
%  1) The text
%  2) The label
\newcommand*{\textlabel}[2]{%
  \edef\@currentlabel{#1}% Set target label
   #1\phantomsection\label{#2}% Print and store label
}
\makeatother



\mdfdefinestyle{whiteBox}{%
    linecolor=black,
    outerlinewidth=0.75pt,
    roundcorner=6pt,
    innertopmargin=10pt,
    innerbottommargin=10pt,
    innerrightmargin=10pt,
    innerleftmargin=10pt,
    backgroundcolor=white,
    outermargin=0cm,
    nobreak=true,
    align=center}

%=========================================================================
%                       Profile image in border
%=========================================================================
\newsavebox\profileImageBox
\NewDocumentCommand{\profileImage}%
      {O{width=0.6\linewidth}
       O{draw=black,line width=0.75pt,rounded corners=6pt}
       m}{%
   \savebox\profileImageBox{\includegraphics[#1]{#3}}%
   \begin{adjustbox}{valign=t}
       \begin{tikzpicture}%
        \draw [path picture={%
                       \node at (path picture bounding box.center) {%
                           \usebox\profileImageBox};},#2]
              (0,0)  rectangle (\wd\profileImageBox,\ht\profileImageBox);
       \end{tikzpicture}%
   \end{adjustbox}%
}

%=========================================================================
%                                 Cross
%=========================================================================
\newcommand{\cross}[1][.7pt]{\ooalign{%
  \rule[1ex]{1ex}{#1}\cr% Horizontal bar
  \hss\rule{#1}{.7em}\hss\cr}% Vertical bar
}

\begin{document}

\section{Carl Wilhelm Larsen}
    \label{CarlWilhelmLarsen1867}

    \createPerson%
        <CarlVilhelmLarsen1867.jpg>%
        [Carl]%
        {CarlWilhelmLarsen1867}%
        {315}%
        [5 maj 1867]%
        <18 maj 1953>%

\end{document}

答案1

使用imakeidx包及其\index[foo]命令-这允许使用分割索引:

\makeindex[name=nameindex,title={Index of persons}]在序言中说清楚,用途\index[foo]{your person entry}以及\printindex[nameindex]你想要在哪里使用它。

我已将其放在hyperref包裹清单的末尾;-)

\createPerson对于这个巨大的命令,没有其他评论。

\documentclass{article}
\usepackage{tikz}
\usepackage{datetime}
\usepackage[danish]{varioref}
\usepackage{xifthen}
\RequirePackage[framemethod=TikZ]{mdframed}
\usepackage{multirow, tabularx}
\usepackage[]{units}
\usepackage{adjustbox}
\usepackage{xparse}
\usepackage{imakeidx}
\usepackage{hyperref}


%=========================================================================
%                             CREATE PERSON NEW
%=========================================================================
%Arguments: 
%   1)  MANDATORY   - Image destination
%   2)  [OPTIONAL]  - Called name
%   3)  MANDATORY   - Reference to the current full name
%   4)  [OPTIONAL]  - Full birth name
%   5)  MANDATORY   - Uniqueue Reference number
%   6)  [OPTIONAL]  - Birth date in the format of dd. mmm. yyyy
%   7)  <OPTIONAL>  - Death date in the format of dd. mmm. yyyy
\NewDocumentCommand\createPerson{r<>omomo+d<>}
{
    \begin{mdframed}[style=whiteBox]%
%        \profileImage[width=0.25\textwidth]{Images/People/ProfileImages/#1}
        \profileImage[width=0.25\textwidth]{#1}%
        \index[nameindex]{#3}
        \begin{tabularx}{0.75\textwidth}[t]{lXrc}%
            % Row one
            Navn:   &   \nameref{#3}    & \textlabel{#5}{PERSON_ID:#3}    & $\Re$%
            %Create new row if needed
            \IfNoValueTF{#2}%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}}%
                        {\\}}%
                    {\\}}%
                {\\}%
            % Row two
            \IfNoValueTF{#4}%
                % If no birth name
                {\IfNoValueTF{#2}%
                    % If no called name
                    {&&}%
                    % If a called name
                    {Kaldenavn: & \textlabel{#2}{KN:#3} &}}%
                %If a birth name
                {Fødenavn: & #4 &}%
                %
                \IfNoValueTF{#6}%
                       % If no birth date
                       {\IfNoValueTF{#7}{}{\textlabel{#7}{DD:#3} & \cross}}%
                       {\textlabel{#6}{FD:#3} & $\star$}%
            % Create new row if needed    
            \IfNoValueTF{#2}%
                {%
                \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                }%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                    }%
                    {\\}%
                }%
            % Row three
            \IfNoValueTF{#2}%
                % If no called name
                {%
                    \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {&&}%
                        }%
                }%
                % If a called name
                {\IfNoValueTF{#4}%
                    % If no birth name
                    {
                        \IfNoValueTF{#6}%
                            {}%
                            {\IfNoValueTF{#7}%
                                {}%
                                {&&}%
                            }%
                    }%
                    %If birth name
                    {Kaldenavn: & \textlabel{#2}{KN:#3} &}%
                }%
            %
            \IfNoValueTF{#7}%
                       % If no death date
                       {}%
                       {\IfNoValueTF{\textlabel{#6}{FD:#3}}{}{\textlabel{#7}{DD:#3} & \cross}}%
        \end{tabularx}%
    \end{mdframed}%
}

%=========================================================================
%                               TEXT LABEL
%=========================================================================
\makeatletter%
% Arguments:
%  1) The text
%  2) The label
\newcommand*{\textlabel}[2]{%
  \edef\@currentlabel{#1}% Set target label
   #1\phantomsection\label{#2}% Print and store label
}
\makeatother



\mdfdefinestyle{whiteBox}{%
    linecolor=black,
    outerlinewidth=0.75pt,
    roundcorner=6pt,
    innertopmargin=10pt,
    innerbottommargin=10pt,
    innerrightmargin=10pt,
    innerleftmargin=10pt,
    backgroundcolor=white,
    outermargin=0cm,
    nobreak=true,
    align=center}

%=========================================================================
%                       Profile image in border
%=========================================================================
\newsavebox\profileImageBox
\NewDocumentCommand{\profileImage}%
      {O{width=0.6\linewidth}
       O{draw=black,line width=0.75pt,rounded corners=6pt}
       m}{%
   \savebox\profileImageBox{\includegraphics[#1]{#3}}%
   \begin{adjustbox}{valign=t}
       \begin{tikzpicture}%
        \draw [path picture={%
                       \node at (path picture bounding box.center) {%
                           \usebox\profileImageBox};},#2]
              (0,0)  rectangle (\wd\profileImageBox,\ht\profileImageBox);
       \end{tikzpicture}%
   \end{adjustbox}%
}

%=========================================================================
%                                 Cross
%=========================================================================
\newcommand{\cross}[1][.7pt]{\ooalign{%
  \rule[1ex]{1ex}{#1}\cr% Horizontal bar
  \hss\rule{#1}{.7em}\hss\cr}% Vertical bar
}


\makeindex[name={nameindex},title={Index of persons}]
\begin{document}

\section{Carl Wilhelm Larsen}
    \label{CarlWilhelmLarsen1867}

    \createPerson%
        <beeduck.jpg>
%        <CarlVilhelmLarsen1867.jpg>%
        [Carl]%
        {CarlWilhelmLarsen1867}%
        {315}%
        [5 maj 1867]%
        <18 maj 1953>%

\printindex[nameindex]

\end{document}

enter image description here

相关内容