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.
| 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)$ | — || Quantity | Formula | Unit |
|---|---|---|
| Kinetic energy | Ek = ½ m v² | J |
| Absolute error | |x − x̂| | — |
| Norm | ‖v‖2 | — |
| Conditional | P(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:
| You want | Write | Renders as |
|---|---|---|
| Absolute value | \lvert x \rvert or \vert x \vert | |x| |
| Norm | \lVert v \rVert or \Vert v \Vert | ‖v‖ |
| Conditional probability | P(A \mid B) | P(A ∣ B) |
| Set-builder notation | \lbrace x \mid x > 0 \rbrace | {x ∣ x > 0} |
| Divides | a \mid b | a ∣ b |
| Evaluated at | f(x) \big\vert_{x=0} | f(x)|ₓ₌₀ |
| Logical or | p \lor q | p ∨ q |
| Function | Definition |
| -------------- | ---------- |
| Absolute value | $|x|$ || Function | Definition | Column 3 | Column 4 |
|---|---|---|---|
| Absolute value | $ | x | $ |
\lvert … \rvert and \mid| Function | Definition |
| -------------- | -------------------------- |
| Absolute value | $\lvert x \rvert$ |
| Set builder | $\lbrace x \mid x > 0 \rbrace$ || Function | Definition |
|---|---|
| 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:
| Term | Expression |
| -------- | ------------------- |
| Sum | $`\sum_{i=1}^n x_i`$ |
| Variance | $`\sigma^2`$ || Term | Expression |
|---|---|
| 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 \$:
| Plan | Price |
| ---- | ------------- |
| Pro | $10-$20/month || Plan | Price |
| ---- | --------------- |
| Pro | \$10–\$20/month || Plan | Price |
|---|---|
| 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:
\begin{tabular}{lcc}
Model & Accuracy & F1 \\
Baseline & 0.81 & 0.78 \\
\end{tabular}You have three working options:
- 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.
- A math-mode
array, which MathJax does support, including column rules and\hline. Text must go in\text{…}:
$$
\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}
$$- Generate the table from code. A DataFrame displays as an HTML table on its own; to get Markdown, use
to_markdown().df.to_latex()producestabularsource for a paper, not something the notebook renders.
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 packageMore 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.arithmatexplus MathJax or KaTeX. - Docusaurus:
remark-mathandrehype-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.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.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`| Shape | Area |
| ------ | ----------- |
| Circle | $$\pi r^2$$ |Math in tables by platform
| Platform | Math in table cells | Works without setup |
|---|---|---|
GitHub (GFM)MathJax. $…$; a dollar-plus-backtick form protects expressions Markdown would alter. | Yes | Yes |
GitLab (GLFM)KaTeX. $…$, plus the dollar-plus-backtick form. | Yes | Yes |
ObsidianMathJax. $…$ in cells. | Yes | Yes |
VS Code previewKaTeX, setting markdown.math.enabled (on by default). | Yes | Yes |
Jupyter (Lab, Notebook)MathJax in Markdown cells. LaTeX tabular is not rendered. | Yes | Yes |
Pandoc / QuartoPandoc HTML needs --mathjax or --katex; PDF output uses LaTeX directly. | Yes | Partly: Quarto yes; Pandoc HTML needs a flag |
| MkDocs / Docusaurus / HugoArithmatex, remark-math + rehype-katex, or Hugo’s passthrough extension, plus MathJax or KaTeX. | Yes | No: Plugin and script |
Jekyll / GitHub Pages (kramdown)kramdown uses $$…$$ for inline math too; load MathJax in your layout. | Yes | No: Add MathJax |
| Reddit, Slack, Discord | No | No |
✅ 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,\midor\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