4

I am trying to set up an intercorrelation table showing results of two samples. However, for better visuals, I want to split this table into two parts by adding a diagonal line through whole table (not only one cell). The cells themselves have different lengths.

I actually tried to use diagbox, but it failed, (afaik) because it's only intended to be applied at one cell only.

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{diagbox}

\begin{document}

\begin{tabular}{rrrrrr}
    \toprule \\[-1.8ex] 
    & AAAAA & BBBBBBBB & CCCCC & DDDDDD & EEEEEE \\ 
    \midrule
    A & \backslashbox && && \\ 
    B & .XX***  &  \backslashbox & &  & \\ 
    C & .XX***  & .XX***  & \backslashbox & & \\ 
    D & .XX***  & .XX***  & .XX***  & \backslashbox &\\ 
    E & .XX***  & .XX***  & .XX***  & .XX***  & \backslashbox \\ 
    \bottomrule
\end{tabular}

\end{document}

Any ideas - I checked existing answers but none seems to fit.

1

2 Answers 2

3

Here is a possibility with pstricks, if I've well understood what you want:

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{diagbox}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

\begin{postscript}
\begin{tabular}{rrrrrr}
    \toprule \\[-1.8ex]
    & AAAAA & BBBBBBBB & CCCCC & DDDDDD & EEEEEE \\
    \midrule
    A \pnode[1em, 2.6ex]{A} & && && \\
    B & .XX*** & & & & \\
    C & .XX*** & .XX*** & & & \\
    D & .XX*** & .XX*** & .XX*** & &\\
    E & .XX*** & .XX*** & .XX*** & .XX*** & \pnode[0.6em, -1.3ex]{X} \\
    \bottomrule
\end{tabular}
\ncline[linewidth = 0.4pt]{A}{X}
\end{postscript}

\end{document} 

enter image description here

6
  • That's a quite good solution, perfect! However, using TeXStudio and trying to compile this, it results in an error (Package auto-pst-pdf Error: . Or turn off auto-pst-pdf.}). If I set it on XeLaTeX, it works but then other issues occur (wrong signs etc.)
    – Jens
    Jan 31, 2019 at 21:38
  • I compiled this with xelatex. Did you obtain these wrong signs with exactly this code?
    – Bernard
    Jan 31, 2019 at 21:40
  • yes, but in the whole document, not in this table - sorry, if this is offtopic!
    – Jens
    Jan 31, 2019 at 21:42
  • Could ypu post a minimal (yet complete) code reproducing your problems?
    – Bernard
    Jan 31, 2019 at 21:43
  • I will try this tomorrow! Thanks so far for your help!
    – Jens
    Jan 31, 2019 at 21:47
1

Here is a solution with {NiceTabular} of nicematrix. That environment is similar to the classical environment {tabular} (of the package array) but creates also PGF/Tikz under the cells, rows and columns. It's possible to use those nodes to draw whatever rule you want with Tikz in the \CodeAfter).

\documentclass{article}
\usepackage{booktabs}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{NiceTabular}{rrrrrr}
\toprule
& AAAAA & BBBBBBBB & CCCCC & DDDDDD & EEEEEE \\
\midrule
A \\
B & .XX*** \\
C & .XX*** & .XX*** \\
D & .XX*** & .XX*** & .XX*** \\
E & .XX*** & .XX*** & .XX*** & .XX*** & \\
\bottomrule
\CodeAfter
  \tikz \draw (2-|2) -- (last-|last) ; 
\end{NiceTabular}

\end{document} 

You need several compilations (because of the PGF/Tikz nodes).

Output of the above code

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.