Library
Documentation for PrettyTables.jl.
PrettyTables.T_BACKENDS — TypeT_BACKENDSTypes that define the supported back ends.
PrettyTables.AnsiTextCell — TypeAnsiTextCellA text cell that supports rendering ANSI escape sequences without interfering with the table layout.
Fields
Public
string::String: The string with the cell text that can contain ANSI escape sequences.
Private
_rendered_lines::Union{Nothing, Vector{String}}: The lines with the rendered strings._stripped_lines::Union{Nothing, Vector{String}}: The lines with the printable text._crops::Union{Nothing, Vector{Int}}: Vector with the number of characters that must be cropped at each line._left_pads::Union{Nothing, Vector{Int}}: Left padding to be applied to each line._right_pads::Union{Nothing, Vector{Int}}: Right padding to be applied to each line._suffixes::Union{Nothing, Vector{String}}: Suffixed to be applied to each line.
PrettyTables.AnsiTextCell — MethodAnsiTextCell(string::AbstractString)Create an AnsiTextCell using string.
AnsiTextCell(renderfn[; context])Create an AnsiTextCell using a render function.
renderfn is a function with the following signature:
renderfn(io)::Stringthat renders a string that can contain ANSI sequences into io.
context is a tuple of context arguments passed to an IOContext that renderfn receives. See IOContext for details on what arguments are available.
Useful for supporting packages that have rich terminal outputs.
Examples
Below are examples for wrappers around AnsiTextCell to print rich data into tables that make use of packages with rich terminal output.
Crayons.jl
Apply custom decoration to text inside a cell.
using Crayons, PrettyTables
b = crayon"blue bold"
y = crayon"yellow bold"
g = crayon"green bold"
pretty_table([AnsiTextCell("$(g)This $(y)is $(b)awesome!") for _ in 1:5, _ in 1:5])ImageInTerminal.jl
Show images inside a table.
using ImageInTerminal, PrettyTables
function ImageCell(img, size)
return AnsiTextCell(
io -> ImageInTerminal.imshow(io, img),
context = (:displaysize => size,),)
end
using TestImages
img = testimage("lighthouse")
pretty_table([ImageCell(img, (20, 20)) ImageCell(img, (40, 40))])UnicodePlots.jl
Show a variety of plots in a table.
using UnicodePlots, PrettyTables
function UnicodePlotCell(p)
return AnsiTextCell(
io -> show(io, p),
context = (:color => true,)
)
end
pretty_table([
UnicodePlotCell(barplot(Dict("x" => 10, "y" => 20)))
UnicodePlotCell(boxplot([1, 3, 3, 4, 6, 10]))
])CommonMark.jl
Use rich Markdown inside tables.
using CommonMark, PrettyTables
function MarkdownCell(md)
return AnsiTextCell(
renderfn = io -> display(TextDisplay(io), md),
context = (:color => true,)
)
end
pretty_table([MarkdownCell(cm"**Hi**") MarkdownCell(cm"> quote")])PrettyTables.ColumnTable — Typestruct ColumnTableThis structure helps to access elements that comply with the column access specification of Tables.jl.
PrettyTables.CustomTextCell — Typeabstract type CustomTextCellAbstract type of custom cells in the text backend.
Each type must implement the following API:
get_printable_cell_text: A function that must return a vector of strings with the printable text, i.e. without any non-printable character.get_rendered_line: A function that must return the rendered line that will be printed to the display.apply_line_padding!: Apply a certain number of spaces to the left and right of a specific line.crop_line!: A function that must crop a certain number of printable characters from the end of the line.append_suffix_to_line!: Append a string suffix to a line of the custom cell.apply_line_padding!: Apply left and right padding to a line of the custom cell.crop_line!: Crop a certain number of characters from a line of the custom cell.get_printable_cell_line: Get a printable line of the custom cell.get_rendered_line: Get a rendered line of the custom cell.parse_cell_text: Parse the cell text and return aVector{String}with the printable lines.reset!: Reset all the temporary fields. This function is not required.
PrettyTables.Display — Typestruct DisplayStore the information of the display and the current cursor position.
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.cont_char::Char: The character that indicates the line is cropped.cont_reset::Bool: Iftrue, the decoration will be reseted before printing the continuation character. Otherwise, the decoration will be reseted after printing the continuation character.cont_space_char::Char: Space character to be printed beforecont_char.
PrettyTables.Highlighter — Typestruct HighlighterDefines the default highlighter of a table when using the text backend.
Fields
f::Function: Function with the signaturef(data, i, j)in which should returntrueif the element(i,j)indatamust be highlighter, orfalseotherwise.fd::Function: Function with the signaturef(h, data, i, j)in whichhis the highlighter. This function must return theCrayonto be applied to the cell that must be highlighted.crayon::Crayon: TheCrayonto be applied to the highlighted cell if the defaultfdis used.
Remarks
This structure 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.
PrettyTables.HtmlCell — Typestruct HtmlCellDefines a table cell that contains HTML code. It can be created using the macro @html_cell_str.
PrettyTables.HtmlDecoration — TypeHtmlDecorationStructure that defines parameters to decorate a table cell.
PrettyTables.HtmlHighlighter — TypeHtmlHighlighterDefines the default highlighter of a table when using the html backend.
Fields
f::Function: Function with the signaturef(data,i,j)in which should returntrueif the element(i,j)indatamust be highlighter, orfalseotherwise.fd::Function: Function with the signaturef(h,data,i,j)in whichhis the highlighter. This function must return theHtmlDecorationto be applied to the cell that must be highlighted.decoration::HtmlDecoration: TheHtmlDecorationto be applied to the highlighted cell if the defaultfdis used.
Remarks
This structure can be constructed using two helpers:
HtmlHighlighter(f::Function, decoration::HtmlDecoration)
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.
PrettyTables.HtmlTableFormat — TypeHtmlTableFormatFormat 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.
Remarks
Besides the usual HTML tags related to the tables (table, td,th,tr, etc.), there are three important classes that can be used to format tables using the variablecss`.
header: This is the class of the header (first line).subheader: This is the class of the sub-headers (all the rest of the lines in the header section).headerLastRow: The last row of the header section has additionally this class.rowNumber: All the cells related to the row number have this class. Thus, the row number header can be styled usingth.rowNumberand the row numbers cells can be styled usingtd.rowNumber.
PrettyTables.LatexCell — Typestruct LatexCellDefines a table cell that contains LaTeX code. It can be created using the macro @latex_cell_str.
PrettyTables.LatexHighlighter — TypeLatexHighlighterDefines the default highlighter of a table when using the LaTeX backend.
Fields
f::Function: Function with the signaturef(data, i, j)in which should returntrueif the element(i, j)indatamust be highlighted, orfalseotherwise.fd: A function with the signaturef(data, i, j, str)::Stringin whichdatais the matrix,(i, j)is the element position in the table, andstris the data converted to string. This function must return a string that will be placed in the cell.
Remarks
This structure can be constructed using two helpers:
LatexHighlighter(f::Function, envs::Union{String, Vector{String}})
LatexHighlighter(f::Function, fd::Function)The first will apply recursively all the LaTeX environments in envs to the highlighted text whereas the second let 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>}}PrettyTables.LatexTableFormat — Typestruct LatexTableFormatThis structure defines the format of the LaTeX table.
Fields
top_line::String: Top line of the table.header_line::String: Line that separate the header from the table body.mid_line::String: Line printed in the middle of the table.bottom_line::String: Bottom line of the table.left_vline::String: Left vertical line of the table.mid_vline::String: Vertical line in the middle of the table.right_vline::String: Right vertical line of the table.header_envs::Vector{String}: LaTeX environments that will be used in each header cell.subheader_envs::Vector{String}: LaTeX environments that will be used in each sub-header cell.hlines::Vector{Symbol}: Horizontal lines that must be drawn by default.vlines::Union{Symbol, Vector{Symbol}}: Vertical lines that must be drawn by default.table_type::Symbol: Select the type of table that should be used for this format.wrap_table::Bool: Select if the table must be wrapped inside the environment defined bywrap_table_environment.wrap_table_environment::String: Environment in which the table will be wrapped ifwrap_tableis true.
PrettyTables.MarkdownDecoration — Typestruct MarkdownDecorationStructure that defines parameters to decorate a table cell in Markdown back end.
Fields
bold::Bool: Bold text.italic::Bool: Italic text.strikethrough::Bool: Strikethrough.code::Bool: Code.
PrettyTables.MarkdownHighlighter — Typestruct MarkdownHighlighterDefines the default highlighter of a table when using the markdown backend.
Fields
f::Function: Function with the signaturef(data, i, j)in which should returntrueif the element(i, j)indatamust be highlighter, orfalseotherwise.fd::Function: Function with the signaturefd(h, data, i, j)in whichhis the highlighter. This function must return theMarkdownDecorationto be applied to the cell that must be highlighted.decoration::MarkdownDecoration: TheMarkdownDecorationto be applied to the highlighted cell if the defaultfdis used.
Remarks
This structure can be constructed using two helpers:
MarkdownHighlighter(f::Function, decoration::MarkdownDecoration)
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.
PrettyTables.PrettyTablesConf — Typestruct PrettyTablesConfType of the object that holds a pre-defined set of configurations for PrettyTables.jl.
PrettyTables.PrintInfo — Typestruct PrintInfoThis structure stores the information required so that the back ends can print the tables.
PrettyTables.ProcessedTable — Typestruct ProcessedTableThis struct contains the processed table, which handles additional columns, etc. All the backend functions have access to this object.
PrettyTables.ProcessedTable — MethodProcessedTable(data::Any, header::Any; kwargs...)Create a processed table with data and header.
PrettyTables.RowPrintingState — Typestruct RowPrintingStateStructure that hold the state of the row printing state machine.
PrettyTables.RowTable — Typestruct RowTableThis structure helps to access elements that comply with the row access specification of Tables.jl.
PrettyTables.TextCrayons — Typestruct TextCrayonsStructure that holds all the crayons in the text backend.
PrettyTables.TextFormat — Typestruct TextFormatFields
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.hlines::Vector{Symbol}: Horizontal lines that must be drawn by default.vlines::Union{Symbol, Vector{Symbol}}: Vertical lines that must be drawn by default.
Pre-defined formats
The following pre-defined formats are available: unicode (default), mysql, compact, markdown, simple, ascii_rounded, and ascii_dots.
PrettyTables.UndefinedCell — Typestruct UndefinedCellInternal structure to indicate that a cell has an undefined reference.
PrettyTables.UrlTextCell — TypeUrlTextCellA text cell that contains a URL and is rendered using the ANSI escape sequence \e8].
Some terminals do not support this feature, leading to a layout problem in the printed table.
Fields
Public
text::String: The label of the URL.url::String: The URL.
Private
_crop::Int: Number of characters in the text that must be cropped when rendering the URL._left_pad::Int: Number of spaces to be added to the left of the text when rendering the URL._right_pad::Int: Number of spaces to be added to the right of the text when rendering the URL._suffix::String: Suffix to be appended to the text when rendering the URL.
PrettyTables._add_column! — Function_add_column!(ptable::ProcessedTable, new_column::AbstractVector, new_header::Vector{String} = String[""]; kwargs...) -> NothingAdd a new column new_column with header new_header to ptable.
Keywords
alignment::Symbol: Alignment for the new column. (Default =:r)header_alignment::Symbol: Alignment for the new column header. (Default =:s)id::Symbol: Identification symbol for the new column. (Default =:additional_column)
PrettyTables._apply_markdown_decoration — Method_apply_markdown_decoration(str::String, d::MarkdownDecoration) -> StringApply the markdown decoration d to str.
PrettyTables._aprint — Function_aprint(buf::IO[, v]; indentation = 0, nspace = 2, minify = false) -> NothingPrint the variable v to the buffer buf at the indentation level indentation. Each level has nspaces spaces. If minify is true, then the text is printed without breaklines or padding.
If v is not present, only the indentation spaces will be printed.
PrettyTables._aprintln — Function_aprintln(buf::IO, [v,] indentation = 0, nspaces = 2, minify = false) -> NothingSame as _aprint, but a new line will be added at the end. Notice that this newline is not added if minify is true Notice that this newline is not added if minify is true.
PrettyTables._check_hline — Method_check_hline(ptable::ProcessedTable, hlines, body_hlines::AbstractVector, i::Int) -> BoolCheck if there is a horizontal line after the ith row of ptable considering the options hlines and body_hlines.
PrettyTables._check_vline — Method_check_vline(ptable::ProcessedTable, vlines::AbstractVector, j::Int) -> BoolCheck if there is a vertical line after the jth column of ptable considering the option vlines.
PrettyTables._conf_to_nt — Method_conf_to_nt(conf::PrettyTablesConf) -> NamedTupleConvert the configuration object conf to a named tuple so that it can be passed to pretty_table.
PrettyTables._convert_axes — Method_convert_axes(data::Any, i::Int) -> IntConvert the axes from the printed table data i to the axes in data.
i refers to the i-th element that will be printed.
_convert_axes(data::Any, i::Int, j::Int) -> IntConvert the axes from the printed table data (i, j) to the axes in data.
(i, j) refers to the i-th data row and j-th data column that will be printed.
PrettyTables._count_hlines — Method_count_hlines(ptable::ProcessedTable, hlines::Vector{Int}, body_hlines::Vector{Int}) -> IntCount the number of horizontal lines.
PrettyTables._count_vlines — Method_count_vlines(ptable::ProcessedTable, vlines::Vector{Int}) -> IntCount the number of vertical lines.
PrettyTables._data_size — Method_data_size(ptable::ProcessedTable) -> Int, IntReturn a tuple with the original data size.
PrettyTables._get_cell_alignment — Method_get_cell_alignemnt(ptable::ProcessedTable, i::Int, j::Int) -> SymbolGet the alignment of the ptable cell in ith row and jth column.
PrettyTables._get_column_alignment — Method_get_column_alignment(ptable::ProcessedTable, j::Int) -> SymbolReturn the alignment of the jth column in ptable.
PrettyTables._get_column_id — Method_get_column_id(ptable::ProcessedTable, j::Int) -> SymbolReturn the identification symbol of the column j of ptable. If the column is from the original data, :__ORIGINAL_DATA__ is returned.
PrettyTables._get_data_column_index — Method_get_data_column_index(ptable::ProcessedTable, j::Int) -> IntGet the index of the jth data column in ptable.
PrettyTables._get_data_row_index — Method_get_data_row_index(ptable::ProcessedTable, i::Int) -> IntGet the index of the ith data row in ptable.
PrettyTables._get_element — Method_get_element(ptable::ProcessedTable, i::Int, j::Int) -> AnyGet the element (i, j) if ptable. This function always considers the additional columns and the header.
Notice that i and j must be related to the row and column that will be printed. The actual index inside the data is handle internally in this function.
PrettyTables._get_header_element — Method_get_header_element(ptable::ProcessedTable, j::Int) -> AnyGet the jth header element in ptable. This function always considers the additional columns.
_get_num_of_hidden_columns(ptable::ProcessedTable) -> IntReturn the number of hidden columns (see option max_num_of_columns).
_get_num_of_hidden_rows(ptable::ProcessedTable) -> IntReturn the number of hidden rows (see option max_num_of_rows).
PrettyTables._get_row_id — Method_get_row_id(ptable::ProcessedTable, j::Int) -> SymbolReturn the identification symbol of the row i of ptable. If the row is part of the header, it returns :__HEADER__: or :__SUBHEADER__. Otherwise it returns :__ORIGINAL_DATA__ because we do not have the functionality to add new rows yet.
PrettyTables._get_table_column_index — Method_get_table_column_index(ptable::ProcessedTable, jr::Int) -> Union{Nothing, Int}Get the table column index related to a data table index jr in ptable.
PrettyTables._header_size — Method_header_size(ptable::ProcessedTable) -> Int, IntReturn a tuple with the header size.
PrettyTables._is_cell_alignment_overridden — Method_is_cell_alignment_overridden(ptable::ProcessedTable, i::Int, j::Int) -> BoolReturn true is the alignment of the cell (i, j) is overridden using the keyword option cell_alignment.
PrettyTables._num_additional_columns — Method_num_additional_columns(ptable::ProcessedTable) -> IntReturn the number of additional columns.
PrettyTables._process_hlines — Method_process_hlines(ptable::ProcessedTable, hlines) -> Union{Symbol, Vector{Int}}Process the horizontal lines hlines considering the processed table ptable.
PrettyTables._process_vlines — Method_process_vlines(ptable::ProcessedTable, vlines) -> Union{Symbol, Vector{Int}}Process the vertical lines vlines considering the processed table ptable.
PrettyTables._size — Method_size(ptable::ProcessedTable) -> Int, IntReturn a tuple with the current size of the table, considering the header, and the additional columns, but also the maximum number of rows and columns that user wants.
PrettyTables._total_size — Method_total_size(ptable::ProcessedTable) -> IntReturn the total table size neglecting the options max_num_of_columns and max_num_of_rows.
PrettyTables.append_suffix_to_line! — Methodappend_suffix_to_line!(c::CustomTextCell, l::Int, suffix::String)Append the suffix to the line l of the custom cell text c.
PrettyTables.apply_line_padding! — Methodapply_line_padding!(c::CustomTextCell, l::Int, left_pad::Int, right_pad::Int)Apply to the line l of the custom text cell c the padding with left_pad spaces in the left and right_pad spaces in the right.
PrettyTables.clear_pt_conf! — Methodclear_pt_conf!(conf::PrettyTablesConf) -> NothingClear all configurations in conf.
PrettyTables.compact_type_str — Methodcompact_type_str(T) -> StringReturn a string with a compact representation of type T.
PrettyTables.crop_line! — Methodcrop_line!(c::CustomTextCell, l::Int, num::Int)Crop num characters from the line l of the custom text cell c. The number of cropped characters must consider the left and right alignment paddings.
PrettyTables.ft_latex_sn — Methodft_latex_sn(m_digits::Int, [columns::AbstractVector{Int}]) -> FunctionFormat the numbers of the elements in the columns to a scientific notation using LaTeX. 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.
If m_digits is a Vector, columns must be also be a Vector with the same number of elements. If m_digits is a Integer, and columns is not specified (or is empty), the format will be applied to the entire table. Otherwise, if m_digits is a String and columns is a Vector, the format will be applied only to the columns in columns.
This formatter will be applied only to the cells that are of type Number.
PrettyTables.ft_nomissing — Methodft_nomissing(v::Any, i::Int, j::Int) -> AnyReplace missing with an empty string. If v is not Missing, v is returned.
PrettyTables.ft_nonothing — Methodft_nonothing(v, i::Int, j::Int) -> AnyReplace nothing with an empty string. If v is not Nothing, v is returned.
PrettyTables.ft_printf — Methodft_printf(ftv_str::Union{String, Vector{String}}, [columns::AbstractVector{Int}]) -> FunctionApply the formats ftv_str (see the Printf standard library) to the elements in the columns columns.
If ftv_str is a Vector, columns must be also be a Vector with the same number of elements. If ftv_str is a String, and columns is not specified (or is empty), the format will be applied to the entire table. Otherwise, if ftv_str is a String and columns is a Vector, the format will be applied only to the columns in columns.
This formatter will be applied only to the cells that are of type Number.
PrettyTables.ft_round — Methodft_round(digits::Union{Int, AbstractVector{Int}}, [columns::AbstractVector{Int}]) -> FunctionRound the elements in the columns to the number of digits.
If digits is a Vector, columns must be also be a Vector with the same number of elements. If digits is a Number, and columns is not specified (or is empty), the rounding will be applied to the entire table. Otherwise, if digits is a Number and columns is a Vector, the elements in the columns columns will be rounded to the number of digits digits.
PrettyTables.get_printable_cell_line — Methodget_printable_cell_line(c::CustomTextCell, l::Int)Return the printable line l of the custom text cell c. The printable cell line must consider the left and right alignment paddings.
PrettyTables.get_rendered_line — Methodget_rendered_line(c::CustomTextCell, l::Int)Return the rendered line l of the custom text cell l.
PrettyTables.hl_cell — Methodhl_cell(i::Number, j::Number, crayon::Crayon) -> HighlighterHighlight the cell (i,j) with the crayon.
hl_cell(cells::AbstractVector{NTuple(2,Int)}, crayon::Crayon) -> HighlighterHighlights all the cells with the crayon.
Those functions return a Highlighter to be used with the text backend.
PrettyTables.hl_cell — Methodhl_cell(i::Number, j::Number, decoration::HtmlDecoration) -> HtmlHighlighterHighlight the cell (i, j) with the decoration (see HtmlDecoration).
hl_cell(cells::AbstractVector{NTuple(2,Int)}, decoration::HtmlDecoration) -> HtmlHighlighterHighlights all the cells with the decoration (see HtmlDecoration).
Those functions return a HtmlHighlighter to be used with the HTML backend.
PrettyTables.hl_cell — Methodhl_cell(i::Number, j::Number, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlight the cell (i, j) with the decoration (see MarkdownDecoration).
hl_cell(cells::AbstractVector{NTuple(2,Int)}, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlights all the cells with the decoration (see MarkdownDecoration).
Those functions return a MarkdownHighlighter to be used with the HTML backend.
PrettyTables.hl_col — Methodhl_col(i::Number, crayon::Crayon) -> HighlighterHighlight the entire column i with the crayon.
hl_col(cols::AbstractVector{Int}, crayon::Crayon) -> HighlighterHighlights all the columns in cols with the crayon.
Those functions return a Highlighter to be used with the text backend.
PrettyTables.hl_col — Methodhl_col(i::Number, decoration::HtmlDecoration) -> HtmlHighlighterHighlight the entire column i with the decoration.
hl_col(cols::AbstractVector{Int}, decoration::HtmlDecoration) -> HtmlHighlighterHighlights all the columns in cols with the decoration.
Those functions return a HtmlHighlighter to be used with the HTML backend.
PrettyTables.hl_col — Methodhl_col(i::Number, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlight the entire column i with the decoration.
hl_col(cols::AbstractVector{Int}, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlights all the columns in cols with the decoration.
Those functions return a MarkdownHighlighter to be used with the HTML backend.
PrettyTables.hl_geq — Methodhl_geq(n::Number, decoration::HtmlDecoration) -> HtmlHighlighterHighlight all elements that are ≥ n using the decoration.
This function returns a HtmlHighlighter to be used with the text backend.
PrettyTables.hl_geq — Methodhl_geq(n::Number, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlight all elements that are ≥ n using the decoration.
This function returns a MarkdownHighlighter to be used with the text backend.
PrettyTables.hl_geq — Methodhl_geq(n::Number) -> HighlighterHighlight all elements that ≥ n.
Those functions return a Highlighter to be used with the text backend.
PrettyTables.hl_gt — Methodhl_gt(n::Number, decoration::HtmlDecoration) -> HtmlHighlighterHighlight all elements that are > n using the decoration.
This function returns a HtmlHighlighter to be used with the text backend.
PrettyTables.hl_gt — Methodhl_gt(n::Number, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlight all elements that are > n using the decoration.
This function returns a MarkdownHighlighter to be used with the text backend.
PrettyTables.hl_gt — Methodhl_gt(n::Number) -> HighlighterHighlight all elements that are > n.
Those functions return a Highlighter to be used with the text backend.
PrettyTables.hl_leq — Methodhl_leq(n::Number, decoration::HtmlDecoration) -> HtmlHighlighterHighlight all elements that are ≤ n using the decoration.
This function returns a HtmlHighlighter to be used with the text backend.
PrettyTables.hl_leq — Methodhl_leq(n::Number, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlight all elements that are ≤ n using the decoration.
This function returns a MarkdownHighlighter to be used with the text backend.
PrettyTables.hl_leq — Methodhl_leq(n::Number) -> HighlighterHighlight all elements that are ≤ n.
This function return a Highlighter to be used with the text backend.
PrettyTables.hl_lt — Methodhl_lt(n::Number, decoration::HtmlDecoration) -> HtmlHighlighterHighlight all elements that are < n using the decoration.
This function returns a HtmlHighlighter to be used with the text backend.
PrettyTables.hl_lt — Methodhl_lt(n::Number, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlight all elements that are < n using the decoration.
This function returns a MarkdownHighlighter to be used with the text backend.
PrettyTables.hl_lt — Methodhl_lt(n::Number) -> HighlighterHighlight all elements that are < n.
This function return a Highlighter to be used with the text backend.
PrettyTables.hl_row — Methodhl_row(i::Number, crayon::Crayon) -> HighlighterHighlight the entire row i with the crayon.
hl_row(rows::AbstractVector{Int}, crayon::Crayon) -> HighlighterHighlights all the rows in rows with the crayon.
Those functions return a Highlighter to be used with the text backend.
PrettyTables.hl_row — Methodhl_row(i::Number, decoration::HtmlDecoration) -> HtmlHighlighterHighlight the entire row i with the decoration.
hl_row(rows::AbstractVector{Int}, decoration::HtmlDecoration) -> HtmlHighlighterHighlights all the rows in rows with the decoration.
Those functions return a HtmlHighlighter to be used with the HTML backend.
PrettyTables.hl_row — Methodhl_row(i::Number, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlight the entire row i with the decoration.
hl_row(rows::AbstractVector{Int}, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlights all the rows in rows with the decoration.
Those functions return a MarkdownHighlighter to be used with the HTML backend.
PrettyTables.hl_value — Methodhl_value(v::Any, decoration::HtmlDecoration) -> HtmlHighlighterHighlight all the values that matches data[i,j] == v using the decoration.
This function returns a HtmlHighlighter to be used with the text backend.
PrettyTables.hl_value — Methodhl_value(v::Any, decoration::MarkdownDecoration) -> MarkdownHighlighterHighlight all the values that matches data[i,j] == v using the decoration.
This function returns a MarkdownHighlighter to be used with the text backend.
PrettyTables.hl_value — Methodhl_value(v::Any) -> HighlighterHighlight all the values that matches data[i,j] == v.
This function return a Highlighter to be used with the text backend.
PrettyTables.include_pt_in_file — Methodinclude_pt_in_file(filename::AbstractString, mark::AbstractString, args...; kwargs...) -> NothingInclude a table in the file filename using the mark.
This function will print a table using the arguments args and keywords kwargs in the function pretty_table (the IO must not be passed to args here). Then, it will search inside the file filename for the following section:
<PrettyTables mark>
...
</PrettyTables>and will replace everything between the marks with the printed table. If the closing tag is in a separate line, all characters before it will be kept. This is important to add comment tags.
If the user wants to also remove the opening and ending tags, pass the keyword remove_tags = true.
The keyword tag_append can be used to pass a string that can be used to add a text after the opening tag. This is important for HTML where the comments have opening and closing tags. Thus, if tag_append = " -->", the following can be used to add a table into HTML files:
<!-- <PrettyTables mark> -->
...
<!-- </PrettyTables> -->By default, this function will copy the original file to filename_backup. If this is not desired, pass the keyword backup_file = false to the function.
PrettyTables.parse_cell_text — Methodparse_cell_text(c::CustomTextCell; kwargs...)Parse the cell text and return a vector of String with the printable cell text, where each element in the vector is a new line.
The returned data must contain only the printable characters.
The following keyword arguments are passed to this function, which is called during the cell parsing phase. Those options are related to the input configuration of pretty_table, and the user must choose whether or not support them.
autowrap::Bool: Iftrue, the user wants to wrap the text in the cell. In this case, the optioncolumn_widthcontains the column width so that the text can be wrapped into multiple lines.cell_first_line_only::Bool: Iftrue, the user only wants the first line.column_width::Integer: The column width.compact_printing::Bool: Iftrue, the user wants compact printing (see:compactoptions ofIOContext).limit_printing::Bool: Iftrue, the user wants the cells to be converted using the option:limit => trueinIOContext.linebreaks::Bool: Iftrue, the user wants line breaks inside the cells.renderer::Union{Val{:print}, Val{:show}}: The render that the user wants to convert the cells to strings.
PrettyTables.pretty_table — Methodpretty_table([io::IO | String | HTML,] table; kwargs...)Print to io the table.
If io is omitted, it defaults to stdout. If String is passed in the place of io, a String with the printed table will be returned by the function. If HTML is passed in the place of io, an HTML object is returned with the printed table.
When printing, it will be verified 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:
AbstractVector: any vector can be printed.AbstractMatrix: any matrix can be printed.Dict: anyDictcan be printed. In this case, the special keywordsortkeyscan be used to select whether or not the user wants to print the dictionary with the keys sorted. If it isfalse, the elements will be printed on the same order returned by the functionskeysandvalues. Notice that this assumes that the keys are sortable, if they are not, an error will be thrown.
Keywords
alignment::Union{Symbol, Vector{Symbol}}: Select the alignment of the columns (see the sectionAlignment).backend::Union{Symbol, T_BACKENDS}: Select which back end will be used to print the table (see the sectionBack End). Notice that the additional configuration inkwargs...depends on the selected back end.cell_alignment::Union{Nothing, Dict{Tuple{Int, Int}, Symbol}, Function, Tuple}: A tuple of functions with the signaturef(data, i, j)that overrides the alignment of the cell(i, j)to the value returned byf. It can also be a single function, when it is assumed that only one alignment function is required, ornothing, when no cell alignment modification will be performed. If the functionfdoes not return a valid alignment symbol as shown in sectionAlignment, it will be discarded. For convenience, it can also be a dictionary of type(i, j) => athat overrides the alignment of the cell(i, j)toa.amust be a symbol like specified in the sectionAlignment. (Default =nothing)
If more than one alignment function is passed to cell_alignment, the functions will be evaluated in the same order of the tuple. The first one that returns a valid alignment symbol for each cell is applied, and the rest is discarded.
cell_first_line_only::Bool: Iftrue, only the first line of each cell will be printed. (Default =false)compact_printing::Bool: Select if the option:compactwill be used when printing the data. (Default =true)formatters::Union{Nothing, Function, Tuple}: See the sectionFormatters.header::Union{Symbol, Vector{Symbol}}: The header must be a tuple of vectors. Each one must have the number of elements equal to the number of columns in the table. The first vector is considered the header and the others are the subheaders. If it isnothing, a default value based on the type will be used. If a single vector is passed, it will be considered the header. (Default =nothing)header_alignment::Union{Symbol, Vector{Symbol}}: Select the alignment of the header columns (see the sectionAlignment). If the symbol that specifies the alignment is:sfor a specific column, the same alignment in the keywordalignmentfor that column will be used. (Default =:s)header_cell_alignment::Union{Nothing, Dict{Tuple{Int, Int}, Symbol}, Function, Tuple}: This keyword has the same structure ofcell_alignmentbut in this case it operates in the header. Thus,(i, j)will be a cell in the header matrix that contains the header and sub-headers. This means that thedatafield in the functions will be the same value passed in the keywordheader. (Default =nothing)
If more than one alignment function is passed to header_cell_alignment, the functions will be evaluated in the same order of the tuple. The first one that returns a valid alignment symbol for each cell is applied, and the rest is discarded.
limit_printing::Bool: Iftrue, the cells will be converted using the property:limit => trueofIOContext. (Default =true)max_num_of_columns::Int: The maximum number of table columns that will be rendered. If it is lower than 0, all columns will be rendered. (Default = -1)max_num_of_rows::Int: The maximum number of table rows that will be rendered. If it is lower than 0, all rows will be rendered. (Default = -1)renderer::Symbol: A symbol that indicates which function should be used to convert an object to a string. It can be:printto use the functionprintor:showto use the functionshow. Notice that this selection is applicable only to the table data. Headers, sub-headers, and row name column are always rendered with print. (Default =:print)row_labels::Union{Nothing, AbstractVector}: A vector containing the row labels that will be appended to the left of the table. If it isnothing, the column with the row labels will not be shown. Notice that the size of this vector must match the number of rows in the table. (Default =nothing)row_label_alignment::Symbol: Alignment of the column with the row labels (see the sectionAlignment).row_label_column_title::AbstractString: Title of the column with the row labels. (Default = "")row_number_column_title::AbstractString: Title of the column with the row numbers. (Default = "Row")show_header::Bool: Iftrue, the header will be printed. Notice that all keywords and parameters related to the header and sub-headers will be ignored. (Default =false)show_row_number::Bool: Iftrue, a new column will be printed showing the row number. (Default =false)show_subheader::Bool: Iftrue, the sub-header will be printed, i.e. the header will contain both the header and subheader. Notice that this option has no effect ifshow_header = false. (Default =true)title::AbstractString: The title of the table. If it is empty, no title will be printed. (Default = "")title_alignment::Symbol: Alignment of the title, which must be a symbol as explained in the sectionAlignment. This argument is ignored in the LaTeX back end. (Default = :l)
Notice that all back ends have the keyword tf to specify the table printing format. Thus, if the keyword backend is not present or if it is nothing, the back end will be automatically inferred from the type of the keyword tf. In this case, if tf is also not present, it just fall-back to the text back end unless HTML is passed as the first argument. In this case, the default back end is set to HTML.
If String is used, the keyword color selects whether or not the table will be converted to string with or without colors. The default value is false. Notice that this option only has effect in text back end.
Alignment
The keyword alignment can be a Symbol or a vector of Symbol.
If it is a symbol, we have the following behavior:
:lor:L: the text of all columns will be left-aligned;:cor:C: the text of all columns will be center-aligned;:ror:R: the text of all columns will be right-aligned;- Otherwise it defaults to
:r.
If it is a vector, it must have the same number of symbols as the number of columns in data. The i-th symbol in the vector specify the alignment of the -i*-th column using the same symbols as described previously.
In HTML back end, the user can select :n ou :N to print the cell without any alignment annotation.
Text Back End
This back end produces text tables. This back end can be used by selecting backend = :text.
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_fallback_override::Dict{Int, Symbol}: ADict{Int, Symbol}to override the behavior offallback_alignment_anchorfor a specific column. Example:Dict(3 => :c)changes the fallback alignment anchor behavior for:conly for the column 3.alignment_anchor_regex::Dict{Int, AbstractVector{Regex}}: A dictionaryDict{Int, AbstractVector{Regex}}with a set of regexes that is used to align the values in the columns (keys). The characters at the first regex match (or anchor) of each line in every cell of the column will be aligned. 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 optionsalignment_anchor_fallbackandalignment_anchor_fallback_override. If the key0is present, the related regexes will be used to align all the columns. In this case, all the other keys will be neglected. Example:Dict(2 => [r"\."])aligns the decimal point of the cells in the second column. (Default =Dict{Int, Vector{Regex}}())autowrap::Bool: Iftrue, the text will be wrapped on spaces to fit the column. Notice that this function requireslinebreaks = trueand the column must have a fixed size (seecolumns_width).body_hlines::Vector{Int}: A vector ofIntindicating row numbers in which an additional horizontal line should be drawn after the row. Notice that numbers lower than 0 and equal or higher than the number of printed rows will be neglected. This vector will be appended to the one inhlines, but the indices here are related to the printed rows of the body. Thus, if1is added tobody_hlines, a horizontal line will be drawn after the first data row. (Default =Int[])body_hlines_format::Union{Nothing, NTuple{4, Char}}: A tuple of 4 characters specifying the format of the horizontal lines that will be drawn bybody_hlines. The characters must be the left intersection, the middle intersection, the right intersection, and the row. If it isnothing, it will use the same format specified intf. (Default =nothing)columns_width::Union{Int, AbstractVector{Int}}: A set of integers specifying the width of each column. If the width is equal or lower than 0, it will be automatically computed to fit the large cell in the column. If it is a single integer, this number will be used as the size of all columns. (Default = 0)crop::Symbol: Select the printing behavior when the data is bigger than the available display size (seedisplay_size). It can be:bothto crop on vertical and horizontal direction,:horizontalto crop only on horizontal direction,:verticalto crop only on vertical direction, or:noneto do not crop the data at all. If theiohas:limit => true,cropis set to:bothby default. Otherwise, it is set to:noneby default.crop_subheader::Bool: Iftrue, the sub-header size will not be taken into account when computing the column size. Hence, the print algorithm can crop it to save space. This has no effect if the user selects a fixed column width. (Default =false)continuation_row_alignment::Symbol: A symbol that defines the alignment of the cells in the continuation row. This row is printed if the table is vertically cropped. (Default =:c)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 keywordcrop. Notice that if a dimension is not positive, it will be treated as unlimited. (Default =displaysize(io))ellipsis_line_skip::Integer: An integer defining how many lines will be skipped from showing the ellipsis that indicates the text was cropped. (Default = 0)equal_columns_width::Bool: Iftrue, all the columns will have the same width. (Default =false)highlighters::Union{Highlighter, Tuple}: An instance ofHighlighteror a tuple with a list of text highlighters (see the sectionText highlighters).hlines::Union{Nothing, Symbol, AbstractVector}: This variable controls where the horizontal lines will be drawn. It can benothing,:all,:noneor a vector of integers. (Default =nothing)- If it is
nothing, which is the default, the configuration will be obtained from the table format in the variabletf(seeTextFormat). - If it is
:all, all horizontal lines will be drawn. - If it is
:none, no horizontal line will be drawn. - If it is a vector of integers, the horizontal lines will be drawn only after the rows in the vector. Notice that the top line will be drawn if
0is inhlines, and the header and subheaders are considered as only 1 row. Furthermore, it is important to mention that the row number in this variable is related to the printed rows. Thus, it is affected by the option to suppress the headershow_header. Finally, for convenience, the top and bottom lines can be drawn by adding the symbols:beginand:endto this vector, respectively, and the line after the header can be drawn by adding the symbol:header.
- If it is
The values of body_hlines will be appended to this vector. Thus, horizontal lines can be drawn even if hlines is :none.
linebreaks::Bool: Iftrue,\nwill break the line inside the cells. (Default =false)maximum_columns_width::Union{Int, AbstractVector{Int}}: A set of integers specifying the maximum width of each column. If the width is equal or lower than 0, it will be ignored. If it is a single integer, this number will be used as the maximum width of all columns. Notice that the parametercolumns_widthhas precedence over this one. (Default = 0)minimum_columns_width::Union{Int, AbstractVector{Int}}: A set of integers specifying the minimum width of each column. If the width is equal or lower than 0, it will be ignored. If it is a single integer, this number will be used as the minimum width of all columns. Notice that the parametercolumns_widthhas precedence over this one. (Default = 0)newline_at_end::Bool: Iffalse, the table will not end with a newline character. (Default =true)overwrite::Bool: Iftrue, the same number of lines in the printed table will be deleted from the outputio. 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. Notice that the lines required to show the title are automatically computed. (Default = 0)row_number_alignment::Symbol: Select the alignment of the row number column (see the sectionAlignment). (Default =:r)show_omitted_cell_summary::Bool: Iftrue, a summary will be printed after the table with the number of columns and rows that were omitted. (Default =true)tf::TextFormat: Table format used to print the table (seeTextFormat). (Default =tf_unicode)title_autowrap::Bool: Iftrue, the title text will be wrapped considering the title size. Otherwise, lines larger than the title size will be cropped. (Default =false)title_same_width_as_table::Bool: Iftrue, the title width will match that of the table. Otherwise, the title size will be equal to the display width. (Default =false)vcrop_mode::Symbol: This variable defines the vertical crop behavior. If it is:bottom, the data, if required, will be cropped in the bottom. On the other hand, if it is:middle, the data will be cropped in the middle if necessary. (Default =:bottom)vlines::Union{Nothing, Symbol, AbstractVector}: This variable controls where the vertical lines will be drawn. It can benothing,:all,:noneor a vector of integers. (Default =nothing)- If it is
nothing, which is the default, the configuration will be obtained from the table format in the variabletf(seeTextFormat). - If it is
:all, all vertical lines will be drawn. - If it is
:none, no vertical line will be drawn. - If it is a vector of integers, the vertical lines will be drawn only after the columns in the vector. Notice that the left line will be drawn if
0is invlines. Furthermore, it is important to mention that the column number in this variable is related to the printed column. Thus, it is affected by the optionsrow_labelsandshow_row_number. Finally, for convenience, the left and right vertical lines can be drawn by adding the symbols:beginand:endto this vector, respectively.
- If it is
The following keywords related to crayons are available to customize the output decoration:
border_crayon::Crayon: Crayon to print the border.header_crayon::Union{Crayon, Vector{Crayon}}: Crayon to print the header.omitted_cell_summary_crayon::Crayon: Crayon used to print the omitted cell summary.row_label_crayon::Crayon: Crayon to print the row labels.row_label_header_crayon::Crayon: Crayon to print the header of the column with the row labels.row_number_header_crayon::Crayon: Crayon for the header of the column with the row numbers.subheader_crayon::Union{Crayon, Vector{Crayon}}: Crayon to print sub-headers.text_crayon::Crayon: Crayon to print default text.title_crayon::Crayon: Crayon to print the title.
The keywords header_crayon and subheader_crayon can be a Crayon or a Vector{Crayon}. In the first case, the Crayon will be applied to all the elements. In the second, each element can have its own crayon, but the length of the vector must be equal to the number of columns in the data.
Crayons
A Crayon is an object that handles a style for text printed on terminals. It is defined in the package Crayons.jl. There are many options available to customize the style, such as foreground color, background color, bold text, etc.
A Crayon can be created in two different ways:
julia> Crayon(foreground = :blue, background = :black, bold = :true)
julia> crayon"blue bg:black bold"For more information, see the package documentation.
Text highlighters
A set of highlighters can be passed as a Tuple to the highlighters keyword. Each highlighter is an instance of the structure Highlighter that contains three fields:
f::Function: Function with the signaturef(data, i, j)in which should returntrueif the element(i, j)indatamust be highlighter, orfalseotherwise.fd::Function: Function with the signaturef(h,data,i,j)in whichhis the highlighter. This function must return theCrayonto be applied to the cell that must be highlighted.crayon::Crayon: TheCrayonto be applied to the highlighted cell if the defaultfdis 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.
If only a single highlighter is wanted, it can be passed directly to the keyword highlighter without being inside a Tuple.
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.
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.
HTML Back End
This back end produces HTML tables. This back end can be used by selecting backend = Val(:html).
Keywords
allow_html_in_cells::Bool: By default, special characters like<,>,", etc. are replaced in HTML back end to generate valid code. However, this algorithm blocks the usage of HTML code inside of the cells. If this keyword istrue, the escape algorithm will not be applied, allowing HTML code inside all the cells. In this case, the user must ensure that the output code is valid. If only few cells have HTML code, wrap in aHtmlCellobject instead. (Default =false)continuation_row_alignment::Symbol: A symbol that defines the alignment of the cells in the continuation row. This row is printed if the table is vertically cropped. (Default =:r)highlighters::Union{HtmlHighlighter, Tuple}: An instance ofHtmlHighlighteror a tuple with a list of HTML highlighters (see the sectionHTML highlighters).linebreaks::Bool: Iftrue,\nwill be replaced by<br>. (Default =false)maximum_columns_width::String: A string with the maximum width of each columns. This string must contain a size that is valid in HTML. If it is not empty, each cell will have the following style:"max-width": <value of maximum_column_width>"overflow": "hidden""text-overflow": "ellipsis""white-space": "nowrap"
minify::Bool: Iftrue, output will be displayed minified, i.e. without unnecessary indentation or newlines. (Default =false)standalone::Bool: Iftrue, a complete HTML page will be generated. Otherwise, only the content between the tags<table>and</table>will be printed (with the tags included). (Default =false)vcrop_mode::Symbol: This variable defines the vertical crop behavior. If it is:bottom, the data, if required, will be cropped in the bottom. On the other hand, if it is:middle, the data will be cropped in the middle if necessary. (Default =:bottom)table_div_class::String: The class name for the tablediv. It is only used ifwrap_table_in_divistrue. (Default = "")table_class::String: The class name for the table. (Default = "")table_style::Dict{String, String}: A dictionary containing the CSS properties and their values to be added to the tablestyle. (Default =Dict{String, String}())tf::HtmlTableFormat: An instance of the structureHtmlTableFormatthat defines the general format of the HTML table.top_left_str::String: String to be printed at the left position of the top bar. (Default = "")top_left_str_decoration::HtmlDecoration: Decoration used to print the top-left string (seetop_left_str). (Default =HtmlDecoration())top_right_str::String: String to be printed at the right position of the top bar. Notice that this string will be replaced with the omitted cell summary if it must be displayed. (Default = "")top_right_str_decoration::HtmlDecoration: Decoration used to print the top-right string (seetop_right_str). (Default =HtmlDecoration())wrap_table_in_div::Bool: Iftrue, the table will be wrapped in adiv. (Default:false)
HTML highlighters
A set of highlighters can be passed as a Tuple 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 signaturef(data, i, j)in which should returntrueif the element(i,j)indatamust be highlighted, orfalseotherwise.fd::Function: Function with the signaturef(h, data, i, j)in whichhis the highlighter. This function must return theHtmlDecorationto 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 HtmlDecoration that contains the decoration to be applied to the cell.
A HTML highlighter can be constructed using two helpers:
HtmlHighlighter(f::Function, decoration::HtmlDecoration)
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.
If only a single highlighter is wanted, it can be passed directly to the keyword highlighter without being inside a Tuple.
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.
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.
LaTeX Back End
This back end produces LaTeX tables. This back end can be used by selecting backend = Val(:latex).
Keywords
body_hlines::Vector{Int}: A vector ofIntindicating row numbers in which an additional horizontal line should be drawn after the row. Notice that numbers lower than 1 and equal or higher than the number of printed rows will be neglected. This vector will be appended to the one inhlines, but the indices here are related to the printed rows of the body. Thus, if1is added tobody_hlines, a horizontal line will be drawn after the first data row. (Default =Int[])highlighters::Union{LatexHighlighter, Tuple}: An instance ofLatexHighlighteror a tuple with a list of LaTeX highlighters (see the sectionLaTeX highlighters).hlines::Union{Nothing, Symbol, AbstractVector}: This variable controls where the horizontal lines will be drawn. It can benothing,:all,:noneor a vector of integers. (Default =nothing)- If it is
nothing, which is the default, the configuration will be obtained from the table format in the variabletf(seeLatexTableFormat). - If it is
:all, all horizontal lines will be drawn. - If it is
:none, no horizontal line will be drawn. - If it is a vector of integers, the horizontal lines will be drawn only after the rows in the vector. Notice that the top line will be drawn if
0is inhlines, and the header and subheaders are considered as only 1 row. Furthermore, it is important to mention that the row number in this variable is related to the printed rows. Thus, it is affected by the option to suppress the headershow_header. Finally, for convenience, the top and bottom lines can be drawn by adding the symbols:beginand:endto this vector, respectively, and the line after the header can be drawn by adding the symbol:header.
- If it is
The values of body_hlines will be appended to this vector. Thus, horizontal lines can be drawn even if hlines is :none.
label::AbstractString: The label of the table. If empty, no label will be added. (Default = "")longtable_footer::Union{Nothing, AbstractString}: The string that will be drawn in the footer of the tables before a page break. This only works iftable_typeis:longtable. If it isnothing, no footer will be used. (Default =nothing)row_number_alignment::Symbol: Select the alignment of the row number column (see the sectionAlignment). (Default =:r)table_type::Union{Nothing, Symbol}: Select which LaTeX environment will be used to print the table. Currently supported options are:tabularfortabularor:longtableforlongtable. If it isnothingthe default option of the table format will be used. (Default =nothing)tf::LatexTableFormat: An instance of the structureLatexTableFormatthat defines the general format of the LaTeX table.vlines::Union{Nothing, Symbol, AbstractVector}: This variable controls where the vertical lines will be drawn. It can be:all,:noneor a vector of integers. In the first case (the default behavior), all vertical lines will be drawn. In the second case, no vertical line will be drawn. In the third case, the vertical lines will be drawn only after the columns in the vector. Notice that the left border will be drawn if0is invlines. Furthermore, it is important to mention that the column number in this variable is related to the printed columns. Thus, it is affected by the columns added using the variableshow_row_number. Finally, for convenience, the left and right border can be drawn by adding the symbols:beginand:endto this vector, respectively. (Default =:none)wrap_table::Union{Nothing, String}: This variable controls whether to wrap the table in a environment defined by the variablewrap_table_environment. Defaults totrue. Whenfalse, the printed table begins with\begin{tabular}. This option does not work with:longtable. If it isnothingthe default option of the table format will be used. (Default =nothing)wrap_table_environment::Union{Nothing, String}: Environment that will be used to wrap the table if the optionwrap_tableistrue. If it isnothingthe default option of the table format will be used. (Default =nothing)
LaTeX highlighters
A set of highlighters can be passed as a Tuple to the highlighters keyword. Each highlighter is an instance of the structure LatexHighlighter. It contains the following two fields:
f::Function: Function with the signaturef(data, i, j)in which should returntrueif the element(i, j)indatamust be highlighted, orfalseotherwise.fd::Functions: A function with the signaturef(data, i, j, str)::Stringin whichdatais the matrix,(i, j)is the element position in the table, andstris the data converted to string. This function must return a string that will be placed in the cell.
The function f has the following signature:
f(data, i, j)in which data is a reference to the data that is being printed, 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(data, i, j, str) will be called and must return the LaTeX string that will be placed in the cell.
There are two helpers that can be used to create LaTeX highlighters:
LatexHighlighter(f::Function, envs::Union{String,Vector{String}})
LatexHighlighter(f::Function, fd::Function)The first will apply recursively all the LaTeX environments in envs to the highlighted text whereas the second let 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>}}If only a single highlighter is wanted, it can be passed directly to the keyword highlighter without being inside a Tuple.
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.
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 Back End
This back end produces Markdown tables. This back end can be used by selecting backend = Val(:markdown).
Keywords
allow_markdown_in_cells::Bool: By default, special markdown characters like*,_,~, etc. are escaped in markdown back end to generate valid output. However, this algorithm blocks the usage of markdown code inside of the cells. If this keyword istrue, the escape algorithm will not be applied, allowing markdown code inside all the cells. In this case, the user must ensure that the output code is valid. (Default =false)highlighters::Union{MarkdownHighlighter, Tuple}: An instance ofMarkdownHighlighteror a tuple with a list of Markdown highlighters (see the section Markdown Highlighters).linebreaks::Bool: Iftrue,\nwill be replaced by<br>. (Default =false)show_omitted_cell_summary::Bool: Iftrue, a summary will be printed after the table with the number of columns and rows that were omitted. (Default =false)
The following keywords are available to customize the output decoration:
header_decoration::MarkdownDecoration: Decoration applied to the header. (Default =MarkdownDecoration(bold = true))row_label_decoration::MarkdownDecoration: Decoration applied to the row label column. (Default =MarkdownDecoration())row_number_decoration::MarkdownDecoration: Decoration applied to the row number column. (Default =MarkdownDecoration(bold = true))subheader_decoration::MarkdownDecoration: Decoration applied to the sub-header. (Default =MarkdownDecoration(code = true))
Markdown Highlighters
A set of highlighters can be passed as a Tuple 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 signaturef(data, i, j)in which should returntrueif the element(i,j)indatamust be highlighted, orfalseotherwise.fd::Function: Function with the signaturefd(h, data, i, j)in whichhis the highlighter. This function must return theMarkdownDecorationto 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 MarkdownDecoration that contains the decoration to be applied to the cell.
A markdown highlighter can be constructed using two helpers:
MarkdownHighlighter(f::Function, decoration::MarkdownDecoration)
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.
If only a single highlighter is wanted, it can be passed directly to the keyword highlighter without being inside a Tuple.
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.
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.
Formatters
The keyword formatters can be used to pass functions to format the values in the columns. It must be a tuple of functions 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. Thus, 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 a single function, meaning that only one formatter is available, or 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 * π : vIf multiple formatters are available, they will be applied in the same order as they are located in the tuple. Thus, for the following formatters:
formatters = (f1, f2, f3)each element v in the table (i-th row and j-th 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.pretty_table_with_conf — Methodpretty_table_with_conf(conf::PrettyTablesConf, args...; kwargs...) -> NothingCall pretty_table using the default configuration in conf. The args... and kwargs... can be the same as those passed to pretty_tables. Notice that all the configurations in kwargs... will overwrite the ones in conf.
The object conf can be created by the function set_pt_conf in which the keyword parameters can be any one supported by the function pretty_table as shown in the following.
PrettyTables.reset! — Methodreset!(c::CustomTextCell)Reset all fields in the custom text cell c.
This function is not required for the API. It is called before parsing the custom text cell.
PrettyTables.set_pt_conf! — Methodset_pt_conf!(conf; kwargs...) -> NothingApply the configurations in kwargs to the object conf.
PrettyTables.set_pt_conf — Methodset_pt_conf(; kwargs...) -> NothingCreate a new configuration object based on the arguments in kwargs.
PrettyTables.@html_cell_str — Macro@html_cell_str(str)Create a table cell with HTML code.
Examples
julia> html_cell"<i>Italic text</i>"
HtmlCell{String}("<i>Italic text</i>")PrettyTables.@latex_cell_str — Macro@latex_cell_str(str)Create a table cell with LaTeX code.
Examples
julia> latex_cell" extbf{Bold text}"
LatexCell{String}("\textbf{Bold text}")PrettyTables.@pt — Macro@pt(expr...)Pretty print tables in expr to stdout using the global configurations selected with the macro @ptconf.
Multiple tables can be printed by passing multiple expressions like:
@pt table1 table2 table3The user can select the table header by passing the expression:
:header = [<Vector with the header>]Notice that the header is valid only for the next printed table. Hence:
@pt :header = header1 table1 :header = header2 table2 table3will print table1 using header1, table2 using header2, and table3 using the default header.
When more than one table is passed to this macro, then multiple calls to pretty_table will occur. Hence, the cropping algorithm will behave exactly the same as printing the tables separately.
Examples
julia> @ptconf tf = tf_simple
julia> @pt :header = ["Time","Velocity"] [1:1:10 ones(10)] :header = ["Time","Position"] [1:1:10 1:1:10]
======= ===========
Time Velocity
======= ===========
1.0 1.0
2.0 1.0
3.0 1.0
4.0 1.0
5.0 1.0
6.0 1.0
7.0 1.0
8.0 1.0
9.0 1.0
10.0 1.0
======= ===========
======= ===========
Time Position
======= ===========
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
======= ===========
julia> @pt ones(3,3) + I + [1 2 3; 4 5 6; 7 8 9]
========= ======== =========
Col. 1 Col. 2 Col. 3
========= ======== =========
3.0 3.0 4.0
5.0 7.0 7.0
8.0 9.0 11.0
========= ======== =========PrettyTables.@ptconf — Macro@ptconf(expr...)Add configurations in expr to be used with the macro @pt.
The expression format must be:
keyword1 = value1 keyword2 = value2 ...in which the keywords can be any other possible keyword that can be used in the function pretty_table.
If a keyword is not supported by the function pretty_table, then no error message is printed when calling @ptconf. However, an error will be thrown when @pt is called.
PrettyTables.@ptconfclean — Macro@ptconfclean()Clean all global configurations to pretty print tables using the macro @pt.