Skip to content

Math and LaTeX in Markdown Tables

By MarkdownTables.com editorial teamUpdated

On this page

How do I put math in a Markdown table?

Math in a cell is ordinary inline math. Write the table as usual and put each expression between single dollar signs. Anything that works in inline math elsewhere in the document (fractions, Greek letters, subscripts, \text{…}, \color) works in a cell.

Formulas in a table, written without a single |
Markdown
| Quantity     | Formula                              | Unit |
| ------------ | ------------------------------------ | ---- |
| Kinetic energy | $E_k = \frac{1}{2} m v^2$          | J    |
| Absolute error | $\lvert x - \hat{x} \rvert$         | —    |
| Norm         | $\lVert \mathbf{v} \rVert_2$         | —    |
| Conditional  | $P(A \mid B)$                        | —    |
Preview
QuantityFormulaUnit
Kinetic energyEk = ½ m v²J
Absolute error|x − x̂|—
Norm‖v‖2—
ConditionalP(A ∣ B)—

Preview approximates the typeset output on GitHub. Our build-time preview doesn’t run MathJax.

Open in editor : Formulas in a table, written without a single |

Keep each expression on one line, because a line break ends the row. Long formulas make the column wide; if that hurts readability, put a short name in the table and the full equation below it. For colored values in cells, see text formatting and color.

How do I write | inside math in a table?

This is the problem nearly everyone hits. GFM splits a table row on every unescaped | before it looks at inline content, and math is inline content. So $|x|$ is cut into three cells and the table breaks. Use a LaTeX command that draws the same symbol instead:

Instead of | inside math, write
You wantWriteRenders as
Absolute value\lvert x \rvert or \vert x \vert|x|
Norm\lVert v \rVert or \Vert v \Vert‖v‖
Conditional probabilityP(A \mid B)P(A ∣ B)
Set-builder notation\lbrace x \mid x > 0 \rbrace{x ∣ x > 0}
Dividesa \mid ba ∣ b
Evaluated atf(x) \big\vert_{x=0}f(x)|ₓ₌₀
Logical orp \lor qp ∨ q
Broken: a raw pipe in math adds a column
Markdown
| Function       | Definition |
| -------------- | ---------- |
| Absolute value | $|x|$      |
Preview
FunctionDefinitionColumn 3Column 4
Absolute value$x$
Fixed: \lvert … \rvert and \mid
Markdown
| Function       | Definition                 |
| -------------- | -------------------------- |
| Absolute value | $\lvert x \rvert$          |
| Set builder    | $\lbrace x \mid x > 0 \rbrace$ |
Preview
FunctionDefinition
Absolute value$\lvert x \rvert$
Set builder$\lbrace x \mid x > 0 \rbrace$

Preview shows the source; GitHub typesets it as |x| and {x ∣ x > 0}.

Open in editor : Fixed: \lvert … \rvert and \mid

\lvert … \rvert is preferred over \vert for absolute values because it spaces the bars as opening and closing delimiters. Escaping as \| is a trap: the table removes the backslash before math renders, so you get a single bar on GitHub, while in LaTeX \| means ‖. Other renderers may treat it differently again. Stick to the named commands, which work everywhere. The general rules for pipes are on the escaping pipes page.

Dollar signs, underscores and backslashes

Math is parsed after Markdown in some renderers, so Markdown can change the expression before MathJax sees it. The symptoms are underscores turning into italics, \\ collapsing to \, or braces disappearing. On GitHub and GitLab, the backtick form $`…`$ protects the expression completely:

Backtick-delimited math (GitHub, GitLab)
Markdown
| Term     | Expression          |
| -------- | ------------------- |
| Sum      | $`\sum_{i=1}^n x_i`$ |
| Variance | $`\sigma^2`$         |
Preview
TermExpression
Sum$\sum_{i=1}^n x_i$
Variance$\sigma^2$

Preview shows the source. Other renderers display the backticks as code, so use this form only for GitHub and GitLab.

Open in editor : Backtick-delimited math (GitHub, GitLab)

The opposite problem is a dollar sign that isn't math. Two $ in one cell (a price range) can be read as a math span. Escape them as \$:

Broken on GitHub: “10-” may render as mathMarkdown
| Plan | Price         |
| ---- | ------------- |
| Pro  | $10-$20/month |
Fixed: escaped dollar signs
Markdown
| Plan | Price           |
| ---- | --------------- |
| Pro  | \$10–\$20/month |
Preview
PlanPrice
Pro$10–$20/month

LaTeX tables in Jupyter and other notebooks

A common search is how to write a LaTeX table in a Jupyter Markdown cell. MathJax, which Jupyter uses, typesets math only; text-mode environments such as tabular and table aren't supported, so this shows up as raw text:

Not rendered in Jupyter Markdown cellsLaTeX
\begin{tabular}{lcc}
Model & Accuracy & F1 \\
Baseline & 0.81 & 0.78 \\
\end{tabular}

You have three working options:

  1. A Markdown table with inline math (the examples above). It renders in JupyterLab, Notebook, VS Code notebooks and Colab, and exports cleanly to HTML and PDF.
  2. A math-mode array, which MathJax does support, including column rules and \hline. Text must go in \text{…}:
A ruled table with \begin{array} in a Markdown cellLaTeX
$$
\begin{array}{l|c|c}
\text{Model} & \text{Accuracy} & \text{F}_1 \\
\hline
\text{Baseline} & 0.81 & 0.78 \\
\text{Tuned} & 0.89 & 0.87
\end{array}
$$
  1. Generate the table from code. A DataFrame displays as an HTML table on its own; to get Markdown, use to_markdown(). df.to_latex() produces tabular source for a paper, not something the notebook renders.
