# PrettyTables linebreak in title

**URL:** <https://discourse.julialang.org/t/prettytables-linebreak-in-title/78017>\
**Category:** General Usage\
**Created:** [March 17, 2022, 10:07am UTC](https://discourse.julialang.org/t/prettytables-linebreak-in-title/78017 "2022-03-17T10:07:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [March 17, 2022, 10:07am UTC](https://discourse.julialang.org/t/prettytables-linebreak-in-title/78017/1 "2022-03-17T10:07:53Z")

</div>

How do I make linebreaks in the header of a `pretty_table`? Here is a MEW of my attempt:

```julia
julia> using PrettyTables

julia> pretty_table(linebreaks=true,
           body_hlines = [1, 2, 3],
           header = ([" " "Actual\npositives" "Actual\nnegatives"],),
               [
                   "Prediced\npositives" 1 2
                   "Prediced\nnegatives" 3 4
                   " " 5 6
               ]
       )
┌───────────┬───────────────────┬───────────────────┐
│ │ Actual\npositives │ Actual\nnegatives │
├───────────┼───────────────────┼───────────────────┤
│ Prediced │ 1 │ 2 │
│ positives │ │ │
├───────────┼───────────────────┼───────────────────┤
│ Prediced │ 3 │ 4 │
│ negatives │ │ │
├───────────┼───────────────────┼───────────────────┤
│ │ 5 │ 6 │
└───────────┴───────────────────┴───────────────────┘

```

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [March 17, 2022, 10:40am UTC](https://discourse.julialang.org/t/prettytables-linebreak-in-title/78017/2 "2022-03-17T10:40:45Z")

</div>

Just a trick like yours with the row headers:

```julia
pretty_table(linebreaks=true,
                  body_hlines = [1, 2, 3],
                  noheader=true,
                      [
                          " " "Actual\npositives" "Actual\nnegatives"
                          "Prediced\npositives" 1 2
                          "Prediced\nnegatives" 3 4
                          " " 5 6
                      ]
              )

```

headers (row+col) are part of the data, so newline is printed.

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [March 17, 2022, 10:42am UTC](https://discourse.julialang.org/t/prettytables-linebreak-in-title/78017/3 "2022-03-17T10:42:59Z")

</div>

Seems hacky, but it works like a charm!

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [March 17, 2022, 12:11pm UTC](https://discourse.julialang.org/t/prettytables-linebreak-in-title/78017/4 "2022-03-17T12:11:16Z")

</div>

Actually linebreaks in headers is what I called subheader (lines below the headers):

```plaintext
pretty_table(linebreaks=true,
                  body_hlines = [1, 2, 3],
                  header = (["", "Actual", "Actual"], ["", "npositives", "nnegatives"]),
                      [
                          "Prediced\npositives" 1 2
                          "Prediced\nnegatives" 3 4
                          " " 5 6
                      ]
              )

```

![Captura de Tela 2022-03-17 às 09.11.07](https://global.discourse-cdn.com/julialang/original/3X/9/2/92668ad1234515fbf9471673896c0f8af3eff101.png)

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [March 17, 2022, 2:28pm UTC](https://discourse.julialang.org/t/prettytables-linebreak-in-title/78017/5 "2022-03-17T14:28:16Z")

</div>

By the way, if you want the same decoration, you can use `AnsiTextCell`:

```julia
julia> cb = crayon"bold";

julia> cg = crayon"dark_gray";

julia> pretty_table(linebreaks=true,
                  body_hlines = [1, 2, 3],
                  header = (["", "Actual", "Actual"], ["", "positives", "negatives"]),
                      [
                          AnsiTextCell("$(cb)Prediced\n$(cg)positives") 1 2
                          AnsiTextCell("$(cb)Prediced\n$(cg)negatives") 3 4
                          " " 5 6
                      ]
              )

```

![Captura de Tela 2022-03-17 às 11.28.07](https://global.discourse-cdn.com/julialang/original/3X/a/a/aa00c8b07d4517733c375ad69cda3e95b1db147d.png)
