TransWikia.com

Additional values besides title in TOC

TeX - LaTeX Asked by Alex Volodko on March 27, 2021

I have an article class with multiple sections. I would like to include more values in TOC, beside just the title of the section, in a table representation. For better understanding: it will be a song book, where the section does not have a "title", but "song title" and "interpret".
The following ssce shows what I mean:

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}

generates:

output

Based on the sections I try to create the result from "Expected TOC". But unfortunatly I am not able to find any help online. I assume I am using wrong buzzwords for it.
Can anyone point in the right direction to look at?
Since I am using leadsheet package for the chord notation I am limited to "section" usage.

Here is an example of more real scenario:

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

definesongtitletemplate{title}{
    ifsongmeasuring {
        section*
    }{
        section[songproperty{title}hfillsongproperty{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}

The section title contains hfill between the values, but it makes the song title left aligned and the interpret right aligned.

One Answer

I was able to achive the goal using etoc and substr packages. With etoc package it is possible to create tables as TOC and with substr package I am extracting the parts of the section title:

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}{hlinehline}}{hline}}
  {etocnumber & BeforeSubString{!-!?!}{etocthename} & BehindSubString{!-!?!}{etocthename}}
  {}

etocsettocstyle{
    hypersetup{hidelinks}
    begin{longtable}{
        |>{bfseries}c|p{7cm}|p{7cm}|
    }
    multicolumn{3}{c}{Largebfseriesstrutstrut 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}

This ends up as expected: Result of the code above I am not sure if this string handling really is the "latex way" to go, but it works.

Correct answer by Alex Volodko on March 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP