Library

Documentation for PrettyTables.jl.

PrettyTables.ColumnTableType
struct ColumnTable

This structure helps to access elements that comply with the column access specification of Tables.jl.

source
PrettyTables.DisplayType
struct Display

Store the information of the display and the current cursor position.

Note

This is not the real cursor position with respect to the display, but with respect to the point in which the table is printed.

Fields

  • size::Tuple{Int, Int}: Display size.
  • row::Int: Current row.
  • column::Int: Current column.
  • has_color::Bool: Indicates if the display has color support.
  • buf_line::IOBuffer: Buffer that stores the current line.
  • buf::IOBuffer: Buffer that stores the entire output.
source
PrettyTables.EmptyCellsType
struct EmptyCells

Specification for adding a set of empty cells at the column label rows.

Fields

  • number_of_cells::Int: Number of cells to add (must be greater than 0).
source
PrettyTables.HtmlHighlighterType
struct HtmlHighlighter

Define the default highlighter of a table when using the HTML back end.

Fields

  • f::Function: Function with the signature f(data, i, j) in which should return true if the element (i, j) in data must be highlighted, or false otherwise.
  • fd::Function: Function with the signature f(h, data, i, j) in which h is the highlighter. This function must return a Vector{Pair{String, String}} with properties compatible with the style field that will be applied to the highlighted cell.
  • _decoration::Dict{String, String}: The decoration to be applied to the highlighted cell if the default fd is used.

Remarks

This structure can be constructed using three helpers:

HtmlHighlighter(f::Function, decoration::Vector{Pair{String, String}})

