目录中除标题之外的附加值

目录中除标题之外的附加值

我有一个包含多个部分的文章类。除了部分标题之外,我还想在表中包含更多值。为了更好地理解:它将是一本歌本,其中部分没有“标题”,但有“歌曲标题”和“解释”。以下 ssce 显示了我的意思:

\documentclass{article}

\begin{document}
    \tableofcontents
    \section[FIRST VALUE - SECOND VALUE]{FIRST VALUE}{test1}
    \section[FIRST - VALUE - WITH - HYPEN - STILL SECOND VALUE]{FIRST - VALUE - WITH - HYPEN}{test2}
    \section[FIRST - VALUE - WITH - HYPEN - ALSO SECOND VALUE - WITH HYPEN]{FIRST - VALUE - WITH - HYPEN}{test3}


    \section*{Expected TOC}{
        \begin{tabular}{|l|l|l|}
        \hline
        \multicolumn{1}{|c|}{\textbf{\#}} & \multicolumn{1}{c|}{\textbf{Title}} & \multicolumn{1}{c|}{\textbf{Interpret}} \\ \hline
        1                                 & FIRST VALUE                         & SECOND VALUE                            \\ \hline
        2                                 & FIRST - VALUE - WITH - HYPEN        & STILL SECOND VALUE                      \\ \hline
        3                                 & FIRST - VALUE - WITH - HYPEN        & ALSO SECOND VALUE - WITH HYPEN          \\ \hline
        \end{tabular}
    }
\end{document}

生成:

输出

根据这些部分,我尝试从“预期目录”创建结果。但不幸的是,我无法在网上找到任何帮助。我想我用错了流行语。有人能指出正确的方向吗?由于我使用 leadsheet 包来记录和弦符号,所以我只能使用“部分”。

以下是更真实场景的示例:

\documentclass{article}
\usepackage{leadsheets}
\usepackage{array}

\definesongtitletemplate{title}{
    \ifsongmeasuring {
        \section*
    }{
        \section[\songproperty{title}\hfill\songproperty{interpret}]{\songproperty{title}}
    }
    \footnotesize{\GetTranslation{leadsheets/interpret}}
}

\setleadsheets{title-template = title}

\begin{document}
    \tableofcontents
    \begin{song}{title={Song 1}, interpret={Author 1}}
        \begin{verse}
            Mary had a little lamb \\
            Its fleece was white as snow, yea \\
        \end{verse}
    \end{song}
    \begin{song}{title={Song 2}, interpret={Auth fdsa fdsa fdsa fdsafsor 2}}
        \begin{verse}
            Mary had a little lamb \\
            Its fleece was white as snow, yea \\
        \end{verse}
    \end{song}
    \begin{song}{title={Song fdsa fdsa fdsa fdsa fdas 3}, interpret={Author 3}}
        \begin{verse}
            Mary had a little lamb \\
            Its fleece was white as snow, yea \\
        \end{verse}
    \end{song}
\end{document}

章节标题的值之间包含 \hfill,但它使歌曲标题左对齐,而解释右对齐。

答案1

我能够使用 etoc 和 substr 包实现目标。使用 etoc 包可以创建目录表,使用 substr 包可以提取章节标题的部分内容:

\documentclass{article}
\usepackage{leadsheets}
\usepackage{array}
\usepackage{etoc}
\usepackage{longtable}
\usepackage{bookmark}
\usepackage{substr}
\usepackage{framed}
\usepackage{varioref}


\definesongtitletemplate{title}{
    \ifsongmeasuring {
        \section*
    }{
        \section[\songproperty{title}!-!?!\songproperty{interpret}]{\songproperty{title}}
    }
    \footnotesize{\GetTranslation{leadsheets/interpret}}
}

\setleadsheets{title-template = title}


\etocglobaldefs

\etocsetstyle{section}
  {}
  {\etociffirst{\etocifnumbered{\\\hline}{\\\hline\hline}}{\\\hline}}
  {\etocnumber & \BeforeSubString{!-!?!}{\etocthename} & \BehindSubString{!-!?!}{\etocthename}}
  {}

\etocsettocstyle{
    \hypersetup{hidelinks}
    \begin{longtable}{
        |>{\bfseries}c|p{7cm}|p{7cm}|
    }
    \multicolumn{3}{c}{\Large\bfseries\strut\strut Songlist}
    \\\hline
    \ & \textbf{Title} & \textbf{Interpret}
}
{
    \\\hline
    \end{longtable}
}

\begin{document}
    \tableofcontents
    \begin{song}{title={Song 1}, interpret={Author 1}}
        \begin{verse}
            Mary had a little lamb \\
            Its fleece was white as snow, yea \\
        \end{verse}
    \end{song}
    \begin{song}{title={Song 2}, interpret={Auth fdsa fdsa fdsa fdsafsor 2}}
        \begin{verse}
            Mary had a little lamb \\
            Its fleece was white as snow, yea \\
        \end{verse}
    \end{song}
    \begin{song}{title={Song fdsa fdsa fdsa fdsa fdas 3}, interpret={Author 3}}
        \begin{verse}
            Mary had a little lamb \\
            Its fleece was white as snow, yea \\
        \end{verse}
    \end{song}
\end{document}

最终结果正如预期: 上述代码的结果 我不确定这种字符串处理是否真的是“乳胶方式”,但它确实有效。

相关内容