Hi guys!
I have just requested the registration of the v0.8.0 of PrettyTables.jl . This version has two major features.
The first is that you can use the function include_pt_to_file to add a table into a file between two marks. This works nice together with LaTeX to update tables when writing reports.
The second is the LaTeX back-end. I tried to add a minimal documentation, but everything should be considered experimental (I havenβt coded any tests about it yetβ¦). Please, open issues on GitHub if you find any bug or strange behavior.
Using the following code:
julia> t = 0:1:20;
julia> data = hcat(t, ones(length(t))*1, 1*t, 0.5.*t.^2);
julia> header = ["Time" "Acceleration" "Velocity" "Distance";
                  "[s]"  "[m/s\$^2\$]"    "[m/s]"      "[m]"];
julia> hl_v = LatexHighlighter( (data,i,j)->(j == 3) && data[i,3] > 9, ["color{blue}","textbf"]);
julia> hl_p = LatexHighlighter( (data,i,j)->(j == 4) && data[i,4] > 10, ["color{red}", "textbf"])
julia> hl_e = LatexHighlighter( (data,i,j)->(i == 10), ["cellcolor{black}", "color{white}", "textbf"])
julia> pretty_table(data, header, backend = :latex, highlighters = (hl_e, hl_p, hl_v))
it is possible to render the following LaTeX table:
             
            
              24 Likes 
            
            
           
          
            
              
                Sijun  
              
                  
                    January 5, 2020,  6:33am
                   
                  2 
               
             
            
              Thank you for beautiful table utility!
The only thing I miss is userβs control over padding size. With backend=:html, there is zero padding between table border and cell border.
I feel a little bit cramped.
             
            
              1 Like 
            
            
           
          
            
            
              
 Sijun:
 
Thank you for beautiful table utility!
The only thing I miss is userβs control over padding size. With backend=:html, there is zero padding between table border and cell border.
 
 
Thanks!
Can you please tell me how you are printing this table? The predefined formats have a padding of 4px and this should not have happened. This is what I see when I render an HTML: HTML Β· Pretty Tables 
             
            
              
            
           
          
            
              
                Sijun  
              
                  
                    January 5, 2020, 11:15pm
                   
                  4 
               
             
            
              @Ronis_BR , thank you for your reply.
I tried printing a table with Weave and I see this:
The padding on the right side of the cell is shown to be as zero.
The content of test.jmd is just:
```julia
df = DataFrame(x=1:3, y=βaβ:βcβ)
```
I tested on Julia 1.3.0 , PrettyTables v0.8.0 , Weave v0.9.1 
             
            
              
            
           
          
            
            
              Can PrettyTables display DataFrames?
             
            
              
            
           
          
            
            
              
I think I need help here. Maybe it is something related to Weave. See the HTML code I get when using your example:
julia> using DataFrames
julia> df = DataFrame(x=1:3, y='a':'c')
using Pr3Γ2 DataFrame
β Row β x     β y    β
β     β Int64 β Char β
βββββββΌββββββββΌβββββββ€
β 1   β 1     β 'a'  β
β 2   β 2     β 'b'  β
β 3   β 3     β 'c'  β
julia> using PrettyTables
[ Info: Precompiling PrettyTables [08abe8d2-0d0c-5749-adfa-8a2ac140af0d]
julia> pretty_table(df, backend = :html)
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<style>
table, td, th {
    border-collapse: collapse;
    font-family: sans-serif;
}
td, th {
    border-bottom: 0;
    padding: 4px
}
tr:nth-child(odd) {
    background: #eee;
}
tr:nth-child(even) {
    background: #fff;
}
tr.header {
    background: navy !important;
    color: white;
    font-weight: bold;
}
tr.subheader {
    background: lightgray !important;
    color: black;
}
tr.headerLastRow {
    border-bottom: 2px solid black;
}
th.rowNumber, td.rowNumber {
    text-align: right;
}
</style>
<body>
<table>
<tr class = header>
<th style = "text-align: right; ">x</th>
<th style = "text-align: right; ">y</th>
</tr>
<tr class = "subheader headerLastRow">
<th style = "text-align: right; ">Int64</th>
<th style = "text-align: right; ">Char</th>
</tr>
<tr>
<td style = "text-align: right; ">1</td>
<td style = "text-align: right; ">a</td>
</tr>
<tr>
<td style = "text-align: right; ">2</td>
<td style = "text-align: right; ">b</td>
</tr>
<tr>
<td style = "text-align: right; ">3</td>
<td style = "text-align: right; ">c</td>
</tr>
</table>
</body>
</html>
Look at the style part that we have padding: 4px. Thus, something is forcing it to be 0.
Yes, it can! In fact, it can print anything that complies with Tables.jl  API.
             
            
              
            
           
          
            
            
              @Sijun 
Notice that everything is fine with Jupyter. I really cannot reproduce this error:
             
            
              
            
           
          
            
              
                Sijun  
              
                  
                    January 5, 2020, 11:59pm
                   
                  8 
               
             
            
              Ah, yes indeed. I tried putting !important at the end in the html file, and it started working.
padding: 4px !important
As you said, Weave seems to overwrite PrettyTables settings. Maybe I need to tell Weave contributors.
             
            
              1 Like 
            
            
           
          
            
            
              And how can I use the html backend? I am using vscode. I just get the html source code printed in the terminal, but this is not what I want.
             
            
              
            
           
          
            
            
              You can define your own HTML style to be used in Weave. Like:
julia> html_weave = HTMLTableFormat(
    css = """
    table, td, th {
        border-collapse: collapse;
        font-family: sans-serif;
    }
    td, th {
        border-bottom: 0;
        padding: 4px !important
    }
    tr:nth-child(odd) {
        background: #eee;
    }
    tr:nth-child(even) {
        background: #fff;
    }
    tr.header {
        background: navy !important;
        color: white;
        font-weight: bold;
    }
    tr.subheader {
        background: lightgray !important;
        color: black;
    }
    tr.headerLastRow {
        border-bottom: 2px solid black;
    }
    th.rowNumber, td.rowNumber {
        text-align: right;
    }
    """
);
julia> df = DataFrame(x=1:3, y='a':'c');
julia> pretty_table(df, backend = :html, tf = html_weave)
 
            
              2 Likes 
            
            
           
          
            
              
                Sijun  
              
                  
                    January 6, 2020, 12:04am
                   
                  11 
               
             
            
              Thank you so much. Now it works very well!
             
            
              1 Like 
            
            
           
          
            
            
              
I do not use vscode. Can it render HTML? The current implementation of the HTML back-end works in Jupyter for example. It prints to stdout using display("text/html", ...). Thus, if what you are using supports HTML, then it should render it as an HTML page. However, maybe it needs tweaking to work in other environments.
             
            
              1 Like 
            
            
           
          
            
            
              I also tried Blink, also doesnβt work. How can I store the html in a string?
             
            
              
            
           
          
            
            
              You can store the HTML as string using an IOBuffer:
julia> io = IOBuffer();
julia> pretty_table(io, [1 1 1; 1 1 1])
julia> str = String(take!(io))
"ββββββββββ¬βββββββββ¬βββββββββ\nβ Col. 1 β Col. 2 β Col. 3 β\nββββββββββΌβββββββββΌβββββββββ€\nβ      1 β      1 β      1 β\nβ      1 β      1 β      1 β\nββββββββββ΄βββββββββ΄βββββββββ\n"
(Just use the HTML back-end in the example above)
             
            
              1 Like