gt-extras
  • Intro
  • API Reference
  1. Utilities
  2. gt_two_column_layout
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_bar_pct
    • gt_plt_bar_stack
    • gt_plt_conf_int
    • gt_plt_dot
    • gt_plt_dumbbell
    • gt_plt_winloss
  • Colors
    • gt_color_box
    • gt_data_color_by_group
    • gt_highlight_cols
    • gt_highlight_rows
    • gt_hulk_col_numeric
  • Themes
    • gt_theme_538
    • gt_theme_dark
    • gt_theme_dot_matrix
    • gt_theme_espn
    • gt_theme_excel
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_pff
  • Icons and Images
    • add_text_img
    • fa_icon_repeat
    • gt_fa_rank_change
    • gt_fa_rating
    • img_header
  • Utilities
    • fmt_pct_extra
    • gt_add_divider
    • gt_duplicate_column
    • gt_merge_stack
    • gt_two_column_layout
    • with_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Examples
  1. Utilities
  2. gt_two_column_layout

gt_two_column_layout

gt_two_column_layout(gt1, gt2, target=None, table_header_from=None)

Combine two GT objects into a two-column layout.

This function takes two GT objects and arranges them side by side in a single HTML output. Optionally, the header (title and subtitle) from one of the tables can be included at the top of the combined layout. The output can be displayed directly in a Jupyter notebook, opened in a browser, or returned as HTML.

Parameters

gt1 : GT

The first table to include in the layout. This table will appear on the left side.

gt2 : GT

The second table to include in the layout. This table will appear on the right side.

target : Literal['notebook', 'browser'] | None = None

Determines how the combined layout is displayed. Use "notebook" to display in a Jupyter notebook, "browser" to open in a web browser. If None, returns the layout object for automatic rendering. Currently, "save" is not yet implemented.

table_header_from : Literal[1, 2] | None = None

Determines which table’s header (title and subtitle) to include in the combined layout. If set to 1, the header from gt1 will be used. If set to 2, the header from gt2 will be used. If None, no header will be included.

Returns

: GTCombinedLayout

A layout object that automatically renders as HTML in Jupyter notebooks and Quarto documents.

Examples

from great_tables import GT
import gt_extras as gte
import pandas as pd

df1 = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
df2 = pd.DataFrame({"X": [7, 8, 9], "Y": [10, 11, 12]})

gt1 = GT(df1).tab_header(title="Table 1", subtitle="1st Table")
gt2 = GT(df2).tab_header(title="Table 2", subtitle="2nd Table")

gte.gt_two_column_layout(gt1, gt2)
Table 1
1st Table
A B
1 4
2 5
3 6
Table 2
2nd Table
X Y
7 10
8 11
9 12

Alternatively, we can combine data from the same table in a two column layout like so:

df1 = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
df2 = pd.DataFrame({"A": [7, 8, 9], "B": [10, 11, 12]})

gt1 = GT(df1).tab_header(title="Joined Table")
gt2 = GT(df2)

gte.gt_two_column_layout(gt1, gt2, table_header_from=1)
Joined Table
A B
1 4
2 5
3 6
A B
7 10
8 11
9 12
gt_merge_stack
with_hyperlink