2

I'm using the diagbox package to create a table with diagonal line.

The code is

\documentclass[]{article}
\usepackage{booktabs}
\usepackage{diagbox} 

\title{}
\author{}

\begin{document}

\maketitle

\section{}
\begin{table}[h!]
    \centering
    \begin{tabular}{@{}lllll@{}}
        \toprule
        \diagbox{Column1}{Column2} & A & BB & CC & SS \\ \midrule
        AAA & 0.1 & 0.1 & 0.1 & 0.1 \\
        BBB & 0.1 & 0.1 & 0.1 & 0.1 \\ \bottomrule
    \end{tabular}
    \caption{Test table}
\end{table}

\end{document}

You will get a result looking like this:

enter image description here

See? The diagonal line is out of the table. How to fix this?

4

Many people would suggest you to use booktabs in the spirit of booktabs. And the result is probably much better (as least, it's my opinion).

\documentclass[]{article}
\usepackage{booktabs}

\begin{document}

\begin{table}[h!]
    \centering
    \begin{tabular}{@{}lllll@{}}
        \toprule
                  & \multicolumn{4}{c}{Column2} \\ \cmidrule{2-5}
        Column1   & A & BB & CC & SS \\ \midrule
        AAA & 0.1 & 0.1 & 0.1 & 0.1 \\
        BBB & 0.1 & 0.1 & 0.1 & 0.1 \\ \bottomrule
    \end{tabular}
    \caption{Test table}
\end{table}

\end{document}

Output of the above code

2
  • How do I accept two answers at the same time? :) Jun 24 '20 at 13:29
  • I think it's not possible. You accept the best one (but I think you can change later if an ever best answer appears). Jun 24 '20 at 13:35
2

Here is the result with the environment {NiceTabular} of nicematrix (≥ 4.0 2020-05-08) which provides a command diagbox.

\documentclass[]{article}
\usepackage{booktabs}
\usepackage{nicematrix}

\begin{document}

\begin{table}[h!]
    \centering
    \begin{NiceTabular}{@{}wl{2.8cm}LLLL@{}}
        \toprule
        \diagbox{Column1}{Column2} & A & BB & CC & SS \\ \midrule
        AAA & 0.1 & 0.1 & 0.1 & 0.1 \\
        BBB & 0.1 & 0.1 & 0.1 & 0.1 \\ \bottomrule
    \end{NiceTabular}
    \caption{Test table}
\end{table}

\end{document}

Output of the above code

6
  • Thanks, it's a solution, but doesn't answer why diagbox package fail? Jun 24 '20 at 12:32
  • and is nicematrix in TexLive 2012? Jun 24 '20 at 12:33
  • 2
    I think that diagbox has not been designed to be compatible with booktabs. There are other similar situations: booktabs is not compatible with colortbl...). Jun 24 '20 at 12:34
  • Hum... nicematrix is not at all in TeXLive 2012. I have begun writting nicematrix in 2018. Jun 24 '20 at 12:35
  • Oh no, the journal submission system is using TexLive 2012, I think. Jun 24 '20 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.