> ## Documentation Index
> Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LaTeX Table Tutorial: tabular, table, booktabs, and siunitx

> Learn how to create a table in LaTeX with `tabular`, `table`, `booktabs`, `multicolumn`, `multirow`, and decimal alignment examples.

To create a table in LaTeX, start with a `tabular` environment, separate columns with `&`, and end each row with `\\`. Wrap that `tabular` block in a `table` environment when you need a caption, label, or float positioning. This guide starts with the basic LaTeX table syntax most people need first, then moves into `booktabs`, decimal alignment, and multi-column or multi-row layouts.

If you only need the fastest possible answer:

* Use `tabular` to build the rows and columns.
* Use `table` when you need a floating table with a caption and label.
* Use `booktabs` when you want journal-style horizontal rules.
* Use `siunitx` when numbers need to align at decimal points.

<Info>
  **Package required**: Basic tables work with the `tabular` environment. For professional tables, add `\usepackage{booktabs}`. For decimal alignment, use `\usepackage{siunitx}`.

  **Need the `tabular` syntax only?** Start with the focused [tabular environment guide](/learn/latex/tables/tabular).

  **Related topics**: [Mathematical matrices](/learn/latex/mathematics/matrices) | [Figure positioning](/learn/latex/figures/positioning) | [Cross-referencing tables](/learn/latex/cross-referencing)

  **Last updated**: April 2026 | **Reading time**: 25 min | **Difficulty**: Beginner to Advanced
</Info>

## What You'll Learn

* ✅ Basic table structure with `tabular` environment
* ✅ Column alignment and formatting options
* ✅ Professional tables with `booktabs` package
* ✅ Multi-column and multi-row cells
* ✅ Decimal alignment for numeric data
* ✅ Table captions and cross-references
* ✅ Advanced formatting techniques
* ✅ Troubleshooting common LaTeX table issues

## Frequently Asked Questions

<Accordion title="What is the difference between table and tabular in LaTeX?">
  The main difference between `table` and `tabular` in LaTeX is their **purpose**:

  * **tabular** is the actual table content - it creates the rows, columns, and cell data
  * **table** is a **float container** that wraps tabular for positioning, captions, and labels

  You typically nest `tabular` inside `table`:

  ```latex theme={null}
  \begin{table}[htbp]
    \centering
    \caption{My table caption}
    \label{tab:mytable}
    \begin{tabular}{lcc}
      Header 1 & Header 2 & Header 3 \\
      Data & Data & Data \\
    \end{tabular}
  \end{table}
  ```

  **When to use each:**

  * Use **tabular alone** for inline tables without captions
  * Use **table + tabular** when you need positioning control, captions, or cross-references
</Accordion>

<Accordion title="How do I align numbers at decimal points in LaTeX tables?">
  To **align decimal points** in LaTeX tables, use the `siunitx` package with the S-type column:

  ```latex theme={null}
  \usepackage{siunitx}
  \begin{tabular}{l S[table-format=3.2]}
  \hline
  Item & {Value} \\
  \hline
  Product A & 12.5 \\
  Product B & 123.45 \\
  Product C & 1.234 \\
  \hline
  \end{tabular}
  ```

  **How it works:**

  * `S[table-format=3.2]` means 3 digits before decimal, 2 after
  * Wrap text headers in `{braces}` to prevent siunitx parsing
  * Numbers automatically align at the decimal point

  This is essential for financial data, scientific measurements, and any numeric tables.
</Accordion>

<Accordion title="What is booktabs and why should I use it for LaTeX tables?">
  **booktabs** is a LaTeX package that provides professional-quality horizontal rules for tables:

  * `\toprule` - Thick line at table top
  * `\midrule` - Medium line between header and body
  * `\bottomrule` - Thick line at table bottom

  ```latex theme={null}
  \usepackage{booktabs}
  \begin{tabular}{lcc}
  \toprule
  Header 1 & Header 2 & Header 3 \\
  \midrule
  Data 1 & Data 2 & Data 3 \\
  Data 4 & Data 5 & Data 6 \\
  \bottomrule
  \end{tabular}
  ```

  **Why use booktabs:**

  * Better spacing around rules (no cramped rows)
  * Professional appearance matching journal standards
  * Avoids vertical lines (considered bad practice)
  * Required by many academic publishers (Nature, IEEE, etc.)
</Accordion>

<Accordion title="How do I make a cell span multiple columns in LaTeX?">
  Use `\multicolumn{n}{alignment}{text}` to span n columns:

  ```latex theme={null}
  \begin{tabular}{lcc}
  \hline
  \multicolumn{3}{c}{Spanning Three Columns} \\
  \hline
  Left & Center & Right \\
  \multicolumn{2}{l}{Spans two columns} & Right \\
  \hline
  \end{tabular}
  ```

  **Parameters:**

  * `{3}` - Number of columns to span
  * `{c}` - Alignment (l, c, r, or with borders like `|c|`)
  * `{text}` - Cell content

  **Common uses:**

  * Table titles spanning all columns
  * Grouped headers for related columns
  * Footnotes or notes spanning the table width
</Accordion>

<Accordion title="How do I make a cell span multiple rows in LaTeX?">
  Use the `multirow` package with `\multirow{n}{width}{text}`:

  ```latex theme={null}
  \usepackage{multirow}
  \begin{tabular}{lcc}
  \hline
  \multirow{2}{*}{Category} & Value 1 & 100 \\
                            & Value 2 & 200 \\
  \hline
  \multirow{3}{*}{Group A}  & Item 1  & 10 \\
                            & Item 2  & 20 \\
                            & Item 3  & 30 \\
  \hline
  \end{tabular}
  ```

  **Parameters:**

  * `{2}` or `{3}` - Number of rows to span
  * `{*}` - Auto width (or specify like `{3cm}`)
  * `{text}` - Cell content

  Leave the corresponding cells in subsequent rows empty (just use `&`).
</Accordion>

<Accordion title="How do I add colors to LaTeX table rows and cells?">
  Use the `xcolor` package with the `table` option:

  ```latex theme={null}
  \usepackage[table]{xcolor}

  % Color entire row
  \rowcolor{gray!20}
  Header 1 & Header 2 & Header 3 \\

  % Color single cell
  Normal & \cellcolor{yellow}Highlighted & Normal \\

  % Alternating row colors (zebra striping)
  \rowcolors{2}{white}{gray!10}
  \begin{tabular}{lcc}
  ...
  \end{tabular}
  ```

  **Color syntax:**

  * `gray!20` = 20% gray (lighter)
  * `red!50` = 50% red
  * `blue!10` = 10% blue (very light)
  * Standard colors: red, green, blue, yellow, cyan, magenta, black, white
</Accordion>

