Bolding the best result in a LaTeX table

To bold a cell in a LaTeX table, wrap it in \textbf{...} or start the cell with \bfseries. In siunitx S columns, \textbf works in current versions and \bfseries needs detect-weight=true. Define a \best macro so the style lives in one place, decide per column whether higher or lower is better, and bold ties together.

Convert a table from a PDF or screenshot →

By TableToLatex · · Examples tested with pdfLaTeX, TeX Live 2023, siunitx 3.3, pandas 3.0

Three ways to bold a cell

The shortest way to bold a number is \textbf{74.8}. The font switch \bfseries placed at the start of a cell also works, and it affects everything after it in that cell. A third way is to bold a whole column with >{\bfseries}c from the array package, which also bolds the header. Rather than typing these everywhere, define a macro once so the style can change in one place.

A best macro and a second-best macro, with siunitx columns (illustrative numbers)
% preamble: \usepackage{booktabs} \usepackage{siunitx}
\newcommand{\best}[1]{\textbf{#1}}
\newcommand{\second}[1]{\underline{#1}}

\begin{table}[htbp]
  \centering
  \caption{Results. Best per column in bold, second best underlined.}
  \label{tab:best}
  \begin{tabular}{l S[table-format=2.1] S[table-format=1.3]}
    \toprule
    {Method} & {Top-1 $\uparrow$} & {Loss $\downarrow$} \\
    \midrule
    Baseline & \second{71.2} & 1.254 \\
    Ours     & \best{74.8}   & \best{1.102} \\
    Ablation & \best{74.8}   & \second{1.180} \\
    \bottomrule
  \end{tabular}
\end{table}

In this test \best and \second worked inside siunitx S columns with version 3.3, and the decimals stayed aligned. The columns are set up as in the guide to decimal alignment with siunitx.

The one trap is \bfseries inside an S column: in a test the number stayed regular. Turning on detect-weight fixed it. The old detect-inline-weight option no longer exists in version 3 and only produces a warning.

Make fseries work in S columns
% \bfseries is a switch, so siunitx must be told to look for it:
\sisetup{detect-weight=true}
% ... then in a cell:
Baseline & 71.2 & \bfseries 92.0 \\

If the numbers live in a DataFrame, pandas can write the markup for you, including ties. The example prints a tabular in which every best cell is wrapped in \textbf.

pandas Styler: bold the best values (Python)
import pandas as pd

df = pd.DataFrame({"Method": ["Baseline", "Ours", "Ablation"],
                   "Top-1": [71.2, 74.8, 74.8], "Loss": [1.254, 1.102, 1.102]})
st = (df.style.hide(axis="index")
        .format({"Top-1": "{:.1f}", "Loss": "{:.3f}"})
        .highlight_max(subset=["Top-1"], props="textbf:--rwrap;")
        .highlight_min(subset=["Loss"], props="textbf:--rwrap;"))
print(st.to_latex(hrules=True))

Before bolding, check that the numbers are right: after OCR, use the proofreading checklist, because bold on a misread digit is worse than no bold. For header layouts above bold columns, see grouped headers.

Mark the best results in six steps

  1. 1

    Decide the direction per column

    Higher is better for accuracy, lower for loss or latency. Mark it in the header with an arrow, $\uparrow$ or $\downarrow$, so readers do not have to guess.

  2. 2

    Decide how ties are judged

    Compare the values as printed, and bold every cell that ties for best. Two equal numbers with only one in bold look like a mistake.

  3. 3

    Define the style once

    Put \newcommand{\best}[1]{\textbf{#1}} in the preamble, and a \second macro if you also mark the runner-up.

  4. 4

    Wrap the winners

    Write \best{74.8} for each best cell. The same macro works in S columns, as in the listing above.

  5. 5

    Say what bold means

    State it in the caption, for example "Best per column in bold.", so the table stands alone.

  6. 6

    Recheck after every edit

    If you rerun an experiment or add a row, re-evaluate the winners. Bold cells are typed by hand and do not update themselves.

Ways to bold in a LaTeX table

MethodSyntaxIn siunitx S columnsNote
Bold one cell\textbf{74.8}Works with siunitx 3.3The simplest option
Bold with a switch\bfseries 74.8Only with detect-weight=trueThe switch lasts to the end of the cell
A macro\best{74.8}Works in testsChange the style in one place
A whole column>{\bfseries}cUse it in ordinary columnsNeeds the array package; the header turns bold too

What goes wrong

  • No bold in an S column. \bfseries needs detect-weight=true. Use \textbf or the macro to avoid the issue.
  • Warnings about removed options. Settings copied from old answers, such as detect-inline-weight, warn in siunitx 3.
  • Command not found. \rowfont, often quoted in answers, comes from the tabu package. It was not defined in a test that loaded array and makecell.
  • Two bold cells that disagree. A tie where only one cell is bold, or a bold cell that is not actually best, after a late edit to the data.
  • Direction confusion. Bolding the highest loss, or the lowest accuracy. Mark the direction in the header.
  • Unexplained marks. Underlines, stars and bold without a caption sentence that explains them.

How TableToLatex helps

TableToLatex turns bold text in a cell into \textbf{...} and italic text into \textit{...}, so bold that survives extraction is kept. Check every bold cell against the source, because a bold result can arrive plain. A bold number still counts as a number, so the column stays right-aligned (r); change it to an S column yourself if you want decimal alignment. Start from the LaTeX table generator. The table tool is free and runs in your browser. Paste a tab-separated range from a spreadsheet. See pricing.

Questions about bold results

How do I make text bold in a LaTeX table cell?+

Wrap it in \textbf{...}, or start the cell with \bfseries. Both work in ordinary l, c and r columns.

How do I bold a whole row or column?+

For a row, start each cell with \bfseries. For a column, add >{\bfseries} before its letter in the column specification, for example l >{\bfseries}c c, with the array package loaded.

Why does bfseries not work in my siunitx S column?+

In a test with siunitx 3.3 the number stayed regular until \sisetup{detect-weight=true} was set. \textbf{...} works without any option.

Is detect-inline-weight still needed?+

No. In siunitx 3 the option has been removed and the package prints a warning if you use it. Keep detect-weight if you rely on \bfseries.

How do I mark the second-best result?+

Define \newcommand{\second}[1]{\underline{#1}} and write \second{71.2}. Explain both marks in the caption. In a test this worked in S columns too.

What if two methods tie for best?+

Bold both. Choosing one arbitrarily misleads readers, and a pandas highlight_max call, as in the example here, bolds every tied maximum.

Can I bold the best values automatically?+

With a DataFrame, Styler.highlight_max or highlight_min with props="textbf:--rwrap;" wrote \textbf around the best cells in a test with pandas 3.0.5. In plain LaTeX you have to type the macro yourself.

Keep reading

Have a table in a spreadsheet? Paste it into the table tool, or see all LaTeX table guides.