HtmlHighlighter(f::Function, decorations::NTuple{N, Pair{String, String})

HtmlHighlighter(f::Function, fd::Function)

The first will apply a fixed decoration to the highlighted cell specified in decoration, whereas the second let the user select the desired decoration by specifying the function fd.

source
PrettyTables.HtmlTableFormatType
HtmlTableFormat

Format that will be used to print the HTML table. All parameters are strings compatible with the corresponding HTML property.

Fields

  • css::String: CSS to be injected at the end of the <style> section.
  • table_width::String: Table width.

Notice that this format is only applied if stand_alone = true.

source
PrettyTables.HtmlTableStyleType
struct HtmlTableStyle

Define the style of the tables printed with the HTML back end.

Fields

  • top_left_string::Vector{HtmlPair}: Style for the top left string.
  • top_right_string::Vector{HtmlPair}: Style for the top right string.
  • table::Vector{HtmlPair}: Style for the table.
  • title::Vector{HtmlPair}: Style for the title.
  • subtitle::Vector{HtmlPair}: Style for the subtitle.
  • row_number_label::Vector{HtmlPair}: Style for the row number label.
  • row_number::Vector{HtmlPair}: Style for the row number.
  • stubhead_label::Vector{HtmlPair}: Style for the stubhead label.
  • row_label::Vector{HtmlPair}: Style for the row label.
  • row_group_label::Vector{HtmlPair}: Style for the row group label.
  • first_line_column_label::Vector{HtmlPair}: Style for the first line of the column labels.
  • column_label::Vector{HtmlPair}: Style for the column label.
  • first_line_merged_column_label::Vector{HtmlPair}: Style for the merged cells at the first column label line.
  • merged_column_label::Vector{HtmlPair}: Style for the merged cells at the rest of the column labels.
  • summary_row_cell::Vector{HtmlPair}: Style for the summary row cell.
  • summary_row_label::Vector{HtmlPair}: Style for the summary row label.
  • footnote::Vector{HtmlPair}: Style for the footnote.
  • source_notes::Vector{HtmlPair}: Style for the source notes.
source
PrettyTables.LatexHighlighterType
LatexHighlighter

Defines the default highlighter of a table when using the LaTeX backend.

Fields

  • f::Function: Function with the signature f(data, i, j) in which should return true if the element (i, j) in data must be highlighted, or false otherwise.
  • fd: A function with the signature f(h, data, i, j)::Vector{String} in which h is the highlighter object, data is the matrix, and (i, j) is the element position in the table. This function should return a vector with the LaTeX environments to be applied to the cell.

Remarks

This structure can be constructed using two helpers:

LatexHighlighter(f::Function, envs::Vector{String})

where it will apply recursively all the LaTeX environments in envs to the highlighted text, and

LatexHighlighter(f::Function, fd::Function)

where the user select the desired decoration by specifying the function fd.

Thus, for example:

LatexHighlighter((data, i, j) -> true, ["textbf", "small"])

will wrap all the cells in the table in the following environment:

\textbf{\small{<Cell text>}}
source
PrettyTables.LatexTableFormatType
struct LatexTableFormat

Define the format of the tables printed with the LaTeX back end.

Fields

  • borders::LatexTableBorders: Format of the borders.
  • horizontal_line_at_beginning::Bool: If true, a horizontal line will be drawn at the beginning of the table.
  • horizontal_line_after_column_labels::Bool: If true, a horizontal line will be drawn after the column labels.
  • horizontal_lines_at_data_rows::Union{Symbol, Vector{Int}}: A horizontal line will be drawn after each data row index listed in this vector. If the symbol :all is passed, a horizontal line will be drawn after every data column. If the symbol :none is passed, no horizontal lines will be drawn after the data rows.
  • horizontal_line_before_row_group_label::Bool: If true, a horizontal line will be drawn before the row group label.
  • horizontal_line_after_row_group_label::Bool: If true, a horizontal line will be drawn after the row group label.
  • horizontal_line_after_data_rows::Bool: If true, a horizontal line will be drawn after the data rows.
  • horizontal_line_after_summary_rows::Bool: If true, a horizontal line will be drawn after the summary rows.
  • vertical_line_at_beginning::Bool: If true, a vertical line will be drawn at the beginning of the table.
  • vertical_line_after_row_number_column::Bool: If true, a vertical line will be drawn after the row number column.
  • vertical_line_after_row_label_column::Bool: If true, a vertical line will be drawn after the row label column.
  • vertical_lines_at_data_columns::Union{Symbol, Vector{Int}}: A vertical line will be drawn after each data column index listed in this vector. If the symbol :all is passed, a vertical line will be drawn after every data column. If the symbol :none is passed, no vertical lines will be drawn after the data columns.
  • vertical_line_after_data_columns::Bool: If true, a vertical line will be drawn after the data columns.
  • vertical_line_after_continuation_column::Bool: If true, a vertical line will be drawn after the continuation column.
source
PrettyTables.LatexTableStyleType
struct LatextTableStyle

Define the style of the tables printed with the latex back end.

Fields

  • title::LatexEnvironments: Latex environments with the style for the title.
  • subtitle::LatexEnvironments: Latex environments with the style for the subtitle.
  • row_number_label::LatexEnvironments: Latex environments with the style for the row number label.
  • row_number::LatexEnvironments: Latex environments with the style for the row numbers.
  • stubhead_label::LatexEnvironments: Latex environments with the style for the stubhead label.
  • row_label::LatexEnvironments: Latex environments with the style for the row labels.
  • row_group_label::LatexEnvironments: Latex environments with the style for the row group label.
  • first_line_column_label::LatexEnvironments: Latex environments with the style for the first column label lines.
  • column_label::LatexEnvironments: Latex environments with the style for the rest of the column labels.
  • first_line_merged_column_label::LatexEnvironments: Latex environments with the style for the merged cells at the first column label line.
  • merged_column_label::LatexEnvironments: Latex environments with the style for the merged cells at the rest of the column labels.
  • summary_row_cell::LatexEnvironments: Latex environments with the style for the summary row cell.
  • summary_row_label::LatexEnvironments: Latex environments with the style for the summary row label.
  • footnote::LatexEnvironments: Latex environments with the style for the footnotes.
  • source_note::LatexEnvironments: Latex environments with the style for the source notes.
  • omitted_cell_summary::LatexEnvironments: Latex environments with the style for the omitted cell summary.
source
PrettyTables.MarkdownHighlighterType
struct MarkdownHighlighter

Defines the default highlighter of a table when using the markdown backend.

Fields

  • f::Function: Function with the signature f(data, i, j) in which should return true if the element (i, j) in data must be highlighter, or false otherwise.
  • fd::Function: Function with the signature fd(h, data, i, j) in which h is the highlighter. This function must return the MarkdownStyle to be applied to the cell that must be highlighted.
  • _decoration::MarkdownStyle: The decoration to be applied to the highlighted cell if the default fd is used.

Remarks

This structure can be constructed using two helpers:

MarkdownHighlighter(f::Function, decoration::MarkdownStyle)

MarkdownHighlighter(f::Function, fd::Function)

The first will apply a fixed decoration to the highlighted cell specified in decoration whereas the second let the user select the desired decoration by specifying the function fd.

source
PrettyTables.MarkdownStyleType
struct MarkdownStyle

Structure that defines styling parameters to a table cell in the markdown back end.

Fields

  • bold::Bool: Bold text.
  • italic::Bool: Italic text.
  • strikethrough::Bool: Strikethrough.
  • code::Bool: Code.
source
PrettyTables.MarkdownTableFormatType
struct MarkdownTableFormat

Define the format of the tables printed with the markdown back end.

Fields

  • title_heading_level::Int: Title heading level.
  • subtitle_heading_level::Int: Subtitle heading level.
  • horizontal_line_char::Char: Character used to draw the horizontal line.
  • line_before_summary_rows::Bool: Whether to draw a line before the summary rows.
source
PrettyTables.MarkdownTableStyleType
struct MarkdownTableStyle

Define the style of the tables printed with the markdown back end.

Fields

  • row_number_label::MarkdownStyle: Style for the row number label.
  • row_number::MarkdownStyle: Style for the row number.
  • stubhead_label::MarkdownStyle: Style for the stubhead label.
  • row_label::MarkdownStyle: Style for the row label.
  • row_group_label::MarkdownStyle: Style for the row group label.
  • first_column_label::MarkdownStyle: Style for the first line of the column labels.
  • column_label::MarkdownStyle: Style for the column label.
  • summary_row_label::MarkdownStyle: Style for the summary row label.
  • summary_row_cell::MarkdownStyle: Style for the summary row cell.
  • footnote::MarkdownStyle: Style for the footnote.
  • source_note::MarkdownStyle: Style for the source note.
  • omitted_cell_summary::MarkdownStyle: Style for the omitted cell summary.
source
PrettyTables.MultiColumnType
struct MultiColumn

Specification for merging columns at the column label rows.

Fields

  • column_span::Int: Number of columns to merge (must be greater than 1).
  • data::Any: Merged cell data.
  • alignment::Symbol: Merge cell alignment.
source
PrettyTables.PrintingTableStateType
struct PrintingTableState

This structure stores the current state of the printing process.

Fields

  • state::Int: The current state of the printing process.
  • i::Int: The current row index.
  • j::Int: The current column index.
  • row_section::Symbol: The current or the next row section.
Warning

The field row_section is used to determine the next state of the printing process. It must not be used to verify the current or the next row section as the meaning can change depending on the current state. Instead, always used the function _next to obtain the next row section.

source
PrettyTables.RowTableType
struct RowTable

This structure helps to access elements that comply with the row access specification of Tables.jl.

source
PrettyTables.TextHighlighterType
struct TextHighlighter

Defines the default highlighter of a table when using the text backend.

Fields

  • f::Function: Function with the signature f(data, i, j) in which should return true if the element (i, j) in data must be highlighter, or false otherwise.
  • fd::Function: Function with the signature f(h, data, i, j) in which h is the highlighter. This function must return the Crayon to be applied to the cell that must be highlighted.
  • crayon::Crayon: The Crayon to be applied to the highlighted cell if the default fd is used.

Remarks

This structure can be constructed using three helpers:

TextHighlighter(f::Function; kwargs...)

where it will construct a Crayon using the keywords in kwargs and apply it to the highlighted cell,

TextHighlighter(f::Function, crayon::Crayon)

where it will apply the crayon to the highlighted cell, and

TextHighlighter(f::Function, fd::Function)

where it will apply the Crayon returned by the function fd to the highlighted cell.

source
PrettyTables.TextTableBordersType
struct TextTableBorders

Define the format of the borders in the tables printed with the text back end.

Fields

  • up_right_corner::Char: Character in the up right corner.
  • up_left_corner::Char: Character in the up left corner.
  • bottom_left_corner::Char: Character in the bottom left corner.
  • bottom_right_corner::Char: Character in the bottom right corner.
  • up_intersection::Char: Character in the intersection of lines in the up part.
  • left_intersection::Char: Character in the intersection of lines in the left part.
  • right_intersection::Char: Character in the intersection of lines in the right part.
  • middle_intersection::Char: Character in the intersection of lines in the middle of the table.
  • bottom_intersection::Char: Character in the intersection of the lines in the bottom part.
  • column::Char: Character in a vertical line inside the table.
  • row::Char: Character in a horizontal line inside the table.
source
PrettyTables.TextTableFormatType
struct TextTableFormat

Define the format of the tables printed with the text back end.

Fields

  • borders::TextTableBorders: Format of the borders.
  • horizontal_line_at_beginning::Bool: If true, a horizontal line will be drawn at the beginning of the table.
  • horizontal_lines_at_column_labels::Union{Symbol, Vector{Int}}: A horizontal line will be drawn after each column label row index listed in this vector. If the symbol :all is passed, a horizontal line will be drawn after every column label. If the symbol :none is passed, no horizontal lines will be drawn.
  • horizontal_line_after_column_labels::Bool: If true, a horizontal line will be drawn after the column labels.
  • horizontal_lines_at_data_rows::Union{Symbol, Vector{Int}}: A horizontal line will be drawn after each data row index listed in this vector. If the symbol :all is passed, a horizontal line will be drawn after every data column. If the symbol :none is passed, no horizontal lines will be drawn.
  • horizontal_line_before_row_group_label::Bool: If true, a horizontal line will be drawn before the row group label.
  • horizontal_line_after_row_group_label::Bool: If true, a horizontal line will be drawn after the row group label.
  • horizontal_line_after_data_rows::Bool: If true, a horizontal line will be drawn after the data rows.
  • horizontal_line_after_summary_rows::Bool: If true, a horizontal line will be drawn after the summary rows.
  • vertical_line_at_beginning::Bool: If true, a vertical line will be drawn at the beginning of the table.
  • vertical_line_after_row_number_column::Bool: If true, a vertical line will be drawn after the row number column.
  • vertical_line_after_row_label_column::Bool: If true, a vertical line will be drawn after the row label column.
  • vertical_lines_at_data_columns::Union{Symbol, Vector{Int}}: A vertical line will be drawn after each data column index listed in this vector. If the symbol :all is passed, a vertical line will be drawn after every data column. If the symbol :none is passed, no vertical lines will be drawn after the data columns.
  • vertical_line_after_data_columns::Bool: If true, a vertical line will be drawn after the data columns.
  • vertical_line_after_continuation_column::Bool: If true, a vertical line will be drawn after the continuation column.
  • ellipsis_line_skip::Integer: Number of lines to skip when printing an ellipsis.
source
PrettyTables.TextTableStyleType
struct TextTableStyle

Define the style of the tables printed with the text back end.

Fields

  • title::Crayon: Crayon with the style for the title.
  • subtitle::Crayon: Crayon with the style for the subtitle.
  • row_number_label::Crayon: Crayon with the style for the row number label.
  • row_number::Crayon: Crayon with the style for the row numbers.
  • stubhead_label::Crayon: Crayon with the style for the stubhead label.
  • row_label::Crayon: Crayon with the style for the row labels.
  • row_group_label::Crayon: Crayon with the style for the row group label.
  • first_line_column_label::Crayon: Crayon with the style for the first column label lines.
  • column_label::Crayon: Crayon with the style for the rest of the column labels.
  • first_line_merged_column_label::Crayon: Crayon with the style for the merged cells at the first column label line.
  • merged_column_label::Crayon: Crayon with the style for the merged cells at the rest of the column labels.
  • summary_row_cell::Crayon: Crayon with the style for the summary row cell.
  • summary_row_label::Crayon: Crayon with the style for the summary row label.
  • footnote::Crayon: Crayon with the style for the footnotes.
  • source_note::Crayon: Crayon with the style for the source notes.
  • omitted_cell_summary::Crayon: Crayon with the style for the omitted cell summary.
  • table_border::Crayon: Crayon with the style for the table border.
source
PrettyTables._align_column_with_regex!Method
_align_column_with_regex!(column::AbstractVector{String}, alignment_anchor_regex::Vector{Regex}, alignment_anchor_fallback::Symbol) -> Int
_align_column_with_regex!(column::AbstractVector{Vector{String}}, alignment_anchor_regex::Vector{Regex}, alignment_anchor_fallback::Symbol) -> Int

Align the lines in the column at the first match obtained by the regex vector alignment_anchor_regex, falling back to alignment_anchor_fallback if a match is not found for a specific line.

This function returns the largest cell width.

Note

In the second signature, each element in column must be a vector of Strings, where each string is a line.

source
PrettyTables._align_multline_column_with_regex!Method
_align_multline_column_with_regex!(column::AbstractVector{String}, alignment_anchor_regex::Vector{Regex}, alignment_anchor_fallback::Symbol,) -> Int

Similar to _align_column_with_regex!, but each row will be split into multiple lines at before applying the alignment.

source
PrettyTables._aprintFunction
_aprint(buf::IO, str::String, indentation_level::Int = 0, indentation_spaces::Int = 2; kwargs...) -> Nothing

Print str in the buffer buf aligned to the indentation_level. Each indentation level contains a number of spaces given by indentation_spaces.

Keywords

  • minify::Bool: If true, the output will be minified, meaning that it will be printed without indentation spaces or line breaks. (Default: false)
source
PrettyTables._aprintlnFunction
_aprintln(buf::IO, str::String, indentation_level::Int = 0, indentation_spaces::Int = 2; kwargs...) -> Nothing

Print str in the buffer buf aligned to the indentation_level and adding a line break at the end. Each indentation level contains a number of spaces given by indentation_spaces.

Keywords

  • minify::Bool: If true, the output will be minified, meaning that it will be printed without indentation spaces or line breaks. (Default: false)
source
PrettyTables._current_cellMethod
_current_cell(action::Symbol, state::PrintingTableState, table_data::TableData) -> Any

Return the current data specified by the action and the current printing table state of table_data.

source
PrettyTables._current_cell_alignmentMethod
_current_cell_alignment(action::Symbol, state::PrintingTableState, table_data::TableData) -> Symbol

Return the alignment where the current cell specified by the action and the current printing table state of table_data.

source
PrettyTables._current_cell_footnotesMethod
_current_cell_footnotes(table_data::TableData, cell_type::Symbol, i::Int, j::Int) -> Union{Nothing, Vector{Int}}

Return an array of integers with the footnotes defined in table_data for the cell_type at position (i, j).

source
PrettyTables._html__cell_to_strMethod
_html__cell_to_str(cell::Any, context::IOContext, renderer::Union{Val{:print}, Val{:show}}) -> String

Convert the cell to a string using a specific context and renderer.

source
PrettyTables._html__create_tagMethod
_html__create_tag(tag::String, content::String; kwargs...) -> String

Create an HTML tag with the content.

Keywords

  • properties::Union{Nothing, Vector{HtmlPair}}: Tag properties. (Default: nothing)
  • style::Union{Nothing, Vector{HtmlPair}}: Tag style. (Default: nothing)
source
PrettyTables._html__escape_strFunction
_html__escape_str(@nospecialize(io::IO), s::AbstractString, replace_newline::Bool = false, escape_html_chars::Bool = true) -> Nothing
_html__escape_str(s::AbstractString, replace_newline::Bool = false, escape_html_chars::Bool = true) -> String

Print the string s in io escaping the characters for the HTML back end. If io is omitted, the escaped string is returned.

If replace_newline is true, is replaced with <br>. Otherwise, it is escaped, leading to \n.

If escape_html_chars is true, &, <, >, ", and ' will be replaced by HTML sequences.

source
PrettyTables._html__open_tagMethod
_html__open_tag(tag::String; kwargs...) -> String

Create the string that opens the HTML tag.

Keywords

  • properties::Union{Nothing, Vector{HtmlPair}}: Tag properties. (Default: nothing)
  • style::Union{Nothing, Vector{HtmlPair}}: Tag style. (Default: nothing)
source
PrettyTables._html__print_top_bar_sectionMethod
_html__print_top_bar_section(buf::IOContext, position::String, text::String, decoration::Union{Nothing, Vector{HtmlPair}}, il::Int, ns::Int; kwargs...)

Print the HTML top bar section.

Arguments

  • buf::IOContext: Buffer to which the top bar will be printed.
  • position::String: Buffer position. It can be "left" or "right".
  • text::String: Text to be printed in the selected position.
  • decoration::Union{Nothing, Vector{HtmlPair}}: Text decoration.
  • il::Int: Indentation level.
  • ns::Int: Number of space per indentation level.

Keywords

  • minify::Bool: If true, the output will be minified. (Default: false)
source
PrettyTables._html__render_cellMethod
_html__render_cell(cell::Any, context::IOContext, renderer::Union{Val{:print}, Val{:show}}; kwargs...) -> String

Render the cell in HTML back end using a specific context and renderer.

Keywords

  • allow_html_in_cells::Bool: If true, we will not escape HTML sequences in the rendered string. (Default: false)
  • line_breaks::Bool: If true, we will replace \n with <br>. (Default: false)
source
PrettyTables._is_column_label_cell_mergedMethod
_is_column_label_cell_merged(table_data::TableData, i::Int, j::Int) -> Bool

Return whether the cell at (i, j) is a merged column label cell. Notice that this function returns true only if (i, j) is in the middle of the merged cell. If the merged cell starts at (i, j), this function returns false.

source
PrettyTables._latex__add_environmentsMethod
_latex__add_environments(str::String, envs::Union{Nothing, Vector{String}}) -> String

Apply the latex environments in envs to the string str. If envs is nothing, it returns str unchanged.

source
PrettyTables._latex__cell_to_strMethod
_latex__cell_to_str(cell::Any, context::IOContext, renderer::Union{Val{:print}, Val{:show}}) -> String

Convert the cell to a string using a specific context and renderer.

source
PrettyTables._latex__escape_strFunction
_latex__escape_str(@nospecialize(io::IO), s::AbstractString, replace_newline::Bool = false, escape_latex_chars::Bool = true) -> Nothing
_latex__escape_str(s::AbstractString, replace_newline::Bool = false, escape_latex_chars::Bool = true) -> String

Print the string s in io escaping the characters for the latex back end. If io is omitted, the escaped string is returned.

If replace_newline is true, is replaced with <br>. Otherwise, it is escaped, leading to \n.

If escape_latex_chars is true, &, <, >, ", and ' will be replaced by latex sequences.

source
PrettyTables._latex__render_cellMethod
_latex__render_cell(cell::Any, context::IOContext, renderer::Union{Val{:print}, Val{:show}}; kwargs...) -> String

Render the cell in latex back end using a specific context and renderer.

source
PrettyTables._latex__table_header_descriptionMethod
_latex__table_header_description(td::TableData, tf::LatexTableFormat, vertical_lines_at_data_columns::AbstractVector{Int}) -> String

Create the LaTeX table header description with the column alignments and vertical lines considering the table data td, table format tf, and the processed information about vertical lines at data columns vertical_lines_at_data_columns.

source
PrettyTables._markdown__cell_to_strMethod
_markdown__cell_to_str(cell::Any, context::IOContext, renderer::Union{Val{:print}, Val{:show}}) -> String

Convert the cell to a string using a specific context and renderer.

source
PrettyTables._markdown__column_alignment_strMethod
_markdown__column_alignment_str(column_width::Int, alignment::Symbol) -> String

Compose the markdown alignment string given a column with width column_width. The possible values for alignment are:

  • :l: Left alignment.
  • :c: Center alignment.
  • :r: Right alignment.
  • :n: No alignment information will be added to the string.
source
PrettyTables._markdown__escape_strMethod
_markdown__escape_str(@nospecialize(io::IO), s::AbstractString, replace_newline::Bool = false, escape_markdown_chars::Bool = true) -> Nothing
_markdown__escape_str(s::AbstractString, replace_newline::Bool = false, escape_markdown_chars::Bool = true) -> String

Print the string s in io escaping the characters for the markdown back end. If io is omitted, the escaped string is returned.

If replace_newline is true, is replaced with <br>. Otherwise, it is escaped, leading to \n.

If escape_markdown_chars is true, *, _, ~, \, and|` will be escaped.

source
PrettyTables._markdown__print_alignedMethod
_markdown__print_aligned(buf::IOContext, str::String, cell_width::Int, alignment::Symbol) -> Nothing

Print str to the buffer buf with alignment considering the cell_width.

source
PrettyTables._markdown__print_header_separatorMethod
_markdown__print_header_separator(buf::IOContext, table_data::TableData, row_number_column_width::Int, row_label_column_width::Int, printed_data_column_widths::Vector{Int}) -> Nothing

Print the markdown header separator with the column alignment information.

Arguments

  • buf::IOContext: Buffer where the separator will be printed.
  • table_data::TableData: Table data.
  • row_number_column_width::Int: Row number column width.
  • row_label_column_width::Int: Row label column width.
  • printed_data_column_widths::Vector{Int}: Widths of the printed data columns.
source
PrettyTables._markdown__print_row_group_lineMethod
_markdown__row_group_line(buf::IOContext, row_group_label::String, table_data::TableData, char::Char, row_number_column_width::Int, row_label_column_width::Int, printed_data_column_widths::Vector{Int}) -> Nothing

Print the row group line to buf.

Arguments

  • buf::IOContext: Buffer where the separator will be printed.
  • row_group_label::String: Row group label.
  • table_data::TableData: Table data.
  • char::Char: Character used for the separation line.
  • row_number_column_width::Int: Row number column width.
  • row_label_column_width::Int: Row label column width.
  • printed_data_column_widths::Vector{Int}: Widths of the printed data columns.
source
PrettyTables._markdown__print_separation_lineMethod
_markdown__row_separation_line(buf::IOContext, table_data::TableData, char::Char, row_number_column_width::Int, row_label_column_width::Int, printed_data_column_widths::Vector{Int}) -> Nothing

Print a row separation line to buf.

Arguments

  • buf::IOContext: Buffer where the separator will be printed.
  • table_data::TableData: Table data.
  • char::Char: Character used for the separation line.
  • row_number_column_width::Int: Row number column width.
  • row_label_column_width::Int: Row label column width.
  • printed_data_column_widths::Vector{Int}: Widths of the printed data columns.
source
PrettyTables._markdown__render_cellMethod
_markdown__render_cell(cell::Any, context::IOContext, renderer::Union{Val{:print}, Val{:show}}; kwargs...) -> String

Render the cell in markdown back end using a specific context and renderer.

Keywords

  • allow_markdown_in_cells::Bool: If true, we will not escape markdown sequences in the rendered string. (Default: false)
  • line_breaks::Bool: If true, we will replace \n with <br>. (Default: false)
source
PrettyTables._nextMethod
_next(state::PrintingTableState, table_data::TableData) -> Union{Symbol, Nothing}, PrintingTableState

Return the action the back end must perform and the new print table state given the current state and the table_data.

source
PrettyTables._omitted_cell_summaryMethod
_omitted_cell_summary(num_omitted_rows::Int, num_omitted_columns::Int) -> String

Return the omitted cell summary string when there are num_omitted_rows omitted data rows and num_omitted_columns omitted data columns.

source
PrettyTables._omitted_cell_summaryMethod
_omitted_cell_summary(table_data::TableData, pspec::PrintingSpec) -> String

Return the omitted cell summary related to the table_data and printing specification pspec.

source
PrettyTables._preprocess_dataMethod
_preprocess_data(data::Any) -> Any

Preprocess the data for printing. This function throws an error if data is not supported by PrettyTables.jl.

source
PrettyTables._process_merge_column_label_specificationMethod
_process_merge_column_label_specification(column_labels::Vector{T}, num_columns::Int) where T <: AbstractVector -> Vector{Vector{Any}}, Vector{MergeCells}

Process the column label specification by replacing MultiColumn objects in column_labels and adding the correct specification to merge_column_label_cells. This function returns the new objects that must replace the olds column_labels and the merge_column_label_cells.

The number of columns in the table must be passed in num_column so the function can verify the correctness of the specification.

source
PrettyTables._resolve_printing_backendMethod
_resolve_printing_backend(configurations) -> Symbol

Return the printing backend to be used based on the configurations provided. Notice that it function must only be used when the user did not specify the backend directly using the backend keyword.

source
PrettyTables._text__cell_to_strMethod
_text__cell_to_str(cell::Any, context::IOContext, renderer::Union{Val{:print}, Val{:show}}) -> String

Convert the cell to a string using a specific context and renderer.

source
PrettyTables._text__design_vertical_croppingMethod
_text__design_vertical_cropping(table_data::TableData, tf::TextTableFormat, horizontal_lines_at_column_labels::AbstractVector{Int}, horizontal_lines_at_data_rows::AbstractVector{Int}, show_omitted_row_summary::Bool, display_number_of_rows::Int, new_line_at_end::Bool = true) -> Int, Bool

Design the vertical cropping of the table by computing how many data lines we can print and if we must suppress the horizontal line before or after the continuation line.

Arguments

  • table_data::TableData: Table data.
  • tf::TextTableFormat: Table format.
  • horizontal_lines_at_column_labels::AbstractVector{Int}: Horizontal lines at column labels.
  • horizontal_lines_at_data_rows::AbstractVector{Int}: Horizontal lines at data rows.
  • show_omitted_row_summary::Bool: If true, we must show the omitted row summary.
  • display_number_of_rows::Int: Number of rows in the display.
  • new_line_at_end::Bool: If true, we must add a new line at the end of the table.

Returns

  • Int: Number of data rows we can print.
  • Bool: If true, we must suppress the horizontal line before the continuation line.
  • Bool: If true, we must suppress the horizontal line after the continuation line.
source
PrettyTables._text__design_vertical_cropping_with_line_breaksMethod
_text__design_vertical_cropping_with_line_breaks(table_data::TableData, table_str::Matrix{String}, tf::TextTableFormat, horizontal_lines_at_column_labels::AbstractVector{Int}, horizontal_lines_at_data_rows::AbstractVector{Int}, show_omitted_row_summary::Bool, display_number_of_rows::Int, new_line_at_end::Bool, num_printed_data_columns::Int) -> Int, Int, Bool

Design the vertical cropping of the table when the user wants line breaks by computing how many data lines we can print and if we must suppress the horizontal line before the continuation line. Notice that middle vertical cropping is not supported when we have line breaks.

Arguments

  • table_data::TableData: Table data.
  • tf::TextTableFormat: Table format.
  • horizontal_lines_at_column_labels::AbstractVector{Int}: Horizontal lines at column labels.
  • horizontal_lines_at_data_rows::AbstractVector{Int}: Horizontal lines at data rows.
  • show_omitted_row_summary::Bool: If true, we must show the omitted row summary.
  • display_number_of_rows::Int: Number of rows in the display.
  • new_line_at_end::Bool: If true, we must add a new line at the end of the table.
  • num_printed_data_columns::Int: Number of printed data columns.

Returns

  • Int: Number of data rows we can fully print.
  • Bool: If true, the printing process with crop the last row.
  • Bool: If true, we must suppress the horizontal line before the continuation line.
source
PrettyTables._text__fit_cell_in_maximum_cell_widthMethod
_text__fit_cell_in_maximum_cell_width(cell_str::String, maximum_cell_width::Int, line_breaks::Bool) -> String

Fit the cell with text cell_str in a field with a maximum width maximum_cell_width. If line_breaks is true, the cell will be split into multiple lines before fitting it.

source
PrettyTables._text__fix_data_column_widths!Method
_text__fix_data_column_widths!(printed_data_column_widths::Vector{Int}, column_labels::Matrix{String}, table_str::Matrix{String}, summary_rows::Union{Nothing, Matrix{String}}, fixed_data_column_widths::AbstractVector{Int}) -> Nothing

Fix the data column widths given the user specification. This function also crops the cells at the data columns to fit the fixed width.

Arguments

  • printed_data_column_widths::Vector{Int}: Printed data column widths.
  • column_labels::Matrix{String}: Column labels.
  • table_str::Matrix{String}: Rendered data cells.
  • summary_rows::Union{Nothing, Matrix{String}}: Summary rows.
  • fixed_data_column_widths::AbstractVector{Int}: Fixed data column widths.
  • auto_wrap::Bool: If true, the strings will be auto wrapped at each column with a fixed width.
  • line_breaks::Bool: If true, the cells will be split into multiple lines if needed.
source
PrettyTables._text__horizontal_line_intersectionMethod
_text__horizontal_line_intersection(display::Display, intersection::String, row::String, final_intersection::Bool) -> Nothing

Print to display the horizontal line intersection if we have enough space. Otherwise, print row. The argument final_intersection indicates that we are printing the final intersection of the table. In that case, we print intersection if we have at least two remaning spaces.

source
PrettyTables._text__number_of_printed_data_columnsMethod
_text__number_of_printed_data_columns(display_width::Int, table_data::TableData, tf::TextTableFormat, vertical_lines_at_data_columns::AbstractVector{Int}, row_number_column_width::Int, row_label_column_width::Int, printed_data_column_widths::Vector{Int}) -> Int

Compute the number of printed data columns.

Arguments

  • display_width::Int: Display width.
  • table_data::TableData: Table data.
  • tf::TextTableFormat: Table format.
  • vertical_lines_at_data_columns::AbstractVector{Int}: List of columns where a vertical line must be drawn after the cell.
  • row_number_column_width::Int: Row number column width.
  • row_label_column_width::Int: Row label column width.
  • printed_data_column_widths::Vector{Int}: Printed data column widths.
source
PrettyTables._text__number_of_required_linesMethod
_text__number_of_required_lines(table_data::TableData, tf::TextTableFormat, horizontal_lines_at_column_lables::AbstractVector{Int}, horizontal_lines_at_data_rows::AbstractVector{Int}, new_line_at_end::Bool) -> NTuple{4, Int}

Compute the total number of lines required to print the table.

Arguments

  • table_data::TableData: Table data.
  • tf::TextTableFormat: Table format.
  • horizontal_lines_at_column_labels::AbstractVector{Int}: Horizontal lines at column labels.
  • horizontal_lines_at_data_rows::AbstractVector{Int}: Horizontal lines at data rows.
  • new_line_at_end::Bool: If true, we must add a new line at the end of the table.

Returns

  • Int: Total number of lines required to print the table.
  • Int: Number of lines required before printing the data.
  • Int: Number of lines required after printing the data.
source
PrettyTables._text__print_column_label_horizontal_lineFunction
_text__print_column_label_horizontal_line(display::Display, tf::TextTableFormat, crayon::Crayon, table_data::TableData, row_number::Int, vertical_lines_at_data_columns::AbstractVector{Int}, row_number_column_width::Int, row_label_column_width::Int, printed_data_column_widths::Vector{Int}, top::Bool = false, bottom::Bool = false)

Print a column label horizontal line to display.

Arguments

  • display::Display: Display where the horizontal line will be printed.
  • tf::TextTableFormat: Table format.
  • crayon::Crayon: Crayon used to print the horizontal line.
  • table_data::TableData: Table data.
  • row_number::Int: Column label row number before the horizontal line.
  • vertical_lines_at_data_columns::AbstractVector{Int}: List of columns where a vertical line must be drawn after the cell.
  • row_number_column_width::Int: Row number column width.
  • row_label_column_width::Int: Row label column width.
  • printed_data_column_widths::Vector{Int}: Printed data column widths.
  • top::Bool: If true, a top horizontal line will be drawn. (Default: false)
  • bottom::Bool: If true, a bottom horizontal line will be drawn. (Default: false)
source
PrettyTables._text__print_horizontal_lineFunction
_text__print_horizontal_line(display::Display, tf::TextTableFormat, crayon::Crayon, table_data::TableData, vertical_lines_at_data_columns::AbstractVector{Int}, row_number_column_width::Int, row_label_column_width::Int, printed_data_column_widths::Vector{Int}, top::Bool = false, bottom::Bool = false, row_group_label::Bool = false) -> Nothing

Print a horizontal line to display.

Arguments

  • display::Display: Display where the horizontal line will be printed.
  • tf::TextTableFormat: Table format.
  • crayon::Crayon: Crayon used to print the horizontal line.
  • table_data::TableData: Table data.
  • vertical_lines_at_data_columns::AbstractVector{Int}: List of columns where a vertical line must be drawn after the cell.
  • row_number_column_width::Int: Row number column width.
  • row_label_column_width::Int: Row label column width.
  • printed_data_column_widths::Vector{Int}: Printed data column widths.
  • top::Bool: If true, a top horizontal line will be drawn. (Default: false)
  • bottom::Bool: If true, a bottom horizontal line will be drawn. (Default: false)
  • row_group_label::Bool: If true, a row group label horizontal line will be drawn. In this case, the horizontal line type is also modified by the keyword top, whereas the keyword bottom is neglected. To draw the bottom row label horizontal line, set topto false. (Default: false)
source
PrettyTables._text__printed_column_widthsMethod
_text__printed_column_widths(table_data::TableData, row_labels::Union{Nothing, Vector{String}}, column_labels::Union{Nothing, Matrix{String}}, summary_rows::Union{Nothing, Matrix{String}}, table_str::Matrix{String}, vertical_lines_at_data_columns::AbstractVector{Int}, column_label_width_based_on_first_line_only::Bool, line_breaks::Bool)

Compute the printed column widths.

Arguments

  • table_data::TableData: Table data.
  • row_labels::Union{Nothing, Vector{String}}: Rendered row labels.
  • column_labels::Union{Nothing, Matrix{String}}: Rendered column labels.
  • summary_rows::Union{Nothing, Vector{String}}: Rendered summary rows.
  • table_str::Matrix{String}: Rendered data cells.
  • vertical_lines_at_data_columns::AbstractVector{Int}: List of columns where a vertical line must be drawn after the cell.
  • column_label_width_based_on_first_line_only::Bool: If true, the column label width will be computed based on the first line only.
  • line_breaks::Bool: If true, the cells will be split into multiple lines if needed. Hence, the textwidth of each line is used to compute the column width.

Returns

  • Int: Row number column width.
  • Int: Row label column width.
  • Vector{Int}: Printed data column widths.
source
PrettyTables._text__render_cellFunction
_text__render_cell(cell::Any, @nospecialize(context::IOContext), renderer::Union{Val{:print}, Val{:show}}; kwargs...) -> String

Render the cell in text back end using a specific context and renderer.

source
PrettyTables._text__render_tableMethod
_text__render_table(table_data::TableData, @nospecialize(context::IOContext), renderer::Union{Val{:print}, Val{:show}}, line_breaks::Bool, maximum_data_column_widths::AbstractVector{Int})

Render the table using the specification in table_data. When the cells are converted to String, we use the context, and the renderer.

If line_breaks is true, we split each cell into multiple lines at every occurence of \n.

maximum_data_column_widths must contain the user specification for the maximum data column widths.

Returns

  • Union{Nothing, Vector{String}}: Rendered row labels.
  • Matrix{String}: Rendered data cells.
  • Union{Nothing, Vector{String}}: Rendered summary rows.
  • Vector{String}: Rendered footnotes.
source
PrettyTables._text__table_width_wo_cont_columnMethod
_text__table_width_wo_cont_column(table_data::TableData, tf::TextTableFormat, vertical_lines_at_data_columns::AbstractVector{Int}, row_number_column_width::Int, row_label_column_width::Int, printed_data_column_widths::Vector{Int}) -> Int

Compute the width of the table without the continuation column.

Arguments

  • table_data::TableData: Table data.
  • tf::TextTableFormat: Table format.
  • vertical_lines_at_data_columns::AbstractVector{Int}: List of columns where a vertical line must be drawn after the cell.
  • row_number_column_width::Int: Row number column width.
  • row_label_column_width::Int: Row label column width.
  • printed_data_column_widths::Vector{Int}: Printed data column widths.
source
PrettyTables.fmt__latex_snMethod
fmt__latex_sn(m_digits::Int[, columns::AbstractVector{Int}]) -> Function

Format the numbers of the elements in the columns to a scientific notation using LaTeX. If columns is not present, the formatting will be applied to the entire table.

The number is first printed using Printf functions with the g modifier and then converted to the LaTeX format. The number of digits in the mantissa can be selected by the argument m_digits.

The formatted number will be wrapped in the object LatexCell. Hence, this formatter only makes sense if the selected backend is :latex.

Info

This formatter will be applied only to the cells that are of type Number.

Extended Help

Examples

julia> data = [10.0^(-i + j) for i in 1:6, j in 1:6]
6×6 Matrix{Float64}:
 1.0     10.0     100.0    1000.0   10000.0  100000.0
 0.1      1.0      10.0     100.0    1000.0   10000.0
 0.01     0.1       1.0      10.0     100.0    1000.0
 0.001    0.01      0.1       1.0      10.0     100.0
 0.0001   0.001     0.01      0.1       1.0      10.0
 1.0e-5   0.0001    0.001     0.01      0.1       1.0

julia> pretty_table(data; formatters = [fmt__latex_sn(1)], backend = :latex)
\begin{tabular}{|r|r|r|r|r|r|}
  \hline
  \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} & \textbf{Col. 4} & \textbf{Col. 5} & \textbf{Col. 6} \\
  \hline
  1 & $1 \cdot 10^{1}$ & $1 \cdot 10^{2}$ & $1 \cdot 10^{3}$ & $1 \cdot 10^{4}$ & $1 \cdot 10^{5}$ \\
  0.1 & 1 & $1 \cdot 10^{1}$ & $1 \cdot 10^{2}$ & $1 \cdot 10^{3}$ & $1 \cdot 10^{4}$ \\
  0.01 & 0.1 & 1 & $1 \cdot 10^{1}$ & $1 \cdot 10^{2}$ & $1 \cdot 10^{3}$ \\
  0.001 & 0.01 & 0.1 & 1 & $1 \cdot 10^{1}$ & $1 \cdot 10^{2}$ \\
  0.0001 & 0.001 & 0.01 & 0.1 & 1 & $1 \cdot 10^{1}$ \\
  $1 \cdot 10^{-5}$ & 0.0001 & 0.001 & 0.01 & 0.1 & 1 \\
  \hline
\end{tabular}
source
PrettyTables.fmt__printfMethod
fmt__printf(fmt_str::String[, columns::AbstractVector{Int}]) -> Function

Apply the format fmt_str (see the Printf standard library) to the elements in the columns specified in the vector columns. If columns is not specified, the format will be applied to the entire table.

Info

This formatter will be applied only to the cells that are of type Number.

Extended Help

Examples

julia> data = [f(a) for a = 0:30:90, f in (sind, cosd, tand)]
4×3 Matrix{Float64}:
 0.0       1.0        0.0
 0.5       0.866025   0.57735
 0.866025  0.5        1.73205
 1.0       0.0       Inf

julia> pretty_table(data; formatters = [fmt__printf("%5.3f")])
┌────────┬────────┬────────┐
│ Col. 1 │ Col. 2 │ Col. 3 │
├────────┼────────┼────────┤
│  0.000 │  1.000 │  0.000 │
│  0.500 │  0.866 │  0.577 │
│  0.866 │  0.500 │  1.732 │
│  1.000 │  0.000 │    Inf │
└────────┴────────┴────────┘

julia> pretty_table(data; formatters = [fmt__printf("%5.3f", [1, 3])])
┌────────┬──────────┬────────┐
│ Col. 1 │   Col. 2 │ Col. 3 │
├────────┼──────────┼────────┤
│  0.000 │      1.0 │  0.000 │
│  0.500 │ 0.866025 │  0.577 │
│  0.866 │      0.5 │  1.732 │
│  1.000 │      0.0 │    Inf │
└────────┴──────────┴────────┘
source
PrettyTables.fmt__roundMethod
fmt__round(digits::Int[, columns::AbstractVector{Int}]) -> Function

Round the elements in the columns specified in the vector columns to the number of digits. If columns is not specified, the rounding will be applied to the entire table.

Extended Help

Examples

julia> data = [f(a) for a = 0:30:90, f in (sind, cosd, tand)]
4×3 Matrix{Float64}:
 0.0       1.0        0.0
 0.5       0.866025   0.57735
 0.866025  0.5        1.73205
 1.0       0.0       Inf

julia> pretty_table(data; formatters = [fmt__round(1)])
┌────────┬────────┬────────┐
│ Col. 1 │ Col. 2 │ Col. 3 │
├────────┼────────┼────────┤
│    0.0 │    1.0 │    0.0 │
│    0.5 │    0.9 │    0.6 │
│    0.9 │    0.5 │    1.7 │
│    1.0 │    0.0 │    Inf │
└────────┴────────┴────────┘

julia> pretty_table(data; formatters = [fmt__round(1, [1, 3])])
┌────────┬──────────┬────────┐
│ Col. 1 │   Col. 2 │ Col. 3 │
├────────┼──────────┼────────┤
│    0.0 │      1.0 │    0.0 │
│    0.5 │ 0.866025 │    0.6 │
│    0.9 │      0.5 │    1.7 │
│    1.0 │      0.0 │    Inf │
└────────┴──────────┴────────┘
source
PrettyTables.pretty_tableFunction
pretty_table(table; kwargs...) -> Nothing

Print the table to the stdout.

pretty_table(io::IO, table; kwargs...) -> Nothing
pretty_table(String, table; kwargs...) -> String
pretty_table(HTML,   table; kwargs...) -> HTML

Print the table to the output specified by the first argument.

If the first argument is of type IO, the function prints the table to it. If it is String, a String with the printed table will be returned by the function. If HTML is passed as the first argument, the function will return an HTML object with the table.

When printing, the function verifies if table complies with Tables.jl API. If it is compliant, this interface will be used to print the table. If it is not compliant, only the following types are supported:

  1. AbstractVector: any vector can be printed.
  2. AbstractMatrix: any matrix can be printed.

pretty_table current supports printing table for four backends: text, markdown, html, and latex. The desired backend can be set using the backend keyword argument.

For more information, see the Extended Help section.

Extended Help

Table Sections

PrettyTables.jl considers the following table sections when printing a table:

                                      TITLE
                                     Subtitle
┌────────────┬───────────────────┬──────────────┬──────────────┬───┬──────────────┐
│ Row Number │    Stubhead Label │ Column Label │ Column Label │ ⋯ │ Column Label │
│            │                   │ Column Label │ Column Label │ ⋯ │ Column Label │
│            │                   │       ⋮      │       ⋮      │ ⋯ │       ⋮      │
│            │                   │ Column Label │ Column Label │ ⋯ │ Column Label │
├────────────┼───────────────────┼──────────────┼──────────────┼───┼──────────────┤
│          1 │         Row Label │         Data │         Data │ ⋯ │         Data │
│          2 │         Row Label │         Data │         Data │ ⋯ │         Data │
├────────────┴───────────────────┴──────────────┴──────────────┴───┴──────────────┤
│ Row Group Label                                                                 │
├────────────┬───────────────────┬──────────────┬──────────────┬───┬──────────────┤
│          3 │         Row Label │         Data │         Data │ ⋯ │         Data │
│          4 │         Row Label │         Data │         Data │ ⋯ │         Data │
├────────────┴───────────────────┴──────────────┴──────────────┴───┴──────────────┤
│ Row Group Label                                                                 │
├────────────┬───────────────────┬──────────────┬──────────────┬───┬──────────────┤
│          5 │         Row Label │         Data │         Data │ ⋯ │         Data │
│          6 │         Row Label │         Data │         Data │ ⋯ │         Data │
│      ⋮     │          ⋮        │       ⋮      │       ⋮      │ ⋱ │       ⋮      │
│        100 │         Row Label │         Data │         Data │ ⋯ │         Data │
├────────────┼───────────────────┼──────────────┼──────────────┼───┼──────────────┤
│            │ Summary Row Label │ Summary Cell │ Summary Cell │ ⋯ │ Summary Cell │
│            │ Summary Row Label │ Summary Cell │ Summary Cell │ ⋯ │ Summary Cell │
│      ⋮     │          ⋮        │       ⋮      │       ⋮      │ ⋯ │       ⋮      │
│            │ Summary Row Label │ Summary Cell │ Summary Cell │ ⋯ │ Summary Cell │
└────────────┴───────────────────┴──────────────┴──────────────┴───┴──────────────┘
Footnotes
Source notes

All those sections can be configured using keyword arguments as described below.

Quick Start

The following commands prints the table in matrix using the text backend with all the available sections:

julia> matrix = [(i, j) for i in 1:3, j in 1:3];

julia> result = pretty_table(
    matrix;
    column_labels            = [["Col. $i" for i in 1:3], ["$i" for i in 1:3]],
    footnotes                = [(:column_label, 1, 2) => "Footnote in column label", (:data, 2, 2) => "Footnote in data"],
    merge_column_label_cells = [MergeCells(1, 2, 2, "Merged Column", :c)],
    row_group_labels         = [2                     => "Row Group"],
    row_labels               = ["Row $i" for i in 1:5],
    show_row_number_column   = true,
    source_notes             = "Source Notes",
    stubhead_label           = "Rows",
    subtitle                 = "Table Subtitle",
    summary_rows             = [(data, i) -> 10i, (data, i) -> 20i],
    title                    = "Table Title",
)
                  Table Title
                Table Subtitle
┌─────┬───────────┬────────┬──────────────────┐
│ Row │      Rows │ Col. 1 │  Merged Column¹  │
│     │           │      1 │       2 │      3 │
├─────┼───────────┼────────┼─────────┼────────┤
│   1 │     Row 1 │ (1, 1) │  (1, 2) │ (1, 3) │
├─────┴───────────┴────────┴─────────┴────────┤
│ Row Group                                   │
├─────┬───────────┬────────┬─────────┬────────┤
│   2 │     Row 2 │ (2, 1) │ (2, 2)² │ (2, 3) │
│   3 │     Row 3 │ (3, 1) │  (3, 2) │ (3, 3) │
├─────┼───────────┼────────┼─────────┼────────┤
│     │ Summary 1 │     10 │      20 │     30 │
│     │ Summary 2 │     20 │      40 │     60 │
└─────┴───────────┴────────┴─────────┴────────┘
¹: Footnote in column label
²: Footnote in data
Source Notes

General Keywords

The following keywords are related to table configuration and are available in all backends:

  • backend::Symbol: Backend used to print the table. The available options are :text, :markdown, :html, and :latex. (Default: :text)

IOContext Arguments

  • compact_printing::Bool: If true, the table will be printed in a compact format, i.e, we will pass the context option :compact => true when rendering the values. (Default: true)
  • limit_printing::Bool: If true, the table will be printed in a limited format, i.e, we will pass the context option :limit => true when rendering the values. (Default: true)

Printing Specification Arguments

  • show_omitted_cell_summary::Bool: If true, a summary of the omitted cells will be printed at the end of the table. (Default: true)
  • renderer::Symbol: The renderer used to print the table. The available options are :print and :show. (Default: :print)

Table Sections Arguments

  • title::String: Title of the table. If it is empty, the title will be omitted. (Default: "")
  • subtitle::String: Subtitle of the table. If it is empty, the subtitle will be omitted. (Default: "")
  • stubhead_label::String: Label of the stubhead column. (Default: "")
  • row_number_column_label::String: Label of the row number column. (Default: "Row")
  • row_labels::Union{Nothing, AbstractVector}: Row labels. If it is nothing, the column with row labels is omitted. (Default: nothing)
  • row_group_labels::Union{Nothing, Vector{Pair{Int, String}}}: Row group labels. If it is nothing, no row group label is printed. For more information on how to specify the row group labels, see the section Row Group Labels. (Default: nothing)
  • column_labels::Union{Nothing, AbstractVector}: Column labels. If it is nothing, the function uses a default value for the column labels. For more information on how to specify the column labels, see the section Column Labels. (Default: nothing)
  • show_column_labels::Bool: If true, the column labels will be printed. (Default: true)
  • summary_rows::Union{Nothing, Vector{Function}}: Summary rows. If it is nothing, no summary rows are printed. For more information on how to specify the summary rows, see the section Summary Rows. (Default: nothing)
  • summary_row_labels::Union{Nothing, Vector{String}}: Labels of the summary rows. If it is nothing, the function uses a default value for the summary row labels. (Default: nothing)
  • footnotes::Union{Nothing, Vector{Pair{FootnoteTuple, String}}}: Footnotes. If it is nothing, no footnotes are printed. For more information on how to specify the footnotes, see the section Footnotes. (Default: nothing)
  • source_notes::String: Source notes. If it is empty, the source notes will be omitted. (Default: "")

Alignment Arguments

The following keyword arguments define the alignment of the table sections. The alignment can be specified using a symbol: :l for left, :c for center, or :r for right.

  • alignment::Union{Symbol, Vector{Symbol}}: Alignment of the table data. It can be a Symbol, which will be used for all columns, or a vector of Symbols, one for each column. (Default: :r)
  • column_label_alignment::Union{Nothing, Symbol, Vector{Symbol}}: Alignment of the column labels. It can be a Symbol, which will be used for all columns, a vector of Symbols, one for each column, or nothing, which will use the value of alignment. (Default: nothing)
  • continuation_row_alignment::Union{Nothing, Symbol}: Alignment of the columns in the continuation row. If it is nothing, we use the value of alignment. (Default: nothing)
  • footnote_alignment::Symbol: Alignment of the footnotes. (Default: :l)
  • row_label_column_alignment::Symbol: Alignment of the row labels. (Default: :r)
  • row_group_label_alignment::Symbol: Alignment of the row group labels. (Default: :l)
  • row_number_column_alignment::Symbol: Alignment of the row number column. (Default: :r)
  • source_note_alignment::Symbol: Alignment of the source notes. (Default: :l)
  • subtitle_alignment::Symbol: Alignment of the subtitle. (Default: :c)
  • title_alignment::Symbol: Alignment of the title. (Default: :c)
  • cell_alignment::Union{Nothing, Vector{Pair{NTuple{2, Int}, Symbol}, Vector{Function}}: A vector of functions with the signature f(data, i, j) that overrides the alignment of the cell (i, j) to the value returned by f. The function must return a valid alignment symbol or nothing. In the latter, the cell alignment will not be modified. If the function returns an invalid data, it will be discarded. For convenience, it can also be a vector of Pair{NTuple{2, Int}, Symbol}, i.e. (i::Int, j::Int) => a::Symbol, that overrides the alignment of the cell (i, j) to a. (Default = nothing)
Warning

Some backends does not support all the alignment options. For example, it is impossible to define cell-specific alignment in the markdown backend.

Other Arguments

  • formatters::Union{Nothing, Vector{Function}}: Formatters used to modify the rendered output of the cells. For more information, see the section Formatters. (Default: nothing)
  • maximum_number_of_columns::Int: Maximum number of columns to be printed. If the table has more columns than this value, the table will be truncated. If it is negative, all columns will be printed. (Default: -1)
  • maximum_number_of_rows::Int: Maximum number of rows to be printed. If the table has more rows than this value, the table will be truncated. If it is negative, all rows will be printed. (Default: -1)
  • merge_column_label_cells::Union{Symbol, Vector{MergeCells}}: Merged cells in the column labels. For more information, see the section Column Labels. (Default: :auto)
  • new_line_at_end::Bool: If true, a new line will be printed at the end of the table. (Default: true)
  • show_first_column_label_only::Bool: If true, only the first row of the column labels will be printed. (Default: false)
  • vertical_crop_mode::Symbol: Vertical crop mode. This option defines how the table will be vertically cropped if it has more rows than the number specified in maximum_number_of_rows. The available options are :bottom, when the data will be cropped at the bottom of the table, or :middle, when the data will be cropped at the middle of the table. (Default: :bottom)

Backend-Specific Keywords

The keywords and information specific to each backend can be seen in the docstrings of the following methods:

  • Text backend: pretty_table_text_backend.
  • Markdown backend: pretty_table_markdown_backend.
  • HTML backend: pretty_table_html_backend.
Warning

Those methods must not be called directly. They are only defined to split the documentation, providing a better organization.

Specification of Table Sections

Here, we show how to specify the table sections using the keyword arguments.

Column Labels

The specification of column labels must be a vector of elements. Each element in this vector must be another vector with a row of column labels. Notice that each vector must have the same size as the number of table columns.

For example, in a table with three columns, we can specify two rows of column labels by passing:

column_labels = [
    ["Column #1",    "Column #2",    "Column #3"],
    ["Subcolumn #1", "Subcolumn #2", "Subcolumn #3"]
]
Info

If the user wants only one row in the column labels, they can pass only a vector with the elements. The algorithm will encapsulate it inside another vector to match the API.

Adjacent column labels can be merged using the keyword merge_column_label_cells. It must contain a vector of MergeCells objects. Each object defines a new merged cell. The MergeCells object has the following fields:

  • row::Int: Row index of the merged cell.
  • column::Int: Column index of the merged cell.
  • column_span::Int: Number of columns spanned by the merged cell.
  • data::String: Data of the merged cell.
  • alignment::Symbol: Alignment of the merged cell. The available options are :l for left, :c for center, and :r for right. (Default: :c)

Hence, in our example, if we want to merge the columns 2 and 3 of the first column label row, we must pass:

merge_column_label_cells = [
    MergeCells(1, 2, 2, "Merged Column", :c)
]

We can pass the helpers MultiColumn and EmptyCells to column_labels to create merged columns more easily. In this case, MultiColumn specify a set of columns that will be merged, and EmptyCells specify a set of empty columns. However, notice that in this case we must set merge_column_label_cells to :auto, which is the default.

MultiColumn has the following fields:

  • column_span::Int: Number of columns spanned by the merged cell.
  • data::String: Data of the merged cell.

EmptyCells has the following field:

  • number_of_cells::Int: Number of columns that will be filled with empty cells.

For example, we can create the following column labels:

┌───────────────────────────────────┬─────────────────┐
│              Group #1             │     Group #2    │
├─────────────────┬─────────────────┼────────┬────────┤
│    Group #1.1   │    Group #1.2   │        │        │
├────────┬────────┼────────┬────────┼────────┼────────┤
│ Test 1 │ Test 2 │ Test 3 │ Test 4 │ Test 5 │ Test 6 │
└────────┴────────┴────────┴────────┴────────┴────────┘

by passing these arguments:

column_labels = [
    [MultiColumn(4, "Group #1"), MultiColumn(2, "Group #2")],
    [MultiColumn(2, "Group #1.1"), MultiColumn(2, "Group #1.2"), EmptyCells(2)],
    ["Test 1", "Test 2", "Test 3", "Test 4", "Test 5", "Test 6"]
]

merge_column_label_cells = :auto

Row Group Labels

The row group labels are specified by a Vector{Pair{Int, String}}. Each element defines a new row group label. The first element of the Pair is the row index of the row group and the second is the label. For example, [3 => "Row Group #1"] defines that before row 3, we have the row group label named "Row Group #1".

Summary Rows

The summary rows can be specified by a vector of Functions. Each element defines a summary row and the function must have the following signature:

f(data, j)

where data is the table data and j is the column index. It must return the summary cell value for the jth column. Hence, if we want, for example, to create two summary rows, one with the sum the column values and other with their mean, we must define:

summary_rows = [
    (data, j) -> sum(data[:, j]),
    (data, j) -> sum(data[:, j]) / length(data[:, j])
]

Footnotes

The footnotes are specified by a vector of Pair{FootnoteTuple, String}. Each element defines a new footnote. The FootnoteTuple is a Tuple with the following elements:

  • section::Symbol: Section to which the footnote must be applied. The available options are :column_label, :data, :row_label, :summary_row_label, and :summary_row_cell.
  • i::Int: Row index of the footnote considering the desired section.
  • j::Int: Column index of the footnote considering the desired section.

The second element of the Pair is the footnote text.

Hence, if we want to apply a foot note to a column label, a data cell, and a summary cell, we can define:

footnotes = [
    (:column_label, 1, 2) => "Footnote in column label",
    (:data, 2, 2) => "Footnote in data",
    (:summary_row_cell, 1, 2) => "Footnote in summary cell"
]

Formatters

The keyword formatters can be used to pass functions to format the values in the columns. It must be a Vector{Function} in which each function has the following signature:

f(v, i, j)

where v is the value in the cell, i is the row number, and j is the column number. It must return the formatted value of the cell (i, j) that has the value v. Notice that the returned value will be converted to string after using the function sprint.

This keyword can also be nothing, meaning that no formatter will be used.

For example, if we want to multiply all values in odd rows of the column 2 by π, the formatter should look like:

formatters = [(v, i, j) -> (j == 2 && isodd(i)) ? v * π : v]

If multiple formatters are available, they will be applied in the same order as they are located in the vector. Thus, for the following formatters:

formatters = [f1, f2, f3]

each element v in the table (ith row and jth column) will be formatted by:

v = f1(v, i, j)
v = f2(v, i, j)
v = f3(v, i, j)

Thus, the user must be ensure that the type of v between the calls are compatible.

PrettyTables.jl provides some predefined formatters for common tasks. For more information, see fmt__printf, fmt__round, and fmt__latex_sn.

source
PrettyTables.pretty_table_html_backendFunction

PrettyTables.jl HTML Backend

The HTML backend can be selected by passing the keyword backend = :html to the function pretty_table. In this case, we have the following additional keywords to configure the output.

Keywords

  • allow_html_in_cells::Bool: If true, the content of the cells can contain HTML code. This can be useful to render tables with more complex content, but it can also be a security risk if the content is not sanitized. (Default: false)
  • highlighters::Vector{HtmlHighlighter}: Highlighters to apply to the table. For more information, see the section HTML Highlighters in the Extended Help.
  • line_breaks::Bool: If true, line breaks in the content of the cells (\n) are replaced by the HTML tag <br>. (Default: false)
  • maximum_column_width::String: CSS width string for the maximum column width. (Default: "")
  • minify::Bool: If true, the output HTML code is minified. (Default: false)
  • stand_alone::Bool: If true, the output HTML code is a complete HTML document. (Default: false)
  • style::HtmlTableStyle: Style of the table. For more information, see the section HTML Table Style in the Extended Help.
  • table_class::String: Class for the table. (Default: "")
  • table_div_class::String: Class for the div containing the table. It is only used if wrap_table_in_div is true. (Default: "")
  • table_format::HtmlTableFormat: HTML table format used to render the table. For more information, see the section HTML Table Format in the Extended Help.
  • top_left_string::String: String to put in the top left corner div. (Default: "")
  • top_right_string::String: String to put in the top right corner div. Notice that this information is replaced if we are printing the omitted cell summary. (Default: "")
  • wrap_table_in_div::Bool: If true, the table is wrapped in a div. (Default: false)

Extended Help

HTML Highlighters

A set of highlighters can be passed as a Vector{HtmlHighlighter} to the highlighters keyword. Each highlighter is an instance of the structure HtmlHighlighter. It contains the following two public fields:

  • f::Function: Function with the signature f(data, i, j) in which should return true if the element (i, j) in data must be highlighted, or false otherwise.
  • fd::Function: Function with the signature f(h, data, i, j) in which h is the highlighter. This function must return a Vector{Pair{String, String}} with properties compatible with the style field that will be applied to the highlighted cell.

A HTML highlighter can be constructed using three helpers:

HtmlHighlighter(f::Function, decoration::Vector{Pair{String, String}})

HtmlHighlighter(f::Function, decorations::NTuple{N, Pair{String, String})

HtmlHighlighter(f::Function, fd::Function)

The first will apply a fixed decoration to the highlighted cell specified in decoration, whereas the second let the user select the desired decoration by specifying the function fd.

Note

If multiple highlighters are valid for the element (i, j), the applied style will be equal to the first match considering the order in the vector highlighters.

Note

If the highlighters are used together with Formatters, the change in the format will not affect the parameter data passed to the highlighter function f. It will always receive the original, unformatted value.

For example, we if want to highlight the cells with value greater than 5 in red, and all the cells with value less than 5 in blue, we can define:

hl_gt5 = HtmlHighlighter(
    (data, i, j) -> data[i, j] > 5,
    ["color" => "red"]
)

hl_lt5 = HtmlHighlighter(
    (data, i, j) -> data[i, j] < 5,
    ["color" => "blue"]
)

highlighters = [hl_gt5, hl_lt5]

HTML Table Format

The HTML table format is defined using an object of type HtmlTableFormat that contains the following fields:

  • css::String: CSS to be injected at the end of the <style> section.
  • table_width::String: Table width.

Notice that this format is only applied if stand_alone = true.

HTML Table Style

The HTML table style is defined using an object of type HtmlTableStyle that contains the following fields:

  • top_left_string::Vector{HtmlPair}: Style for the top left string.
  • top_right_string::Vector{HtmlPair}: Style for the top right string.
  • table::Vector{HtmlPair}: Style for the table.
  • title::Vector{HtmlPair}: Style for the title.
  • subtitle::Vector{HtmlPair}: Style for the subtitle.
  • row_number_label::Vector{HtmlPair}: Style for the row number label.
  • row_number::Vector{HtmlPair}: Style for the row number.
  • stubhead_label::Vector{HtmlPair}: Style for the stubhead label.
  • row_label::Vector{HtmlPair}: Style for the row label.
  • row_group_label::Vector{HtmlPair}: Style for the row group label.
  • first_line_column_label::Vector{HtmlPair}: Style for the first line of the column labels.
  • column_label::Vector{HtmlPair}: Style for the column label.
  • first_line_merged_column_label::Vector{HtmlPair}: Style for the merged cells at the first column label line.
  • merged_column_label::Vector{HtmlPair}: Style for the merged cells at the rest of the column labels.
  • summary_row_cell::Vector{HtmlPair}: Style for the summary row cell.
  • summary_row_label::Vector{HtmlPair}: Style for the summary row label.
  • footnote::Vector{HtmlPair}: Style for the footnote.
  • source_notes::Vector{HtmlPair}: Style for the source notes.

Each field is a vector of HtmlPair, i.e. Pair{String, String}, describing properties and values compatible with the HTML style attribute.

For example, we if want that the stubhead label is bold and red, we must define:

style = HtmlTableStyle(
    stubhead_label = ["font-weight" => "bold", "color" => "red"]
)
source
PrettyTables.pretty_table_latex_backendFunction

PrettyTables.jl LaTeX Backend

The LaTeX backend can be selected by passing the keyword backend = :latex to the function pretty_table. In this case, we have the following additional keywords to configure the output.

Keywords

  • highlighters::Vector{LatexHighlighter}: Highlighters to apply to the table. For more information, see the section LaTeX Highlighters in the Extended Help.
  • style::LatexTableStyle: Style of the table. For more information, see the section LaTeX Table Style in the Extended Help.
  • table_format::LatexTableFormat: LaTeX table format used to render the table. For more information, see the section LaTeX Table Format in the Extended Help.

Extended Help

LaTeX Highlighters

A set of highlighters can be passed as a Vector{LatexHighlighter} to the highlighters keyword. Each highlighter is an instance of the structure LatexHighlighter. It contains the following two public fields:

  • f::Function: Function with the signature f(data, i, j) in which should return true if the element (i, j) in data must be highlighted, or false otherwise.
  • fd::Function: Function with the signature f(h, data, i, j) in which h is the highlighter. This function must return a Vector{String} with the LaTeX environments to be applied to the cell.

A LaTeX highlighter can be constructured using two helpers:

LatexHighlighter(f::Function, envs::Vector{String})

where it will apply recursively all the LaTeX environments in envs to the highlighted text, and

LatexHighlighter(f::Function, fd::Function)

where the user select the desired decoration by specifying the function fd.

Note

If multiple highlighters are valid for the element (i, j), the applied style will be equal to the first match considering the order in the vector highlighters.

Note

If the highlighters are used together with Formatters, the change in the format will not affect the parameter data passed to the highlighter function f. It will always receive the original, unformatted value.

For example, we if want to make the cells with value greater than 5 in bold, and all the cells with value less than 5 to be small, we can define:

hl_gt5 = LatexHighlighter(
    (data, i, j) -> data[i, j] > 5,
    ["textbf"]
)

hl_lt5 = LatexHighlighter(
    (data, i, j) -> data[i, j] < 5,
    ["small"]
)

highlighters = [hl_gt5, hl_lt5]

LaTeX Table Format

The LaTeX table format is defined using an object of type LatexTableFormat that contains the following fields:

  • borders::LatexTableBorders: Format of the borders.
  • horizontal_line_at_beginning::Bool: If true, a horizontal line will be drawn at the beginning of the table.
  • horizontal_line_after_column_labels::Bool: If true, a horizontal line will be drawn after the column labels.
  • horizontal_lines_at_data_rows::Union{Symbol, Vector{Int}}: A horizontal line will be drawn after each data row index listed in this vector. If the symbol :all is passed, a horizontal line will be drawn after every data column. If the symbol :none is passed, no horizontal lines will be drawn after the data rows.
  • horizontal_line_before_row_group_label::Bool: If true, a horizontal line will be drawn before the row group label.
  • horizontal_line_after_row_group_label::Bool: If true, a horizontal line will be drawn after the row group label.
  • horizontal_line_after_data_rows::Bool: If true, a horizontal line will be drawn after the data rows.
  • horizontal_line_after_summary_rows::Bool: If true, a horizontal line will be drawn after the summary rows.
  • vertical_line_at_beginning::Bool: If true, a vertical line will be drawn at the beginning of the table.
  • vertical_line_after_row_number_column::Bool: If true, a vertical line will be drawn after the row number column.
  • vertical_line_after_row_label_column::Bool: If true, a vertical line will be drawn after the row label column.
  • vertical_lines_at_data_columns::Union{Symbol, Vector{Int}}: A vertical line will be drawn after each data column index listed in this vector. If the symbol :all is passed, a vertical line will be drawn after every data column. If the symbol :none is passed, no vertical lines will be drawn after the data columns.
  • vertical_line_after_data_columns::Bool: If true, a vertical line will be drawn after the data columns.
  • vertical_line_after_continuation_column::Bool: If true, a vertical line will be drawn after the continuation column.

We provide a few helpers to configure the table format. For more information, see the documentation of the following macros:

LaTeX Table Style

The LaTeX table style is defined using an object of type LatexTableStyle that contains the following fields:

  • title::LatexEnvironments: Latex environments with the style for the title.
  • subtitle::LatexEnvironments: Latex environments with the style for the subtitle.
  • row_number_label::LatexEnvironments: Latex environments with the style for the row number label.
  • row_number::LatexEnvironments: Latex environments with the style for the row numbers.
  • stubhead_label::LatexEnvironments: Latex environments with the style for the stubhead label.
  • row_label::LatexEnvironments: Latex environments with the style for the row labels.
  • row_group_label::LatexEnvironments: Latex environments with the style for the row group label.
  • first_line_column_label::LatexEnvironments: Latex environments with the style for the first column label lines.
  • column_label::LatexEnvironments: Latex environments with the style for the rest of the column labels.
  • first_line_merged_column_label::LatexEnvironments: Latex environments with the style for the merged cells at the first column label line.
  • merged_column_label::LatexEnvironments: Latex environments with the style for the merged cells at the rest of the column labels.
  • summary_row_cell::LatexEnvironments: Latex environments with the style for the summary row cell.
  • summary_row_label::LatexEnvironments: Latex environments with the style for the summary row label.
  • footnote::LatexEnvironments: Latex environments with the style for the footnotes.
  • source_note::LatexEnvironments: Latex environments with the style for the source notes.
  • omitted_cell_summary::LatexEnvironments: Latex environments with the style for the omitted cell summary.

Each field is a LatexEnvironments object, which is a vector of strings with the LaTeX environments to be applied to the corresponding element.

For example, if we want to make the stubhead label bold and red, we must define:

style = LatexTableStyle(
    stubhead_label = ["textbf", "color{red}"]
)
source
PrettyTables.pretty_table_markdown_backendFunction

PrettyTables.jl Markdown Backend

The markdown backend can be selected by passing the keyword backend = :markdown to the function pretty_table. In this case, we have the following additional keywords to configure the output.

Keywords

  • allow_markdown_in_cells::Bool: If true, the content of the cells can contain markdown code. (Default: false)
  • highlighters::Vector{MarkdownHighlighter}: Highlighters to apply to the table. For more information, see the section Markdown Highlighters in the Extended Help.
  • line_breaks::Bool: If true, line breaks in the content of the cells (\n) are replaced by <br>. (Default: false)
  • style::MarkdownTableStyle: Style of the table. For more information, see the section Markdown Table Style in the Extended Help.
  • table_format::MarkdownTableFormat: Markdown table format used to render the table. For more information, see the section Markdown Table Format in the Extended Help.

Extended Help

Markdown Highlighters

A set of highlighters can be passed as a Vector{MarkdownHighlighter} to the highlighters keyword. Each highlighter is an instance of the structure MarkdownHighlighter. It contains the following two public fields:

  • f::Function: Function with the signature f(data, i, j) in which should return true if the element (i, j) in data must be highlighted, or false otherwise.
  • fd::Function: Function with the signature fd(h, data, i, j) in which h is the highlighter. This function must return the MarkdownStyle to be applied to the

cell that must be highlighted.

The function f has the following signature:

f(data, i, j)

in which data is a reference to the data that is being printed, and i and j are the element coordinates that are being tested. If this function returns true, the highlight style will be applied to the (i, j) element. Otherwise, the default style will be used.

If the function f returns true, the function fd(h, data, i, j) will be called and must return an element of type MarkdownStyle that contains the decoration to be applied to the cell.

A markdown highlighter can be constructed using two helpers:

MarkdownHighlighter(f::Function, decoration::MarkdownStyle)

MarkdownHighlighter(f::Function, fd::Function)

The first will apply a fixed decoration to the highlighted cell specified in decoration whereas the second let the user select the desired decoration by specifying the function fd.

Note

If multiple highlighters are valid for the element (i, j), the applied style will be equal to the first match considering the order in the tuple highlighters.

Note

If the highlighters are used together with Formatters, the change in the format will not affect the parameter data passed to the highlighter function f. It will always receive the original, unformatted value.

Markdown Table Format

The markdown table format is defined using an object of type MarkdownTableFormat that contains the following fields:

  • title_heading_level::Int: Title heading level.
  • subtitle_heading_level::Int: Subtitle heading level.
  • horizontal_line_char::Char: Character used to draw the horizontal line.
  • line_before_summary_rows::Bool: Whether to draw a line before the summary rows.

Markdown Table Style

The markdown table style is defined using an object of type MarkdownTableStyle that contains the following fields:

  • row_number_label::MarkdownStyle: Style for the row number label.
  • row_number::MarkdownStyle: Style for the row number.
  • stubhead_label::MarkdownStyle: Style for the stubhead label.
  • row_label::MarkdownStyle: Style for the row label.
  • row_group_label::MarkdownStyle: Style for the row group label.
  • first_column_label::MarkdownStyle: Style for the first line of the column labels.
  • column_label::MarkdownStyle: Style for the column label.
  • summary_row_label::MarkdownStyle: Style for the summary row label.
  • summary_row_cell::MarkdownStyle: Style for the summary row cell.
  • footnote::MarkdownStyle: Style for the footnote.
  • source_note::MarkdownStyle: Style for the source note.
  • omitted_cell_summary::MarkdownStyle: Style for the omitted cell summary.

Each field is an instance of the structure MarkdownStyle describing the style to be applied to the corresponding element.

For example, if we want that the stubhead label is bold and italic, we must define:

style = MarkdownTableStyle(
    stubhead_label = MarkdownStyle(bold = true, italic = true)
)
source
PrettyTables.pretty_table_text_backendFunction

PrettyTables.jl Text Backend

The text backend can be selected by passing the keyword backend = :text to the function pretty_table. In this case, we have the following additional keywords to configure the output.

Keywords

  • alignment_anchor_fallback::Symbol: This keyword controls the line alignment when using the regex alignment anchors if a match is not found. If it is :l, the left of the line will be aligned with the anchor. If it is :c, the line center will be aligned with the anchor. Otherwise, the end of the line will be aligned with the anchor. (Default = :l)
  • alignment_anchor_regex::Union{Vector{Regex}, Vector{Pair{Int, Vector{Regex}}}}: This keyword can be used to provide regexes to aligh the data values in the table columns. It it is Vector{Regex}, the regexes will be used to align all the columns. If it is Vector{Pair{Int, Vector{Regex}}}, the Int element specify the column to which the regexes in Vector{Regex} will be applied. The regex match is searched in the same order as the regexes appear on the vector. The regex matching is applied after the cell conversion to string, which includes the formatters. If no match is found for a specific line, the alignment of this line depends on the options alignment_anchor_fallback. Example: [2 => [r"\."]] aligns the decimal point of the cells in the second column. (Default = Regex[])
  • auto_wrap::Bool: If true, the text will be wrapped on spaces to fit the column. Notice that this function requires linebreaks = true and the column must have a fixed size (see fixed_data_column_widths). (Default = false)
  • column_label_width_based_on_first_line_only::Bool: If true, the column label width is based on the first line of the column. Hence, if the other column labels have a text width larger than the computed column width, they will be cropped to fit. (Default = false)
  • display_size::Tuple{Int, Int}: A tuple of two integers that defines the display size (num. of rows, num. of columns) that is available to print the table. It is used to crop the data depending on the value of the keyword crop. Notice that if a dimension is not positive, it will be treated as unlimited. (Default = displaysize(io))
  • equal_data_column_widths::Bool: If true, the data columns will have the same width. (Default = false)
  • fit_table_in_display_horizontally::Bool: If true, the table will be cropped to fit the display horizontally. (Default = true)
  • fit_table_in_display_vertically::Bool: If true, the table will be cropped to fit the display vertically. (Default = true)
  • fixed_data_column_widths::Union{Int, Vector{Int}}: If it is a Vector{Int}, this vector specifies the width of each column. If it is a Int, this number will be used as the width of all columns. If the width is equal or lower than 0, it will be automatically computed to fit the large cell in the column. (Default = 0)
  • highlighters::Vector{TextHighlighter}: Highlighters to apply to the table. For more information, see the section Text Highlighters in the Extended Help.
  • line_breaks::Bool: If true, a new line character will break the line inside the cells. (Default = false)
  • maximum_data_column_widths::Union{Int, Vector{Int}}: If it is a Vector{Int}, this vector specifies the maximum width of each column. If it is a Int, this number will be used as the maximum width of all columns. If the maximum width is equal or lower than 0, it will be ignored. Notice that the parameter fixed_data_column_widths has precedence over this one. (Default = 0)
  • overwrite_display::Bool: If true, the same number of lines in the printed table will be deleted from the output io. This can be used to update the table in the display continuously. (Default = false)
  • reserved_display_lines::Int: Number of lines to be left at the beginning of the printing when vertically cropping the output. (Default = 0)
  • style::TextTableStyle: Style of the table. For more information, see the section Text Table Style in the Extended Help.
  • table_format::TextTableFormat: Text table format used to render the table. For more information, see the section Text Table Format in the Extended Help.

Extended Help

Text highlighters

A set of highlighters can be passed as a Vector{TextHighlighter} to the highlighters keyword. Each highlighter is an instance of the structure TextHighlighter. It contains three fields:

  • f::Function: Function with the signature f(data, i, j) in which should return true if the element (i, j) in data must be highlighter, or false otherwise.
  • fd::Function: Function with the signature f(h, data, i, j) in which h is the highlighter. This function must return the Crayon to be applied to the cell that must be highlighted.
  • crayon::Crayon: The Crayon to be applied to the highlighted cell if the default fd is used.

The function f has the following signature:

f(data, i, j)

in which data is a reference to the data that is being printed, and i and j are the element coordinates that are being tested. If this function returns true, the cell (i, j) will be highlighted.

If the function f returns true, the function fd(h, data, i, j) will be called and must return a Crayon that will be applied to the cell.

A highlighter can be constructed using three helpers:

Highlighter(f::Function; kwargs...)

where it will construct a Crayon using the keywords in kwargs and apply it to the highlighted cell,

Highlighter(f::Function, crayon::Crayon)

where it will apply the crayon to the highlighted cell, and

Highlighter(f::Function, fd::Function)

where it will apply the Crayon returned by the function fd to the highlighted cell.

Note

If multiple highlighters are valid for the element (i, j), the applied style will be equal to the first match considering the order in the tuple highlighters.

Note

If the highlighters are used together with Formatters, the change in the format will not affect the parameter data passed to the highlighter function f. It will always receive the original, unformatted value.

For example, we if want to highlight the cells with value greater than 5 in red, and all the cells with value less than 5 in blue, we can define:

hl_gt5 = TextHighlighter(
    (data, i, j) -> data[i, j] > 5,
    crayon"red"
)

hl_lt5 = HtmlHighlighter(
    (data, i, j) -> data[i, j] < 5,
    crayon"blue"
)

highlighters = [hl_gt5, hl_lt5]

Text Table Format

The text table format is defined using an object of type TextTableFormat that contains the following fields:

  • borders::TextTableBorders: Format of the borders.
  • horizontal_line_at_beginning::Bool: If true, a horizontal line will be drawn at the beginning of the table.
  • horizontal_lines_at_column_labels::Union{Symbol, Vector{Int}}: A horizontal line will be drawn after each column label row index listed in this vector. If the symbol :all is passed, a horizontal line will be drawn after every column label. If the symbol :none is passed, no horizontal lines will be drawn.
  • horizontal_line_after_column_labels::Bool: If true, a horizontal line will be drawn after the column labels.
  • horizontal_lines_at_data_rows::Union{Symbol, Vector{Int}}: A horizontal line will be drawn after each data row index listed in this vector. If the symbol :all is passed, a horizontal line will be drawn after every data column. If the symbol :none is passed, no horizontal lines will be drawn.
  • horizontal_line_before_row_group_label::Bool: If true, a horizontal line will be drawn before the row group label.
  • horizontal_line_after_row_group_label::Bool: If true, a horizontal line will be drawn after the row group label.
  • horizontal_line_after_data_rows::Bool: If true, a horizontal line will be drawn after the data rows.
  • horizontal_line_after_summary_rows::Bool: If true, a horizontal line will be drawn after the summary rows.
  • vertical_line_at_beginning::Bool: If true, a vertical line will be drawn at the beginning of the table.
  • vertical_line_after_row_number_column::Bool: If true, a vertical line will be drawn after the row number column.
  • vertical_line_after_row_label_column::Bool: If true, a vertical line will be drawn after the row label column.
  • vertical_lines_at_data_columns::Union{Symbol, Vector{Int}}: A vertical line will be drawn after each data column index listed in this vector. If the symbol :all is passed, a vertical line will be drawn after every data column. If the symbol :none is passed, no vertical lines will be drawn after the data columns.
  • vertical_line_after_data_columns::Bool: If true, a vertical line will be drawn after the data columns.
  • vertical_line_after_continuation_column::Bool: If true, a vertical line will be drawn after the continuation column.
  • ellipsis_line_skip::Integer: Number of lines to skip when printing an ellipsis.

We provide a few helpers to configure the table format. For more information, see the documentation of the following macros:

Text Table Style

The text table style is defined using an object of type TextTableStyle that contains the following fields:

  • title::Crayon: Crayon with the style for the title.
  • subtitle::Crayon: Crayon with the style for the subtitle.
  • row_number_label::Crayon: Crayon with the style for the row number label.
  • row_number::Crayon: Crayon with the style for the row numbers.
  • stubhead_label::Crayon: Crayon with the style for the stubhead label.
  • row_label::Crayon: Crayon with the style for the row labels.
  • row_group_label::Crayon: Crayon with the style for the row group label.
  • first_line_column_label::Crayon: Crayon with the style for the first column label lines.
  • column_label::Crayon: Crayon with the style for the rest of the column labels.
  • first_line_merged_column_label::Crayon: Crayon with the style for the merged cells at the first column label line.
  • merged_column_label::Crayon: Crayon with the style for the merged cells at the rest of the column labels.
  • summary_row_cell::Crayon: Crayon with the style for the summary row cell.
  • summary_row_label::Crayon: Crayon with the style for the summary row label.
  • footnote::Crayon: Crayon with the style for the footnotes.
  • source_note::Crayon: Crayon with the style for the source notes.
  • omitted_cell_summary::Crayon: Crayon with the style for the omitted cell summary.
  • table_border::Crayon: Crayon with the style for the table border.

Each field is a Crayon describing the style for the corresponding element in the table.

For example, if we want that the stubhead label is bold and red, we must define:

style = TextTableStyle(
    stubhead_label = crayon"bold red"
)
source
PrettyTables.@latex__all_horizontal_linesMacro
@latex__all_horizontal_lines() -> Keywords for `LatexTableFormat`

Return the keyword arguments to be passed to LatexTableFormat to show all horizontal lines.

We can use the output of this function when creating the text table format object. For example, the following code creates a text table format with all horizontal lines:

tf = LatexTableFormat(; @latex__all_horizontal_lines())

Any option can be overridden by merging the keyword arguments. For example, the following code shows all the horizontal lines but the first one:

tf = LatexTableFormat(; @latex__all_horizontal_lines, horizontal_line_at_beginning = false)

Extended Help

Example

julia> A = ones(3, 3);

julia> pretty_table(A; table_format = LatexTableFormat(; @latex__all_horizontal_lines))
\begin{tabular}{|r|r|r|}
  \hline
  \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \\hline
  1.0 & 1.0 & 1.0 \\hline
  1.0 & 1.0 & 1.0 \\hline
  1.0 & 1.0 & 1.0 \\hline
\end{tabular}

julia> pretty_table(
           A;
           table_format = LatexTableFormat(;
               @latex__all_horizontal_lines,
               horizontal_line_after_column_labels = false
           )
       )
\begin{tabular}{|r|r|r|}
  \hline
  \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \
  1.0 & 1.0 & 1.0 \\hline
  1.0 & 1.0 & 1.0 \\hline
  1.0 & 1.0 & 1.0 \\hline
\end{tabular}
source
PrettyTables.@latex__all_vertical_linesMacro
@latex__all_vertical_lines() -> Keywords for `LatexTableFormat`

Return the keyword arguments to be passed to LatexTableFormat to show all vertical lines.

We can use the output of this function when creating the text table format object. For example, the following code creates a text table format with all vertical lines:

tf = LatexTableFormat(; @latex__all_vertical_lines)

Any option can be overridden by merging the keyword arguments. For example, the following code shows all the vertical lines but the first one:

tf = LatexTableFormat(; @latex__all_vertical_lines, vertical_line_at_beginning = false)

Extended Help

Examples

julia> A = ones(3, 3);

julia> pretty_table(A; table_format = LatexTableFormat(; @latex__all_vertical_lines))
\begin{tabular}{|r|r|r|}
  \hline
  \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \\\hline
  1.0 & 1.0 & 1.0 \\
  1.0 & 1.0 & 1.0 \\
  1.0 & 1.0 & 1.0 \\\hline
\end{tabular}

julia> pretty_table(
           A;
           show_row_number_column = true,
           table_format = LatexTableFormat(;
               @latex__all_vertical_lines,
               vertical_line_after_row_number_column = false
           )
       )
\begin{tabular}{|rr|r|r|}
  \hline
  \textbf{Row} & \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \\\hline
  1 & 1.0 & 1.0 & 1.0 \\
  2 & 1.0 & 1.0 & 1.0 \\
  3 & 1.0 & 1.0 & 1.0 \\\hline
\end{tabular}
source
PrettyTables.@latex__no_horizontal_linesMacro
latex__no_horizontal_lines() -> Keywords for `LatexTableFormat`

Return the keyword arguments to be passed to LatexTableFormat to suppress all horizontal lines.

We can use the output of this function when creating the text table format object. For example, the following code creates a text table format without horizontal lines:

tf = LatexTableFormat(; @latex__no_horizontal_lines)

Any option can be overridden by merging the keyword arguments. For example, the following code draws only the horizontal line at the beginning of the table:

tf = LatexTableFormat(; @latex__no_horizontal_lines, horizontal_line_at_beginning = true)

Extended Help

Example

julia> A = ones(3, 3);

julia> pretty_table(A; table_format = LatexTableFormat(; @latex__no_horizontal_lines))
\begin{tabular}{|r|r|r|}
  \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \\
  1.0 & 1.0 & 1.0 \\
  1.0 & 1.0 & 1.0 \\
  1.0 & 1.0 & 1.0 \\
\end{tabular}

julia> pretty_table(
           A;
           table_format = LatexTableFormat(;
               @latex__no_horizontal_lines,
               horizontal_line_after_column_labels = true
           )
       )
\begin{tabular}{|r|r|r|}
  \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \\\hline
  1.0 & 1.0 & 1.0 \\
  1.0 & 1.0 & 1.0 \\
  1.0 & 1.0 & 1.0 \\
\end{tabular}
source
PrettyTables.@latex__no_vertical_linesMacro
latex__no_vertical_lines() -> Keywords for `LatexTableFormat`

Return the keyword arguments to be passed to LatexTableFormat to suppress all vertical lines.

We can use the output of this function when creating the text table format object. For example, the following code creates a text table format without vertical lines:

tf = LatexTableFormat(; @latex__no_vertical_lines)

Any option can be overridden by merging the keyword arguments. For example, the following code draws only the vertical line at the beginning of the table:

tf = LatexTableFormat(; @latex__no_vertical_lines, vertical_line_at_beginning = true)

Extended Help

Examples

julia> A = ones(3, 3);

julia> pretty_table(A; table_format = LatexTableFormat(; @latex__no_vertical_lines))
\begin{tabular}{rrr}
  \hline
  \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \\\hline
  1.0 & 1.0 & 1.0 \\
  1.0 & 1.0 & 1.0 \\
  1.0 & 1.0 & 1.0 \\\hline
\end{tabular}

julia> pretty_table(
           A;
           show_row_number_column = true,
           table_format = LatexTableFormat(;
               @latex__no_vertical_lines,
               vertical_line_after_row_number_column = true
           )
       )
\begin{tabular}{r|rrr}
  \hline
  \textbf{Row} & \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} \\\hline
  1 & 1.0 & 1.0 & 1.0 \\
  2 & 1.0 & 1.0 & 1.0 \\
  3 & 1.0 & 1.0 & 1.0 \\\hline
\end{tabular}
source
PrettyTables.@latex_cell_strMacro
@latex_cell_str(str)

Create a table cell with LaTeX code.

Examples

julia> latex_cell"	extbf{Bold text}"
LatexCell{String}("\textbf{Bold text}")
source
PrettyTables.@text__all_horizontal_linesMacro
@text__all_horizontal_lines() -> Keywords for `TextTableFormat`

Return the keyword arguments to be passed to TextTableFormat to show all horizontal lines.

We can use the output of this function when creating the text table format object. For example, the following code creates a text table format with all horizontal lines:

tf = TextTableFormat(; @text__all_horizontal_lines())

Any option can be overridden by merging the keyword arguments. For example, the following code shows all the horizontal lines but the first one:

tf = TextTableFormat(; @text__all_horizontal_lines, horizontal_line_at_beginning = false)

Extended Help

Example

julia> A = ones(3, 3);

julia> pretty_table(A; table_format = TextTableFormat(; @text__all_horizontal_lines))
┌────────┬────────┬────────┐
│ Col. 1 │ Col. 2 │ Col. 3 │
├────────┼────────┼────────┤
│    1.0 │    1.0 │    1.0 │
├────────┼────────┼────────┤
│    1.0 │    1.0 │    1.0 │
├────────┼────────┼────────┤
│    1.0 │    1.0 │    1.0 │
└────────┴────────┴────────┘

julia> pretty_table(
    A;
    table_format = TextTableFormat(
        ;
        @text__all_horizontal_lines,
        horizontal_line_after_column_labels = false
    )
)
┌────────┬────────┬────────┐
│ Col. 1 │ Col. 2 │ Col. 3 │
│    1.0 │    1.0 │    1.0 │
├────────┼────────┼────────┤
│    1.0 │    1.0 │    1.0 │
├────────┼────────┼────────┤
│    1.0 │    1.0 │    1.0 │
└────────┴────────┴────────┘
source
PrettyTables.@text__all_vertical_linesMacro
@text__all_vertical_lines() -> Keywords for `TextTableFormat`

Return the keyword arguments to be passed to TextTableFormat to show all vertical lines.

We can use the output of this function when creating the text table format object. For example, the following code creates a text table format with all vertical lines:

tf = TextTableFormat(; @text__all_vertical_lines)

Any option can be overridden by merging the keyword arguments. For example, the following code shows all the vertical lines but the first one:

tf = TextTableFormat(; @text__all_vertical_lines, vertical_line_at_beginning = false)

Extended Help

Examples

julia> A = ones(3, 3);

julia> pretty_table(A; table_format = TextTableFormat(; @text__all_vertical_lines))
┌────────┬────────┬────────┐
│ Col. 1 │ Col. 2 │ Col. 3 │
├────────┼────────┼────────┤
│    1.0 │    1.0 │    1.0 │
│    1.0 │    1.0 │    1.0 │
│    1.0 │    1.0 │    1.0 │
└────────┴────────┴────────┘

julia> pretty_table(
    A;
    show_row_number_column = true,
    table_format = TextTableFormat(
        ;
        @text__all_vertical_lines,
        vertical_line_after_row_number_column = false
    )
)
┌─────────────┬────────┬────────┐
│ Row  Col. 1 │ Col. 2 │ Col. 3 │
├─────────────┼────────┼────────┤
│   1     1.0 │    1.0 │    1.0 │
│   2     1.0 │    1.0 │    1.0 │
│   3     1.0 │    1.0 │    1.0 │
└─────────────┴────────┴────────┘
source
PrettyTables.@text__no_horizontal_linesMacro
text__no_horizontal_lines() -> Keywords for `TextTableFormat`

Return the keyword arguments to be passed to TextTableFormat to suppress all horizontal lines.

We can use the output of this function when creating the text table format object. For example, the following code creates a text table format without horizontal lines:

tf = TextTableFormat(; @text__no_horizontal_lines)

Any option can be overridden by merging the keyword arguments. For example, the following code draws only the horizontal line at the beginning of the table:

tf = TextTableFormat(; @text__no_horizontal_lines, horizontal_line_at_beginning = true)

Extended Help

Example

julia> A = ones(3, 3);

julia> pretty_table(A; table_format = TextTableFormat(; @text__no_horizontal_lines))
│ Col. 1 │ Col. 2 │ Col. 3 │
│    1.0 │    1.0 │    1.0 │
│    1.0 │    1.0 │    1.0 │
│    1.0 │    1.0 │    1.0 │

julia> pretty_table(
    A;
    table_format = TextTableFormat(
        ;
        @text__no_horizontal_lines,
        horizontal_line_after_column_labels = true
    )
)
│ Col. 1 │ Col. 2 │ Col. 3 │
├────────┼────────┼────────┤
│    1.0 │    1.0 │    1.0 │
│    1.0 │    1.0 │    1.0 │
│    1.0 │    1.0 │    1.0 │
source
PrettyTables.@text__no_vertical_linesMacro
text__no_vertical_lines() -> Keywords for `TextTableFormat`

Return the keyword arguments to be passed to TextTableFormat to suppress all vertical lines.

We can use the output of this function when creating the text table format object. For example, the following code creates a text table format without vertical lines:

tf = TextTableFormat(; @text__no_vertical_lines)

Any option can be overridden by merging the keyword arguments. For example, the following code draws only the vertical line at the beginning of the table:

tf = TextTableFormat(; @text__no_vertical_lines, vertical_line_at_beginning = true)

Extended Help

Examples

julia> A = ones(3, 3);

julia> pretty_table(A; table_format = TextTableFormat(; @text__no_vertical_lines))
────────────────────────
 Col. 1  Col. 2  Col. 3
────────────────────────
    1.0     1.0     1.0
    1.0     1.0     1.0
    1.0     1.0     1.0
────────────────────────

julia> pretty_table(
    A;
    show_row_number_column = true,
    table_format = TextTableFormat(
        ;
        @text__no_vertical_lines,
        vertical_line_after_row_number_column = true
    )
)
─────┬────────────────────────
 Row │ Col. 1  Col. 2  Col. 3
─────┼────────────────────────
   1 │    1.0     1.0     1.0
   2 │    1.0     1.0     1.0
   3 │    1.0     1.0     1.0
─────┴────────────────────────
source