<Accordion title="How do I make a table fit the page width in LaTeX?">
  Use the `tabularx` package with the X column type:

  ```latex theme={null}
  \usepackage{tabularx}
  \begin{tabularx}{\textwidth}{lXr}
  \hline
  Fixed left & This column expands to fill space & Fixed right \\
  \hline
  \end{tabularx}
  ```

  **Options for wide tables:**

  1. **tabularx** with `X` columns - columns expand to fill `\textwidth`
  2. **Multiple X columns** - `{|X|X|X|}` distributes space equally
  3. **resizebox** - scales entire table: `\resizebox{\textwidth}{!}{\begin{tabular}...}`
  4. **Smaller font** - `{\small \begin{tabular}...}` or `\footnotesize`
  5. **Rotating** - `\usepackage{rotating}` with `sidewaystable` for landscape
</Accordion>

<Accordion title="How do I fix table positioning problems in LaTeX?">
  Control table positioning with float placement specifiers:

  ```latex theme={null}
  \begin{table}[htbp]  % Try here, top, bottom, page
  \begin{table}[H]     % Force exact position (requires float package)
  ```

  **Placement options:**

  * `h` - Here (approximately)
  * `t` - Top of page
  * `b` - Bottom of page
  * `p` - Page of floats only
  * `H` - HERE exactly (requires `\usepackage{float}`)
  * `!` - Override LaTeX's restrictions

  **Common issues and fixes:**

  * Table floats away: Use `[H]` with float package
  * Table at wrong page: Use `[t]` or adjust surrounding content
  * Too many floats: Use `\clearpage` to flush pending floats
  * Want inline table: Use `tabular` without `table` wrapper
</Accordion>

<Accordion title="How do I create a table that spans multiple pages in LaTeX?">
  Use the `longtable` package for tables that break across pages:

  ```latex theme={null}
  \usepackage{longtable}
  \usepackage{booktabs}

  \begin{longtable}{lcc}
  \caption{Multi-page table example} \\
  \toprule
  Header 1 & Header 2 & Header 3 \\
  \midrule
  \endfirsthead

  \multicolumn{3}{c}{\textit{Continued from previous page}} \\
  \toprule
  Header 1 & Header 2 & Header 3 \\
  \midrule
  \endhead

  \midrule
  \multicolumn{3}{r}{\textit{Continued on next page}} \\
  \endfoot

  \bottomrule
  \endlastfoot

  % Your data rows here
  Row 1 & Data & Data \\
  Row 2 & Data & Data \\
  % ... many more rows
  \end{longtable}
  ```

  **Key commands:**

  * `\endfirsthead` - Header for first page only
  * `\endhead` - Header for continuation pages
  * `\endfoot` - Footer for pages that continue
  * `\endlastfoot` - Footer for final page

  **Note:** Unlike `table`, `longtable` is NOT a float - it appears exactly where placed in your document.
</Accordion>

<Accordion title="How do I fix row spacing in LaTeX tables?">
  LaTeX table rows can appear cramped. Here are solutions:

  **Method 1: Adjust arraystretch (global)**

  ```latex theme={null}
  \renewcommand{\arraystretch}{1.3}  % 1.3x normal spacing
  \begin{tabular}{lcc}
  ...
  \end{tabular}
  ```

  **Method 2: Add struts (per-row control)**

  ```latex theme={null}
  \begin{tabular}{lcc}
  Header 1 & Header 2 & Header 3 \\[6pt]  % Extra space after this row
  Data 1 & Data 2 & Data 3 \\
  \end{tabular}
  ```

  **Method 3: Use booktabs (recommended)**

  ```latex theme={null}
  \usepackage{booktabs}
  \begin{tabular}{lcc}
  \toprule
  Header \\
  \midrule
  Data \\  % booktabs automatically adds proper spacing
  \bottomrule
  \end{tabular}
  ```

  **Method 4: cellspace package for consistent padding**

  ```latex theme={null}
  \usepackage{cellspace}
  \setlength{\cellspacetoplimit}{4pt}
  \setlength{\cellspacebottomlimit}{4pt}
  ```

  The `booktabs` package is generally the best solution as it handles spacing automatically with professional results.
</Accordion>

## Basic Table Structure

### Simple Tabular Environment

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex basic-table.tex theme={null}
      \documentclass{article}
      \begin{document}

      % Basic table without float
      \begin{tabular}{lcr}
      Left & Center & Right \\
      1 & 2 & 3 \\
      4 & 5 & 6
      \end{tabular}

      % With horizontal lines
      \begin{tabular}{|l|c|r|}
      \hline
      Name & Age & Score \\
      \hline
      Alice & 25 & 95 \\
      Bob & 30 & 87 \\
      Carol & 28 & 92 \\
      \hline
      \end{tabular}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    **Basic table without float** - A simple 3x3 table demonstrating column alignment:

    | Left | Center | Right |
    | :--- | :----: | ----: |
    | 1    |    2   |     3 |
    | 4    |    5   |     6 |

    * Column 1 (`l`): Text aligns to the left
    * Column 2 (`c`): Text centers in the column
    * Column 3 (`r`): Text aligns to the right

    **Table with horizontal and vertical lines** - A bordered table with header row:

    | Name  | Age | Score |
    | :---- | :-: | ----: |
    | Alice |  25 |    95 |
    | Bob   |  30 |    87 |
    | Carol |  28 |    92 |

    * `\hline`: Creates horizontal lines above and below rows
    * `|` in column spec: Creates vertical lines between columns
    * `{|l|c|r|}`: Left, center, right columns with vertical separators
  </Tab>
</Tabs>

### Column Specifications

