Search code examples
markdownpandoctableofcontents

Pandoc : How to add a table before the table of content?


I would like to add a table before the table of content generated by pandoc/markdown.

I've found the parameter "include-before". With this, I can add text before the table of content. But is there a way to add a table ?

Show my code below. I would like the toc to be between the two tables and the header1 and not before the tables.

Is there another way to achieve that ? I would like to use only one file for the generation.

Thanks for your help

---
geometry: margin=1in
fontfamily: qbookman
numbersections: true
toc: true
toc-title: Table des matières
header-includes: |
    \usepackage{graphicx}
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \setlength\headheight{20pt}
    \lhead{\includegraphics[width=4cm]{C:/logo.png}}
    \rhead{Doc generator}
---

+---------------+---------------------------------------------------------------+
| **Title**     | Markdown - Pandoc - Plantuml \                                
|
+---------------+---------------------------------------------------------------+
| **Customer**  | Customer \                                                      
|
+---------------+---------------------------------------------------------------+
| **Project**   | Doc generator                                                 
|
+---------------+---------------------------------------------------------------+


----------------------------------------------------------------------------------
**VERSION**  **DATE**      **MODIFICATION**                            **AUTHOR**
-----------  ------------- ------------------------------------------- -----------
1.0          20-12-2018    Initial                                     DGO 

----------------------------------------------------------------------------------


# Header 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

Solution

  • There are two options: you can either use the include-before field, it works for text as well as for lists or tables. Just make sure to indent the table.

    ---
    toc: true
    toc-title: Table des matières
    include-before: |
        ----------------------------------------------------------------------
        **VERSION**  **DATE**      **MODIFICATION**                **AUTHOR**
        -----------  ------------- ------------------------------- -----------
        1.0          20-12-2018    Initial                         DGO 
    
        ----------------------------------------------------------------------
    

    Alternatively, you can disable pandoc's toc mechanism and manually add the LaTeX commands to generate the table of contents at the desired location:

    ---
    geometry: margin=1in
    fontfamily: qbookman
    numbersections: true
    toc: false
    header-includes: |
        \usepackage{graphicx}
        \usepackage{fancyhdr}
        \pagestyle{fancy}
        \setlength\headheight{20pt}
        \lhead{\includegraphics[width=4cm]{C:/logo.png}}
        \rhead{Doc generator}
    ---
    
    +---------------+---------------------------------------------------------------+
    | **Title**     | Markdown - Pandoc - Plantuml \                                
    |
    +---------------+---------------------------------------------------------------+
    | **Customer**  | Customer \                                                      
    |
    +---------------+---------------------------------------------------------------+
    | **Project**   | Doc generator                                                 
    |
    +---------------+---------------------------------------------------------------+
    
    
    ----------------------------------------------------------------------------------
    **VERSION**  **DATE**      **MODIFICATION**                            **AUTHOR**
    -----------  ------------- ------------------------------------------- -----------
    1.0          20-12-2018    Initial                                     DGO 
    
    ----------------------------------------------------------------------------------
    
    \renewcommand*\contentsname{Table des matières}
    \tableofcontents
    
    
    # Header 1
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
    incididunt ut labore et dolore magna aliqua.