Show a DataFrame as a Markdown table in JupyterPython
import pandas as pd
from IPython.display import Markdown

df = pd.DataFrame({"Model": ["Baseline", "Tuned"], "Accuracy": [0.81, 0.89]})
Markdown(df.to_markdown(index=False))  # needs the tabulate package

More on generating tables from code is in the Python guide.

Math in tables on docs sites (MkDocs, Docusaurus, Hugo, Jekyll)

Static site generators don't render math by default. Once math is enabled for the site, it works in table cells with the same pipe rule.

  • MkDocs: pymdownx.arithmatex plus MathJax or KaTeX.
  • Docusaurus: remark-math and rehype-katex, plus the KaTeX CSS.
  • Hugo: the Goldmark passthrough extension with MathJax or KaTeX in your templates.
  • Jekyll / GitHub Pages: kramdown recognises $$…$$ (for inline math too) and outputs MathJax delimiters; add MathJax to your layout.
MkDocs: enable mathYAML
# mkdocs.yml
markdown_extensions:
  - pymdownx.arithmatex:
      generic: true
extra_javascript:
  - javascripts/mathjax.js
  - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
Docusaurus: enable mathJavaScript
// docusaurus.config.js (docs preset options)
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';

docs: {
  remarkPlugins: [remarkMath],
  rehypePlugins: [rehypeKatex],
},
// and add the KaTeX stylesheet to `stylesheets`
kramdown: inline math uses double dollarsMarkdown
| Shape  | Area        |
| ------ | ----------- |
| Circle | $$\pi r^2$$ |

Math in tables by platform

Inline math inside table cells by platform
PlatformMath in table cellsWorks without setup
GitHub (GFM)MathJax. $…$; a dollar-plus-backtick form protects expressions Markdown would alter.YesYes
GitLab (GLFM)KaTeX. $…$, plus the dollar-plus-backtick form.YesYes
ObsidianMathJax. $…$ in cells.YesYes
VS Code previewKaTeX, setting markdown.math.enabled (on by default).YesYes
Jupyter (Lab, Notebook)MathJax in Markdown cells. LaTeX tabular is not rendered.YesYes
Pandoc / QuartoPandoc HTML needs --mathjax or --katex; PDF output uses LaTeX directly.YesPartly: Quarto yes; Pandoc HTML needs a flag
MkDocs / Docusaurus / HugoArithmatex, remark-math + rehype-katex, or Hugo’s passthrough extension, plus MathJax or KaTeX.YesNo: Plugin and script
Jekyll / GitHub Pages (kramdown)kramdown uses $$…$$ for inline math too; load MathJax in your layout.YesNo: Add MathJax
Reddit, Slack, DiscordNoNo

✅ supported · ⚠️ partly or with a workaround · ❌ not supported · Last verified October 2026

Common mistakes and fixes

  • Raw | in math. Splits the cell. Use \lvert, \rvert, \mid or \Vert.
  • Pipes inside backtick math. $`|x|`$ still splits the cell; GFM splits rows before code spans are parsed.
  • Display math in a cell. $$ blocks need their own lines, which ends the row. Use inline math with \displaystyle.
  • Spaces next to the dollar signs. On GitHub, $ x $ may not be treated as math. Write $x$.
  • Using a table for a matrix. For a matrix, use \begin{bmatrix} in math, not a Markdown table.

When a table with math refuses to render, the table validator shows which row has the extra column.

When to switch to LaTeX or HTML

Markdown tables with inline math suit READMEs, notes and notebooks. For a paper or a PDF with numbered tables, merged header cells and booktabs rules, write LaTeX. Convert an existing table with the Markdown table to LaTeX converter or let Pandoc do it as part of the build. On a website that needs merged cells as well as math, use an HTML table; MathJax and KaTeX typeset math inside HTML tables too.

For the basics of table structure, see Markdown table syntax.

Frequently asked questions

Can you use LaTeX math in a Markdown table?

Yes, inline math: wrap the expression in $…$ inside the cell, for example | Area | $\pi r^2$ |. GitHub, GitLab, Obsidian, VS Code and Jupyter render it. Avoid the | character inside the math; write \vert, \lvert…\rvert or \mid.

Why does |x| break my Markdown table?

The table splits each row on | before the math is rendered, so $|x|$ becomes three cells. Write $\lvert x \rvert$ or $\vert x \vert$ for absolute value, $\lVert v \rVert$ for a norm and $P(A \mid B)$ for conditional probability.

How do I make a LaTeX table in a Jupyter Markdown cell?

Use a Markdown pipe table, which Jupyter renders, and put any math in $…$. Jupyter’s MathJax only typesets math, so \begin{tabular} shows as text. For a ruled grid in math mode, $$\begin{array}{l|c} … \end{array}$$ works.

Can I use display math ($$) in a table cell?

Not as a block: a cell holds one line of inline content, so display equations don’t fit. Use inline $…$, and \displaystyle inside it if you want full-size fractions and sums. kramdown is different: it uses $$…$$ for inline math too.

How do I show a dollar sign in a table with math?

Escape it as \$. On GitHub, two unescaped dollar signs in one cell, as in $10-$20, can be read as a math span. Prices in separate cells are usually fine, because each cell is parsed on its own.

Does Markdown math work in GitHub table cells?

Yes. GitHub has rendered $…$ math since 2022, including inside table cells. If underscores or backslashes are being eaten by Markdown, put a backtick just inside each dollar sign; GitHub and GitLab both support that form.

How do I convert a Markdown table to a LaTeX table?

Paste it into the Markdown table to LaTeX converter, which outputs a tabular environment with alignment kept, or run pandoc table.md -t latex. Math in cells passes through unchanged.

Turn a Markdown table into a LaTeX tabular for your paper.

Convert to LaTeX