| Specifier  | Alignment | Description                       |               |
| ---------- | --------- | --------------------------------- | ------------- |
| `l`        | Left      | Left-aligned column               |               |
| `c`        | Center    | Centered column                   |               |
| `r`        | Right     | Right-aligned column              |               |
| `p{width}` | Justified | Paragraph column with fixed width |               |
| \`         | \`        | —                                 | Vertical line |
| `@{...}`   | —         | Custom column separator           |               |

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex column-types.tex theme={null}
      % Various column types
      \begin{tabular}{lcrp{3cm}}
      Left & Center & Right & Paragraph text that wraps \\
      \end{tabular}

      % Custom spacing
      \begin{tabular}{l@{\hspace{2cm}}r}
      Name & Value \\
      \end{tabular}

      % Remove default spacing
      \begin{tabular}{@{}lcr@{}}
      No space & on & sides \\
      \end{tabular}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    **Paragraph column with text wrapping** - The `p{3cm}` column type creates a fixed-width paragraph column:

    | Left | Center | Right | Paragraph column                                     |
    | :--- | :----: | ----: | :--------------------------------------------------- |
    | Left | Center | Right | Paragraph text that wraps within the specified width |

    The fourth column (`p{3cm}`) automatically wraps text to fit within 3cm width.

    **Custom spacing between columns** - Using `@{\hspace{2cm}}` creates 2cm spacing between columns:

    | Name | Value |
    | :--- | ----: |
    | Name | Value |

    The `@{...}` specifier replaces default column padding with custom content (here, 2cm of horizontal space).

    **No default spacing** - Using `@{}lcr@{}` removes padding from table edges:

    | No space |  on | sides |
    | :------- | :-: | ----: |
    | No space |  on | sides |

    The `@{}` at the start and end removes the default padding LaTeX adds to table edges, making the table content flush with the margins.
  </Tab>
</Tabs>

## Table Float Environment

### Basic Table with Caption

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex table-float.tex theme={null}
      \documentclass{article}
      \usepackage{caption}
      \begin{document}

      \begin{table}[htbp]
        \centering
        \caption{Student grades}
        \label{tab:grades}
        \begin{tabular}{lcc}
          \hline
          Student & Midterm & Final \\
          \hline
          Alice & 85 & 92 \\
          Bob & 78 & 88 \\
          Carol & 92 & 95 \\
          \hline
        \end{tabular}
      \end{table}

      As shown in Table \ref{tab:grades}, all students improved.

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    **Table 1: Student grades** - A captioned table with cross-reference capability:

    | Student | Midterm | Final |
    | :------ | :-----: | :---: |
    | Alice   |    85   |   92  |
    | Bob     |    78   |   88  |
    | Carol   |    92   |   95  |

    As shown in Table 1, all students improved.

    * `\caption{}`: Adds a numbered caption above the table
    * `\label{}`: Creates a reference label for cross-referencing
    * `\centering`: Centers the table within the page
    * `[htbp]`: Float placement options (here, top, bottom, page)
  </Tab>
</Tabs>

### Table Positioning

<CodeGroup>
  ```latex table-positioning.tex theme={null}
  % Positioning options
  \begin{table}[h]    % Here
  \begin{table}[t]    % Top of page
  \begin{table}[b]    % Bottom of page
  \begin{table}[p]    % Page of floats
  \begin{table}[htbp] % Try here, top, bottom, page

  % Force exact placement
  \usepackage{float}
  \begin{table}[H]    % HERE exactly
  ```
</CodeGroup>

## Lines and Rules

### Horizontal Lines

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex horizontal-lines.tex theme={null}
      \documentclass{article}
      \usepackage{booktabs} % For professional tables
      \begin{document}

      % Basic lines
      \begin{tabular}{lcc}
      \hline
      Header 1 & Header 2 & Header 3 \\
      \hline
      Data 1 & Data 2 & Data 3 \\
      \hline
      \end{tabular}

      % Professional tables with booktabs
      \begin{tabular}{lcc}
      \toprule
      Header 1 & Header 2 & Header 3 \\
      \midrule
      Data 1 & Data 2 & Data 3 \\
      Data 4 & Data 5 & Data 6 \\
      \bottomrule
      \end{tabular}

      % Partial horizontal lines
      \begin{tabular}{lcr}
      Full line \\
      \hline
      Partial & line & below \\
      \cline{2-3}
      Only & under & these \\
      \end{tabular}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Basic lines with `\hline`** - Standard horizontal rules:

      | Header 1 | Header 2 | Header 3 |
      | :------- | :------: | :------: |
      | Data 1   |  Data 2  |  Data 3  |

      Uses `\hline` to create uniform horizontal lines above and below rows.
    </Card>

    <Card title="Rendered output" icon="eye">
      **Professional tables with `booktabs`** - Enhanced horizontal rules with varying weights:

      | Header 1 | Header 2 | Header 3 |
      | :------- | :------: | :------: |
      | Data 1   |  Data 2  |  Data 3  |
      | Data 4   |  Data 5  |  Data 6  |

      The `booktabs` package provides:

      * `\toprule`: Thick top rule
      * `\midrule`: Medium rule between header and body
      * `\bottomrule`: Thick bottom rule
      * Improved spacing around rules
    </Card>

    <Card title="Rendered output" icon="eye">
      **Partial horizontal lines with `\cline{2-3}`** - Selective horizontal rules:

      The table structure shows:

      * Row 1: "Full line" (with full `\hline` below)
      * Row 2: "Partial | line | below" (with `\cline{2-3}` below - line only under columns 2-3)
      * Row 3: "Only | under | these"

      `\cline{2-3}` draws a line only under columns 2 and 3, leaving column 1 without a line below.
    </Card>
  </Tab>
</Tabs>

<Tip>
  **Best practice**: Use the `booktabs` package for professional-looking tables. It provides better spacing and line weights than standard LaTeX rules.
</Tip>

### Vertical Lines

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex vertical-lines.tex theme={null}
      % Single vertical lines
      \begin{tabular}{l|c|r}
      Left & Center & Right \\
      \end{tabular}

      % Double vertical lines
      \begin{tabular}{l||c||r}
      Left & Center & Right \\
      \end{tabular}

      % Mixed lines
      \begin{tabular}{|l|c|r|}
      \hline
      A & B & C \\
      \hline
      1 & 2 & 3 \\
      \hline
      \end{tabular}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Tables with vertical lines** - Three variations:

      **Single vertical lines** (`l|c|r`):
      \| Left | Center | Right |

      **Double vertical lines** (`l||c||r`):
      \| Left || Center || Right |

      **Full grid with borders** (`|l|c|r|` + `\hline`):

      | A | B | C |
      | - | - | - |
      | 1 | 2 | 3 |

      Vertical lines are created using `|` in the column specification.
    </Card>
  </Tab>
</Tabs>

<Warning>
  **Note**: Vertical lines are generally discouraged in professional tables. They can make tables look cluttered and harder to read.
</Warning>

## Column Formatting

### Text Alignment and Width

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex column-formatting.tex theme={null}
      \documentclass{article}
      \usepackage{array} % Enhanced column types
      \begin{document}

      % Fixed width columns
      \begin{tabular}{p{3cm}p{3cm}p{3cm}}
      This is a paragraph column & 
      Text wraps automatically & 
      Within the specified width \\
      \end{tabular}

      % Array package column types
      \begin{tabular}{>{\bfseries}l c >{\itshape}r}
      Bold & Normal & Italic \\
      Left & Center & Right \\
      \end{tabular}

      % Centered fixed-width columns
      \usepackage{array}
      \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
      \begin{tabular}{C{3cm}C{3cm}}
      Centered & Fixed Width \\
      \end{tabular}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Array package column formatting** - Automatic styling applied to columns:

      | **Bold** | Normal | *Italic* |
      | :------- | :----: | -------: |
      | **Left** | Center |  *Right* |

      Using `>{\bfseries}l` makes the first column bold, and `>{\itshape}r` makes the last column italic.
    </Card>

    <Card title="Rendered output" icon="eye">
      **Custom centered fixed-width columns** - Using a custom column type:

      | Centered | Fixed Width |
      | :------: | :---------: |
      |  Content |   Content   |

      The custom `C` column type combines `p{width}` with `\centering` for centered, fixed-width columns.
    </Card>
  </Tab>
</Tabs>

### Multi-column Cells

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex multicolumn.tex theme={null}
      \begin{tabular}{lcr}
      \hline
      \multicolumn{3}{c}{Spanning Three Columns} \\
      \hline
      Left & Center & Right \\
      A & B & C \\
      \multicolumn{2}{l}{Span two} & Right \\
      \hline
      \end{tabular}

      % Complex headers
      \begin{tabular}{lcc}
      \hline
      \multicolumn{1}{c}{Item} & 
      \multicolumn{2}{c}{Measurements} \\
      \cline{2-3}
      & Length & Width \\
      \hline
      Box A & 10 cm & 5 cm \\
      Box B & 15 cm & 8 cm \\
      \hline
      \end{tabular}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Multi-column spanning** - Using `\multicolumn` to span cells:

      | Spanning Three Columns |        |       |
      | :--------------------- | :----: | ----: |
      | Left                   | Center | Right |
      | A                      |    B   |     C |
      | Span two               |        | Right |

      * `\multicolumn{3}{c}{text}` spans 3 columns, centered
      * `\multicolumn{2}{l}{text}` spans 2 columns, left-aligned
    </Card>

    <Card title="Rendered output" icon="eye">
      **Complex headers with partial lines** - Hierarchical column headers:

      | Item  | Measurements |       |
      | :---- | :----------: | :---: |
      |       |    Length    | Width |
      | Box A |     10 cm    |  5 cm |
      | Box B |     15 cm    |  8 cm |

      The header "Measurements" spans two columns using `\multicolumn{2}{c}{Measurements}`, with `\cline{2-3}` creating a partial line under only the spanned columns.
    </Card>
  </Tab>
</Tabs>

### Multi-row Cells

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex multirow.tex theme={null}
      \documentclass{article}
      \usepackage{multirow}
      \begin{document}

      \begin{tabular}{lcc}
      \hline
      \multirow{2}{*}{Category} & Value 1 & Value 2 \\
      & 10 & 20 \\
      \hline
      \multirow{3}{*}{Group A} & Item 1 & 100 \\
      & Item 2 & 200 \\
      & Item 3 & 300 \\
      \hline
      \end{tabular}

      % With width specification
      \begin{tabular}{lp{3cm}c}
      \hline
      \multirow{2}{3cm}{Long text that needs wrapping} & 
      Description & Value \\
      & More info & 42 \\
      \hline
      \end{tabular}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Multi-row cells example** - Using `\multirow` to span rows:

      The table shows:

      * "Category" spans 2 rows vertically (with values 10, 20 in the adjacent cells)
      * "Group A" spans 3 rows vertically (with Items 1-3 and values 100-300)

      | Category       | Value 1 | Value 2 |
      | :------------- | :-----: | :-----: |
      | (spans 2 rows) |    10   |    20   |
      | Group A        |  Item 1 |   100   |
      | (spans 3 rows) |  Item 2 |   200   |
      |                |  Item 3 |   300   |

      `\multirow{n}{*}{text}` makes a cell span n rows, with `*` for automatic width.
    </Card>
  </Tab>
</Tabs>

## Numeric Alignment

### Decimal Alignment

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex decimal-alignment.tex theme={null}
      \documentclass{article}
      \usepackage{siunitx} % For numeric alignment
      \begin{document}

      % Using siunitx S column
      \begin{tabular}{l S[table-format=3.2]}
      \hline
      Item & {Value} \\
      \hline
      Product A & 12.5 \\
      Product B & 123.45 \\
      Product C & 1.234 \\
      \hline
      \end{tabular}

      % Multiple numeric columns
      \begin{tabular}{l *{3}{S[table-format=2.1]}}
      \hline
      Test & {Run 1} & {Run 2} & {Run 3} \\
      \hline
      A & 9.5 & 10.2 & 9.8 \\
      B & 12.1 & 11.9 & 12.3 \\
      C & 8.7 & 8.9 & 8.8 \\
      \hline
      \end{tabular}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Decimal alignment with siunitx** - The S column type aligns numbers at the decimal point:

      | Item      |  Value |
      | :-------- | -----: |
      | Product A |   12.5 |
      | Product B | 123.45 |
      | Product C |  1.234 |

      Notice how decimal points align vertically. The `S[table-format=3.2]` specifies 3 digits before and 2 after the decimal.
    </Card>

    <Card title="Rendered output" icon="eye">
      **Multiple numeric columns** - Using `*{3}{S[table-format=2.1]}` to repeat column specs:

      | Test | Run 1 | Run 2 | Run 3 |
      | :--- | ----: | ----: | ----: |
      | A    |   9.5 |  10.2 |   9.8 |
      | B    |  12.1 |  11.9 |  12.3 |
      | C    |   8.7 |   8.9 |   8.8 |

      The `*{3}{S[...]}` syntax repeats the S column specification 3 times.
    </Card>
  </Tab>
</Tabs>

### Currency and Units

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex currency-units.tex theme={null}
      \usepackage{siunitx}

      % Currency alignment
      \begin{tabular}{l S[table-format=4.2, table-space-text-pre=\$]}
      \hline
      Item & {Price} \\
      \hline
      Laptop & \$1299.99 \\
      Mouse & \$29.95 \\
      Keyboard & \$89.50 \\
      \hline
      Total & \$1419.44 \\
      \hline
      \end{tabular}

      % Units in headers
      \begin{tabular}{l S[table-format=3.1]}
      \hline
      Material & {Density (\si{g/cm^3})} \\
      \hline
      Water & 1.0 \\
      Iron & 7.9 \\
      Gold & 19.3 \\
      \hline
      \end{tabular}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Currency alignment with dollar signs** - Prices aligned at the decimal point:

      | Item      |         Price |
      | :-------- | ------------: |
      | Laptop    |     \$1299.99 |
      | Mouse     |       \$29.95 |
      | Keyboard  |       \$89.50 |
      | **Total** | **\$1419.44** |

      The `table-space-text-pre=\$` option reserves space for the dollar sign while maintaining decimal alignment.
    </Card>

    <Card title="Rendered output" icon="eye">
      **Scientific units in headers** - Using `\si{}` for proper unit formatting:

      | Material | Density (g/cm^3) |
      | :------- | ---------------: |
      | Water    |              1.0 |
      | Iron     |              7.9 |
      | Gold     |             19.3 |

      The `\si{g/cm^3}` command from siunitx properly formats scientific units with correct spacing and superscripts.
    </Card>
  </Tab>
</Tabs>

## Coloring Tables

### Row and Cell Colors

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex colored-tables.tex theme={null}
      \documentclass{article}
      \usepackage[table]{xcolor}
      \begin{document}

      % Alternating row colors
      \begin{tabular}{lcc}
      \rowcolor{gray!20}
      Header 1 & Header 2 & Header 3 \\
      Row 1 & Data & Data \\
      \rowcolor{gray!10}
      Row 2 & Data & Data \\
      Row 3 & Data & Data \\
      \rowcolor{gray!10}
      Row 4 & Data & Data \\
      \end{tabular}

      % Individual cell colors
      \begin{tabular}{lcc}
      \hline
      Normal & \cellcolor{yellow}Highlighted & Normal \\
      \cellcolor{red!20}Light red & Normal & \cellcolor{blue!20}Light blue \\
      \hline
      \end{tabular}

      % Column colors
      \begin{tabular}{>{\columncolor{gray!20}}l cc}
      Gray column & Normal & Normal \\
      \end{tabular}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Alternating row colors** - Using `\rowcolor` for zebra striping:

      The table displays:

      * Header row with gray background (gray!20)
      * Alternating white and light gray (gray!10) rows

      | Header 1       | Header 2 | Header 3 |
      | :------------- | :------: | :------: |
      | Row 1          |   Data   |   Data   |
      | Row 2 (shaded) |   Data   |   Data   |
      | Row 3          |   Data   |   Data   |
      | Row 4 (shaded) |   Data   |   Data   |

      Use `\rowcolor{gray!20}` before a row to apply a background color.
    </Card>

    <Card title="Rendered output" icon="eye">
      **Individual cell coloring** - Using `\cellcolor` for specific cells:

      | Normal    | Highlighted (yellow) | Normal     |
      | :-------- | :------------------: | :--------- |
      | Light red |        Normal        | Light blue |

      * `\cellcolor{yellow}` highlights a single cell in yellow
      * `\cellcolor{red!20}` creates a light red (20% red)
      * `\cellcolor{blue!20}` creates a light blue (20% blue)
    </Card>
  </Tab>
</Tabs>

### Professional Striped Tables

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex striped-tables.tex theme={null}
      \usepackage[table]{xcolor}
      \usepackage{booktabs}

      % Define alternating colors
      \rowcolors{2}{white}{gray!10}

      \begin{tabular}{lcc}
      \toprule
      \rowcolor{gray!40}
      Product & Quantity & Price \\
      \midrule
      Apples & 10 & \$5.00 \\
      Oranges & 15 & \$7.50 \\
      Bananas & 20 & \$4.00 \\
      Grapes & 5 & \$6.00 \\
      \bottomrule
      \end{tabular}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Professional striped table with booktabs** - Combining zebra stripes with professional rules:

      | Product          | Quantity |  Price |
      | :--------------- | :------: | -----: |
      | Apples           |    10    | \$5.00 |
      | Oranges (shaded) |    15    | \$7.50 |
      | Bananas          |    20    | \$4.00 |
      | Grapes (shaded)  |     5    | \$6.00 |

      Using `\rowcolors{2}{white}{gray!10}` automatically alternates row colors starting from row 2. Combined with booktabs rules for a professional appearance.
    </Card>
  </Tab>
</Tabs>

## Table Width Control

### Full Width Tables

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex full-width-tables.tex theme={null}
      \documentclass{article}
      \usepackage{tabularx}
      \begin{document}

      % Using tabularx
      \begin{tabularx}{\textwidth}{lXr}
      \hline
      Left & Expanding middle column & Right \\
      \hline
      A & This column expands to fill available space & 100 \\
      B & Automatically adjusts width & 200 \\
      \hline
      \end{tabularx}

      % Multiple X columns
      \begin{tabularx}{\textwidth}{|X|X|X|}
      \hline
      Equal & Width & Columns \\
      \hline
      These three columns & share the available & space equally \\
      \hline
      \end{tabularx}

      % Custom width distribution
      \begin{tabularx}{\textwidth}{l>{\hsize=.5\hsize}X>{\hsize=1.5\hsize}Xr}
      Fixed & Narrow & Wide expanding column & Fixed \\
      \end{tabularx}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Full-width table with expanding column** - Using tabularx with X columns:

      | Left | Expanding middle column                     | Right |
      | :--- | :------------------------------------------ | ----: |
      | A    | This column expands to fill available space |   100 |
      | B    | Automatically adjusts width                 |   200 |

      The `X` column type in `tabularx` automatically expands to fill available width while maintaining fixed-width columns for `l` and `r` types.
    </Card>

    <Card title="Rendered output" icon="eye">
      **Equal width columns spanning full width** - Multiple X columns share space equally:

      |        Equal        |        Width        |    Columns    |
      | :-----------------: | :-----------------: | :-----------: |
      | These three columns | share the available | space equally |

      Using `{|X|X|X|}` creates three columns that each take up 1/3 of the available width.
    </Card>
  </Tab>
</Tabs>

### Resizing Tables

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex resizing-tables.tex theme={null}
      \usepackage{graphicx}

      % Scale to specific width
      \resizebox{\textwidth}{!}{%
      \begin{tabular}{lcccccc}
      \hline
      Many & Columns & That & Would & Be & Too & Wide \\
      \hline
      Data & Data & Data & Data & Data & Data & Data \\
      \hline
      \end{tabular}
      }

      % Scale to fit column width
      \resizebox{\columnwidth}{!}{%
      \begin{tabular}{lcr}
      % Table content
      \end{tabular}
      }

      % Scale by percentage
      \scalebox{0.8}{%
      \begin{tabular}{lcr}
      % 80% of original size
      \end{tabular}
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Table resized to fit text width** - Using `\resizebox{\textwidth}{!}{}`:

      | Many | Columns | That | Would |  Be  |  Too | Wide |
      | :--: | :-----: | :--: | :---: | :--: | :--: | :--: |
      | Data |   Data  | Data |  Data | Data | Data | Data |

      The `\resizebox{\textwidth}{!}{...}` command scales the entire table (including text) to fit within the text width. Note that this may make text smaller than desired for very wide tables.
    </Card>

    <Card title="Rendered output" icon="eye">
      **Table scaled to 80%** - Using `\scalebox{0.8}{}`:

      | Left                             | Center | Right |
      | :------------------------------- | :----: | ----: |
      | (scaled to 80% of original size) |        |       |

      The `\scalebox{0.8}{...}` command scales the table to 80% of its original size while maintaining aspect ratio. Useful for making tables slightly smaller without reflowing content.
    </Card>
  </Tab>
</Tabs>

## Table Design Principles

### Professional Table Design Guidelines

Creating professional tables in LaTeX requires attention to both technical implementation and design principles. Here are the key guidelines that will elevate your table design:

<CardGroup cols={2}>
  <Card title="Clarity First" icon="eye" color="#FF6037">
    Tables should communicate data clearly. Avoid unnecessary decorations that distract from the content.
  </Card>

  <Card title="Consistent Formatting" icon="palette" color="#FF6037">
    Use consistent number formats, alignment, and styling throughout your document.
  </Card>

  <Card title="Appropriate Spacing" icon="arrows-alt-v" color="#FF6037">
    Proper spacing makes tables more readable. Use `\arraystretch` or booktabs for better spacing.
  </Card>

  <Card title="Meaningful Headers" icon="heading" color="#FF6037">
    Clear, descriptive headers help readers understand your data structure immediately.
  </Card>
</CardGroup>

### When to Use Tables vs Other Formats

Not all data belongs in a table. Consider these alternatives:

| Data Type                 | Best Format   | When to Use                                                  |
| ------------------------- | ------------- | ------------------------------------------------------------ |
| **Few data points**       | Inline text   | When you have 2-3 values that can be mentioned in a sentence |
| **Trends over time**      | Line graph    | When showing how values change over a continuous variable    |
| **Proportions**           | Pie/bar chart | When showing parts of a whole or comparing categories        |
| **Complex relationships** | Diagram       | When showing connections or flow between elements            |
| **Structured lists**      | Tables        | When comparing multiple attributes across items              |

## Advanced Table Techniques

### Creating Publication-Quality Tables

Professional journals often have specific requirements for tables. Here's how to meet common standards:

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex publication-table.tex theme={null}
      \documentclass{article}
      \usepackage{booktabs}
      \usepackage{siunitx}
      \usepackage{threeparttable}
      \usepackage[font=small,labelfont=bf]{caption}

      \begin{document}

      \begin{table}[htbp]
      \centering
      \small % Reduce font size for journal requirements
      \caption{Comparison of experimental results across different conditions}
      \label{tab:results}
      \begin{threeparttable}
      \begin{tabular}{@{}lS[table-format=3.1]S[table-format=2.1]S[table-format=1.3]@{}}
      \toprule
      Condition & {Temperature (\si{\celsius})} & {Time (h)} & {Yield} \\
      \midrule
      Control\tnote{a} & 25.0 & 2.0 & 0.850 \\
      Optimized\tnote{b} & 35.5 & 1.5 & 0.923 \\
      Modified & 30.2 & 1.8 & 0.891 \\
      \bottomrule
      \end{tabular}
      \begin{tablenotes}
      \footnotesize
      \item[a] Standard laboratory conditions
      \item[b] Conditions optimized through preliminary experiments
      \end{tablenotes}
      \end{threeparttable}
      \end{table}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Table 1: Comparison of experimental results across different conditions**

      | Condition   | Temperature (C) | Time (h) | Yield |
      | :---------- | --------------: | -------: | ----: |
      | Control^a   |            25.0 |      2.0 | 0.850 |
      | Optimized^b |            35.5 |      1.5 | 0.923 |
      | Modified    |            30.2 |      1.8 | 0.891 |

      Notes:

      * ^a Standard laboratory conditions
      * ^b Conditions optimized through preliminary experiments

      This publication-quality table uses `threeparttable` for proper footnotes, `siunitx` for number alignment, and `booktabs` for professional rules.
    </Card>
  </Tab>
</Tabs>

### Dynamic Table Generation from External Data

For reproducible research, generating tables from data files is essential:

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex csv-table.tex theme={null}
      \documentclass{article}
      \usepackage{pgfplotstable}
      \usepackage{booktabs}
      \usepackage{filecontents}

      % Create sample data file
      \begin{filecontents*}{data.csv}
      Sample,Temperature,Pressure,Result
      A,25.3,101.2,Pass
      B,26.1,102.5,Pass
      C,24.8,99.8,Fail
      D,25.7,101.9,Pass
      \end{filecontents*}

      \begin{document}

      % Basic CSV import
      \pgfplotstabletypeset[
        col sep=comma,
        string type,
        every head row/.style={
          before row=\toprule,
          after row=\midrule
        },
        every last row/.style={
          after row=\bottomrule
        }
      ]{data.csv}

      % Advanced formatting
      \pgfplotstabletypeset[
        col sep=comma,
        string type,
        columns={Sample,Temperature,Result}, % Select specific columns
        column type/.add={}{}, % Clear default column types
        columns/Sample/.style={column name=\textbf{Sample ID}},
        columns/Temperature/.style={
          column name=\textbf{Temp. (\si{\celsius})},
          fixed,
          precision=1
        },
        columns/Result/.style={
          column name=\textbf{Status},
          postproc cell content/.code={
            \ifstrequal{##1}{Pass}
              {\pgfkeysalso{@cell content=\textcolor{green!60!black}{##1}}}
              {\pgfkeysalso{@cell content=\textcolor{red!60!black}{##1}}}
          }
        }
      ]{data.csv}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Basic CSV import** - Using `pgfplotstabletypeset` to read data.csv:

      | Sample | Temperature | Pressure | Result |
      | :----- | ----------: | -------: | :----- |
      | A      |        25.3 |    101.2 | Pass   |
      | B      |        26.1 |    102.5 | Pass   |
      | C      |        24.8 |     99.8 | Fail   |
      | D      |        25.7 |    101.9 | Pass   |

      The `pgfplotstable` package automatically reads CSV files and formats them as tables with booktabs rules.
    </Card>

    <Card title="Rendered output" icon="eye">
      **Advanced formatting with column selection and styling:**

      | **Sample ID** | **Temp. (C)** |  **Status**  |
      | :------------ | ------------: | :----------: |
      | A             |          25.3 | Pass (green) |
      | B             |          26.1 | Pass (green) |
      | C             |          24.8 |  Fail (red)  |
      | D             |          25.7 | Pass (green) |

      This example shows column renaming, selective column display, and conditional formatting (green for Pass, red for Fail) using `postproc cell content`.
    </Card>
  </Tab>
</Tabs>

## Accessibility in Tables

### Making Tables Screen-Reader Friendly

While LaTeX primarily produces PDF output, considering accessibility improves document usability:

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex accessible-table.tex theme={null}
      \documentclass{article}
      \usepackage{booktabs}
      \usepackage{array}

      % Define column type for headers
      \newcolumntype{H}{>{\bfseries}l}

      \begin{document}

      % Use semantic markup
      \begin{table}[htbp]
      \caption{Student enrollment by department and year}
      \label{tab:enrollment}
      \centering
      \begin{tabular}{H*{4}{r}}
      \toprule
      Department & \textbf{2021} & \textbf{2022} & \textbf{2023} \\
      \midrule
      Computer Science & 245 & 289 & 312 \\
      Mathematics & 156 & 162 & 171 \\
      Physics & 98 & 103 & 99 \\
      Chemistry & 134 & 141 & 139 \\
      \midrule
      \textbf{Total} & \textbf{633} & \textbf{695} & \textbf{721} \\
      \bottomrule
      \end{tabular}
      \end{table}

      % Alternative text description
      \begin{quote}
      \textit{Table description: This table shows student enrollment numbers across four science departments from 2021 to 2023, with totals for each year. Overall enrollment increased from 633 to 721 students.}
      \end{quote}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Table: Student enrollment by department and year**

      | **Department**   | **2021** | **2022** | **2023** |
      | :--------------- | -------: | -------: | -------: |
      | Computer Science |      245 |      289 |      312 |
      | Mathematics      |      156 |      162 |      171 |
      | Physics          |       98 |      103 |       99 |
      | Chemistry        |      134 |      141 |      139 |
      | **Total**        |  **633** |  **695** |  **721** |

      *Table description: This table shows student enrollment numbers across four science departments from 2021 to 2023, with totals for each year. Overall enrollment increased from 633 to 721 students.*

      Adding a text description below the table improves accessibility for screen readers.
    </Card>
  </Tab>
</Tabs>

## Troubleshooting Complex Tables

### Common Table Problems and Solutions

<Accordion title="Table extends beyond page margins">
  **Problem**: Your table is too wide for the page.

  **Solutions**:

  1. Use `\small` or `\footnotesize` to reduce font size
  2. Use `tabularx` to automatically adjust column widths
  3. Rotate the table with `rotating` package
  4. Use `\resizebox` (last resort - can make text too small)

  ```latex theme={null}
  % Option 1: Reduce font size
  {\small
  \begin{tabular}{llllll}
  % Table content
  \end{tabular}
  }

  % Option 2: Use tabularx
  \begin{tabularx}{\textwidth}{l*{5}{X}}
  % Content automatically fits page width
  \end{tabularx}
  ```
</Accordion>

<Accordion title="Decimal points don't align">
  **Problem**: Numbers in columns don't align at decimal points.

  **Solution**: Use the `siunitx` package with S-type columns:

  ```latex theme={null}
  \usepackage{siunitx}
  \begin{tabular}{l S[table-format=3.2]}
  Item & {Value} \\
  \hline
  Product A & 12.5 \\
  Product B & 123.45 \\
  Product C & 1.234 \\
  \end{tabular}
  ```
</Accordion>

<Accordion title="Table numbering is wrong">
  **Problem**: Tables are numbered incorrectly or out of sequence.

  **Solutions**:

  1. Check for manual `\setcounter` commands
  2. Ensure proper placement of `\caption`
  3. Use `\numberwithin{table}{section}` for section-based numbering

  ```latex theme={null}
  % Reset numbering by section
  \usepackage{amsmath}
  \numberwithin{table}{section}

  % Manual adjustment if needed
  \setcounter{table}{0}
  ```
</Accordion>

## Performance Optimization for Large Tables

### Handling Tables with Thousands of Rows

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex large-dataset.tex theme={null}
      \documentclass{article}
      \usepackage{longtable}
      \usepackage{array}

      % Optimize compilation for large tables
      \usepackage{etoolbox}
      \AtBeginEnvironment{longtable}{\small}

      \begin{document}

      % For very large datasets, consider:
      % 1. External processing
      % 2. Pagination
      % 3. Summary tables

      \begin{longtable}{@{}lrrr@{}}
      \caption{Large dataset with automatic page breaks} \\
      \toprule
      ID & Value A & Value B & Result \\
      \midrule
      \endfirsthead

      \multicolumn{4}{c}{\tablename\ \thetable\ -- \textit{Continued}} \\
      \toprule
      ID & Value A & Value B & Result \\
      \midrule
      \endhead

      \midrule
      \multicolumn{4}{r}{\textit{Continued on next page}} \\
      \endfoot

      \bottomrule
      \endlastfoot

      % Generate sample data
      \newcount\rowcount
      \rowcount=1
      \loop
        \the\rowcount & \number\numexpr\rowcount*2\relax & 
        \number\numexpr\rowcount*3\relax & 
        \number\numexpr\rowcount*5\relax \\
        \advance\rowcount by 1
      \ifnum\rowcount<100 \repeat

      \end{longtable}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Table: Large dataset with automatic page breaks**

      | ID                       | Value A | Value B | Result |
      | :----------------------- | ------: | ------: | -----: |
      | 1                        |       2 |       3 |      5 |
      | 2                        |       4 |       6 |     10 |
      | 3                        |       6 |       9 |     15 |
      | 4                        |       8 |      12 |     20 |
      | 5                        |      10 |      15 |     25 |
      | ...                      |     ... |     ... |    ... |
      | *Continued on next page* |         |         |        |

      The `longtable` environment automatically:

      * Handles page breaks within the table
      * Repeats headers on each new page (`\endhead`)
      * Shows "Continued" message at page breaks (`\endfoot`)
      * Displays different footer on last page (`\endlastfoot`)
    </Card>
  </Tab>
</Tabs>

## Best Practices

<Tip>
  **Table design guidelines:**

  1. **Simplicity**: Less is more - avoid excessive lines and decoration
  2. **Alignment**: Right-align numbers, left-align text
  3. **Spacing**: Use adequate white space for readability
  4. **Captions**: Place captions above tables (convention)
  5. **Consistency**: Use the same style throughout your document
  6. **Booktabs**: Use `\toprule`, `\midrule`, `\bottomrule` for professional appearance
  7. **Width**: Avoid tables wider than text width
</Tip>

## Common Issues and Solutions

<Warning>
  **Troubleshooting tables:**

  1. **Table too wide**: Use `tabularx`, `\small`, or rotate the table
  2. **Text not wrapping**: Use `p{width}` columns instead of `l`, `c`, or `r`
  3. **Vertical alignment**: Use `[t]`, `[c]`, or `[b]` with `p` columns
  4. **Missing package errors**: Load required packages (`array`, `booktabs`, etc.)
  5. **Spacing issues**: Adjust `\arraystretch` or use `\renewcommand{\arraystretch}{1.2}`
</Warning>

## Comparison with Other Table Tools

### LaTeX Tables vs Word/Excel Tables

Understanding when to use LaTeX tables versus other tools:

| Feature             | LaTeX         | Word    | Excel                 |
| ------------------- | ------------- | ------- | --------------------- |
| **Precision**       | Exact control | Limited | Good for calculations |
| **Consistency**     | Excellent     | Manual  | Good within sheet     |
| **Math support**    | Native        | Limited | Basic                 |
| **Automation**      | Scriptable    | Limited | VBA/Macros            |
| **Version control** | Text-based    | Binary  | Binary                |
| **Learning curve**  | Steep         | Gentle  | Moderate              |

### Converting Tables Between Formats

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex excel-to-latex.tex theme={null}
      % Converting Excel data to LaTeX
      % Option 1: Use excel2latex plugin
      % Option 2: Export as CSV and use pgfplotstable
      % Option 3: Use online converters

      % Example using datatool package
      \usepackage{datatool}
      \DTLloaddb{mydata}{data.csv}

      \begin{tabular}{lrr}
      \toprule
      \DTLforeach{mydata}{%
        \name=Name,\value=Value,\status=Status}{%
        \name & \value & \status \\
      }
      \bottomrule
      \end{tabular}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Example using datatool to import CSV data:**

      | Name      | Value | Status  |
      | :-------- | ----: | :------ |
      | Product A |   125 | Active  |
      | Product B |    89 | Pending |
      | Product C |   203 | Active  |

      The `datatool` package provides `\DTLforeach` to iterate over CSV rows and automatically populate table cells. This table was automatically generated from CSV data.
    </Card>
  </Tab>
</Tabs>

## Real-World Table Examples

### Financial Reports

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex financial-table.tex theme={null}
      \documentclass{article}
      \usepackage{booktabs}
      \usepackage{siunitx}
      \usepackage{xcolor}

      \begin{document}

      \begin{table}[htbp]
      \centering
      \caption{Quarterly Financial Summary (in millions)}
      \begin{tabular}{l*{4}{S[table-format=4.1]}S[table-format=+3.1]}
      \toprule
      {Revenue Stream} & {Q1} & {Q2} & {Q3} & {Q4} & {Change (\%)} \\
      \midrule
      Product Sales & 125.4 & 132.7 & 141.2 & 156.8 & +25.0 \\
      Services & 45.2 & 47.8 & 49.1 & 52.3 & +15.7 \\
      Licensing & 12.3 & 11.9 & 13.2 & 14.1 & +14.6 \\
      \midrule
      \textbf{Total Revenue} & 182.9 & 192.4 & 203.5 & 223.2 & +22.0 \\
      \midrule
      Operating Expenses & 89.2 & 91.5 & 94.8 & 98.2 & +10.1 \\
      \midrule
      \textbf{Net Income} & \textbf{93.7} & \textbf{100.9} & \textbf{108.7} & \textbf{125.0} & 
        \textcolor{green!60!black}{\textbf{+33.4}} \\
      \bottomrule
      \end{tabular}
      \end{table}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Table: Quarterly Financial Summary (in millions)**

      | Revenue Stream     |       Q1 |        Q2 |        Q3 |        Q4 |        Change (%) |
      | :----------------- | -------: | --------: | --------: | --------: | ----------------: |
      | Product Sales      |    125.4 |     132.7 |     141.2 |     156.8 |             +25.0 |
      | Services           |     45.2 |      47.8 |      49.1 |      52.3 |             +15.7 |
      | Licensing          |     12.3 |      11.9 |      13.2 |      14.1 |             +14.6 |
      | **Total Revenue**  |    182.9 |     192.4 |     203.5 |     223.2 |             +22.0 |
      | Operating Expenses |     89.2 |      91.5 |      94.8 |      98.2 |             +10.1 |
      | **Net Income**     | **93.7** | **100.9** | **108.7** | **125.0** | **+33.4** (green) |

      This financial table uses `siunitx` for aligned decimal numbers and `\textcolor` for highlighting positive growth in green.
    </Card>
  </Tab>
</Tabs>

### Scientific Data Tables

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex scientific-data.tex theme={null}
      \documentclass{article}
      \usepackage{booktabs}
      \usepackage{siunitx}
      \usepackage{multirow}

      \begin{document}

      \begin{table}[htbp]
      \centering
      \caption{Experimental measurements with uncertainties}
      \begin{tabular}{
        l
        S[table-format=2.3(1)]
        S[table-format=3.2(2)]
        S[table-format=1.4(1)]
      }
      \toprule
      {Sample} & {Mass (\si{\gram})} & {Volume (\si{\milli\liter})} & {Density (\si{\gram\per\cubic\centi\meter})} \\
      \midrule
      Water (control) & 10.000(5) & 10.02(3) & 0.9980(8) \\
      Solution A & 12.345(8) & 11.23(5) & 1.0990(12) \\
      Solution B & 15.678(10) & 13.45(8) & 1.1658(15) \\
      \multirow{2}{*}{Solution C} & 18.234(12) & 15.12(10) & 1.2061(18) \\
      & \multicolumn{3}{c}{\textit{Measurement repeated due to anomaly}} \\
      \bottomrule
      \end{tabular}
      \end{table}

      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Table: Experimental measurements with uncertainties**

      | Sample          |                              Mass (g) |    Volume (mL) |  Density (g/cm^3) |
      | :-------------- | ------------------------------------: | -------------: | ----------------: |
      | Water (control) |                      10.000 +/- 0.005 | 10.02 +/- 0.03 | 0.9980 +/- 0.0008 |
      | Solution A      |                      12.345 +/- 0.008 | 11.23 +/- 0.05 | 1.0990 +/- 0.0012 |
      | Solution B      |                      15.678 +/- 0.010 | 13.45 +/- 0.08 | 1.1658 +/- 0.0015 |
      | Solution C      |                      18.234 +/- 0.012 | 15.12 +/- 0.10 | 1.2061 +/- 0.0018 |
      |                 | *Measurement repeated due to anomaly* |                |                   |

      This scientific table uses siunitx's uncertainty notation `10.000(5)` which displays as "10.000 +/- 0.005". The `\multirow` command is used for Solution C to span two rows with an explanatory note.
    </Card>
  </Tab>
</Tabs>

## Quick Reference

### Essential Commands

| Command                         | Purpose                 |
| ------------------------------- | ----------------------- |
| `\hline`                        | Horizontal line         |
| `\cline{i-j}`                   | Partial horizontal line |
| `\multicolumn{n}{format}{text}` | Span n columns          |
| `\multirow{n}{width}{text}`     | Span n rows             |
| `&`                             | Column separator        |
| `\\`                            | Row separator           |
| `\caption{}`                    | Table caption           |
| `\label{}`                      | Reference label         |

### Column Types Summary

```latex theme={null}
l              % left-aligned
c              % centered  
r              % right-aligned
p{3cm}         % paragraph, fixed width
|              % vertical line
@{text}        % custom separator
>{decl}col     % apply declaration to column
<{decl}        % apply declaration after column
```

## Practice in LaTeX Cloud Studio

<CardGroup cols={2}>
  <Card title="Build the table in the editor" icon="cloud" href="https://app.latex-cloud-studio.com/?utm_source=resources&utm_medium=card&utm_campaign=docs_open_app&utm_content=creating_tables_open_app">
    Paste a `tabular` example into the editor, change alignment and spacing, and check the PDF output immediately.
  </Card>

  <Card title="Advanced tables next" icon="table-columns" href="/learn/latex/tables/advanced-tables?utm_source=resources&utm_medium=related_guide&utm_campaign=docs_open_app&utm_content=creating_tables_advanced_tables">
    Use this when you need longtable, multirow, decimal alignment, or more complex layouts.
  </Card>
</CardGroup>

***

## Related Topics

<CardGroup cols={2}>
  <Card title="Mathematical Matrices" icon="table-cells" href="/learn/latex/mathematics/matrices">
    Create matrices with pmatrix, bmatrix, vmatrix environments
  </Card>

  <Card title="Figure Positioning" icon="image" href="/learn/latex/figures/positioning">
    Control float placement for figures and tables
  </Card>

  <Card title="Cross-Referencing" icon="link" href="/learn/latex/cross-referencing">
    Reference tables, figures, and equations in text
  </Card>

  <Card title="Advanced Tables" icon="table-columns" href="/learn/latex/tables/advanced-tables">
    Long tables, complex layouts, and professional formatting
  </Card>
</CardGroup>

## Further Reading & References

For authoritative documentation on LaTeX table creation and formatting:

* **LaTeX Tables Guide** - The standard reference for tabular environment options and column specifications
* **booktabs Package Documentation** - Professional table rules and spacing guidelines (CTAN)
* **siunitx Package Manual** - Complete guide to number and unit formatting including decimal alignment
* **The LaTeX Companion (3rd Edition)** - Comprehensive reference for table typesetting best practices
* **Publication Style Guides** - IEEE, APA, and Nature journals specify booktabs-style tables as standard

<Info>
  **Next steps**:

  * Learn about [Long tables spanning pages](/learn/latex/tables/advanced-tables) with longtable
  * Explore [Mathematical matrices](/learn/latex/mathematics/matrices) for similar structured layouts
  * Master [Figure and table positioning](/learn/latex/figures/positioning)
</Info>

<Tip>
  **LaTeX Cloud Studio** tip: Use our real-time preview feature to instantly see how your tables render. Experiment with booktabs styling and column alignment without waiting for compilation!
</Tip>
