Search code examples
markdownpresentationmarp

Insert Tables in Marp


I amm using Marp to produce presentations in pdf (markdown syntax). For a presentation i have to insert tables from pandas dataframe. The trick i use for now is to print "to_markdown" thanks to pandas and copy paste the result into my markdown code, but i have no possibility to change font size and choose where to put the table. The Marp documentation is not so helpful for this type of issue. How can i modify font size and table localisation in markdown?


Solution

  • You can style the table in any way you'd like through the availability of the style attribute (both globally or scoped to just a single slide).

    For example, you can take your markdown tables and chnage their appearance by adjusting the necessary CSS selectors. By default this will apply globally but if you add scoped after the style tag then it will only act on that slide. (See the marp documentation for more info).

    This allows you to set-up all kinds of styles for tables -- even setting a general style that can be tweaked as necesasry for each slide.

    See the example below.

    
    ---
    marp: true
    theme: default
    ---
    
    <style scoped>
    table {
        height: 100%;
        width: 100%;
        font-size: 20px;
        color: red;
    }
    th {
        color: blue;
    }
    </style>
    
    # Fruit Table -- styled
    
    Fruit | Colour | Amount | Cost
    -----|------|:-----:|------:
    Banana | Yellow | 4 | £1.00
    Apple | Red | 2 | £0.60
    Orange | Orange | 10 | £2.50
    Coconut | Brown | 1 | £1.50
    
    ---
    
    # Fruit Table -- default
    
    Fruit | Colour | Amount | Cost
    -----|------|:-----:|------:
    Banana | Yellow | 4 | £1.00
    Apple | Red | 2 | £0.60
    Orange | Orange | 10 | £2.50
    Coconut | Brown | 1 | £1.50