How to Use LaTeX Math and Tables in Markdown
At a glance
- 1. Check your renderer
Confirm that your Markdown platform supports math and pipe tables; neither feature is part of every Markdown implementation.
- 2. Write Markdown tables
Use pipe-table syntax for ordinary tables, and put LaTeX math in cells only if the renderer supports it.
- 3. Use LaTeX for documents
For a document compiled with LaTeX, write tables with tabular and math with standard LaTeX commands.
- 4. Choose a conversion route
Use a Markdown renderer or Pandoc when you want Markdown source converted to LaTeX or PDF.
Markdown and LaTeX can appear in the same workflow, but they do not share one table syntax. Markdown tables are usually written with pipes and hyphens; LaTeX tables use environments such as tabular. Whether you can put LaTeX math inside a Markdown table depends on the software that renders the Markdown.
The practical choice is simple: use Markdown table syntax in a Markdown document, or use LaTeX table syntax in a .tex document. If you need both, check the renderer or convert the Markdown with a tool that supports the features you use.
Markdown tables with LaTeX math
A common Markdown extension, often called a pipe table, looks like this:
| Quantity | Value |
|:--|--:|
| $x$ | $2$ |
| $x^2$ | $4$ |
The colon in the separator row sets alignment: :-- aligns left, --: aligns right, and :-: centers the column. The $...$ delimiters are commonly used for inline math, but math rendering is not guaranteed by Markdown itself. Some sites use MathJax or KaTeX; others show the dollar signs and contents as plain text.
Pipe tables are also not part of every Markdown flavor. If a table displays as unformatted text, check whether your platform enables a table extension and whether its math renderer is enabled. A Markdown preview in one application may behave differently from the published page or exported document.
Tables in a LaTeX document
If you compile a .tex file with LaTeX, use tabular for the table and ordinary math mode for expressions. Here is a complete minimal example. It uses the booktabs package for clean horizontal rules and amsmath for math support:
\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{lr}
\toprule
Quantity & Value \\
\midrule
$x$ & 2 \\
$x^2$ & 4 \\
\bottomrule
\end{tabular}
\end{document}
Save this as a .tex file and compile it with a LaTeX engine such as pdfLaTeX. In \begin{tabular}{lr}, l makes the first column left-aligned and r makes the second right-aligned. Each & separates columns, and \\ ends a row. The commands \toprule, \midrule, and \bottomrule come from booktabs.
Converting Markdown to LaTeX or PDF
If you want to author in Markdown but produce a PDF, use a converter or publishing system that understands the syntax in your source. Pandoc, for example, can convert Markdown to LaTeX or PDF, but the result depends on its options, the Markdown extensions enabled, and the LaTeX packages available. A pipe table in the Markdown source may be converted to LaTeX table code; it is not simply the same syntax as a tabular environment.
Before writing a long document, test one small example containing both a table and math. This reveals whether the renderer recognizes the table, whether it processes math inside table cells, and whether special characters are being interpreted as intended. If your target is a LaTeX source file, inspect the generated .tex when a conversion produces unexpected output.
Common mistakes
- Assuming all Markdown supports tables or math. Basic Markdown does not specify a universal table or math syntax. Extensions and platform settings determine what works.
- Putting
tabularcode in a Markdown pipe table. A LaTeX environment is not automatically parsed as a Markdown table, and may be displayed as literal code or mishandled. - Using pipe-table syntax in a
.texfile. LaTeX does not interpret| Column |as a table. Usetabularor another LaTeX table environment. - Forgetting column separators in LaTeX. Every row must have the expected number of cells, separated by
&; use\\to end rows between rows, while the final row may be terminated by\end{tabular}without a trailing\\. - Expecting math in a table cell to render everywhere. Even when a renderer supports math, its table parser may have limitations. Test the actual publishing or export environment.
If you need Markdown macros or custom LaTeX commands, verify that your specific renderer defines and permits them; support for $...$ does not automatically mean support for arbitrary preamble commands.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.