2

I'm trying to replicate complicated table (scheme) from Excel:

enter image description here

Cells with numbers (1, 2, ...) should be more or less squared. Lines forming right angle around center table are thicker than ordinary borders (not shown here).

I can make every table separately, but have no idea how to combine them together (with some small spaces in horizontal and vertical). Tried with excel2latex macro from ctan, but with no luck.

Thank you in advance.

EDIT

As asked in comments, here are separate tables:

\documentclass{article}
\usepackage{multirow}
\usepackage{graphicx}
\begin{document}
    
    \begin{tabular}{|r|r|r|r|r|}
    \hline
    1 & 2 & 3 & 4 & 5\\
    \hline
    1 & 2 & 3 & 4 & 5\\
    \hline
    1 & 2 & 3 & 4 & 5\\
    \hline
    1 & 2 & 3 & 4 & 5\\
    \hline
    1 & 2 & 3 & 4 & 5\\
    \hline
    \end{tabular}

    \begin{tabular}{c|l|r|}
    \cline{2-3} 
    \multirow{5}{*}{\rotatebox[origin=c]{90}{some long text here}} & qwerty 1 & 1 \\[1.5ex]
    \cline {2-3}
    & qwerty 2 & 2 \\[1.5ex]
    \cline {2-3}
    & qwerty 3 & 3 \\[1.5ex]
    \cline {2-3}
    & qwerty 4 & 4 \\[1.5ex]
    \cline {2-3}
    & qwerty 5 & 5 \\[1.5ex]
    \cline{2-3}
    \end{tabular}

    \begin{tabular}{|r|l|}
    \hline
    4 & text \\
    \hline
    3 & text text \\
    \hline
    2 & text text text \\
    \hline
    1 & text \\
    \hline
    \end{tabular}

    \begin{tabular}{|r|r|r|r|r|}
    \hline
    1 & 2 & 3 & 4 & 5 \\
    \hline
    \rotatebox[origin=c]{90}{abc} & \rotatebox[origin=c]{90}{abc abc} & \rotatebox[origin=c]{90}{abc} & \rotatebox[origin=c]{90}{abc abc} & \rotatebox[origin=c]{90}{abc abc abc} \\
    \hline
    \multicolumn{5}{c}{long text here 2} \\
    \end{tabular}
\end{document}

EDIT 2

I ask this question to draw the attention of advanced users and packges' developers to the fact that people need an easy and robust way to make such complex "visual" tables. Complexity of creating tables makes people away from using LaTeX.

1
  • @Teepeemm, I edited question and added simple codes for separate tables.
    – Alx
    Aug 23, 2021 at 15:15

3 Answers 3

2

A solution with {NiceTabular} of nicematrix.

The rules of each sub-table are drawn by a command \Block (with the key hvlines) inserted in top-left cell of the sub-table.

The thick rule forming right angle is drawn with Tikz in the \CodeAfter after the construction of the tabular (using PGF/Tikz nodes created by nicematrix under the rows, columns and cells of the array).

\documentclass[10pt]{article}

\usepackage{nicematrix,tikz}

\begin{document}

\sffamily
\small
\renewcommand{\arraystretch}{1.8}
\setlength{\tabcolsep}{2pt}
\newcolumntype{R}{w{r}{8mm}}

\begin{NiceTabular}{clRw{c}{4mm}RRRRRcRl}[cell-space-top-limit=2pt]
\Block{5-1}{\rotate some long text here}
& \Block[hvlines]{5-2}{}
  qwerty 1 & 1 & & \Block[hvlines]{5-5}{}
                   1 & 2 & 3 & 4 & 5 & & \Block[hvlines]{4-2}{}
                                         4 & text \\
& qwerty 2 & 2 & & 1 & 2 & 3 & 4 & 5 & & 3 & text text \\
& qwerty 3 & 3 & & 1 & 2 & 3 & 4 & 5 & & 2 & text text text \\
& qwerty 4 & 4 & & 1 & 2 & 3 & 4 & 5 & & 1 & text \\
& qwerty 5 & 5 & & 1 & 2 & 3 & 4 & 5 \\
\\
&          &   & & \Block[hvlines]{2-5}{}
                   1 & 2 & 3 & 4 & 5 & & \Block[C,draw]{2-2}{centered text }\\
\RowStyle{\rotate}
&          &   & & abc & abc abc & abc & abc abc & abc abc abc \\  
\CodeAfter
  \tikz \draw [thick] (1-|4.5) |- (6.5-|10) ;
\end{NiceTabular}

\end{document}

Output of the above code


Answer to the question in the comment

I have non easy solution. I have changed the columns w{r}{8mm} in columns p[r]{8mm} because, in the columns p, it's possible to change the horizontal alignement with \RowStyle{\centering}. However, that creates a problem for the rotatede elements which are now wrapped at 8 mm (maybe I should change that in nicematrix). That's why I have use \makebox...

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

\begin{document}

\sffamily
\small
\renewcommand{\arraystretch}{1.8}
\setlength{\tabcolsep}{2pt}
\newcolumntype{R}{p[r]{8mm}}

\begin{NiceTabular}{clRw{c}{4mm}RRRRRcRl}[cell-space-top-limit=2pt]
\Block{5-1}{\rotate some long text here}
& \Block[hvlines]{5-2}{}
  qwerty 1 & 1 & & \Block[hvlines]{5-5}{}
                   1 & 2 & 3 & 4 & 5 & & \Block[hvlines]{4-2}{}
                                         4 & text \\
& qwerty 2 & 2 & & 1 & 2 & 3 & 4 & 5 & & 3 & text text \\
& qwerty 3 & 3 & & 1 & 2 & 3 & 4 & 5 & & 2 & text text text \\
& qwerty 4 & 4 & & 1 & 2 & 3 & 4 & 5 & & 1 & text \\
& qwerty 5 & 5 & & 1 & 2 & 3 & 4 & 5 \\
\\
\RowStyle{\rotate\centering}
&          &   & & \Block[hvlines]{2-5}{}
                   1 & 2 & 3 & 4 & 5 & & \Block[C,draw]{2-2}{centered text }\\
\noalign{\vskip 11mm}
\RowStyle{\rotate\centering}
&          &   & & \makebox[18mm][r]{abc} & \makebox[18mm][r]{abc abc} & \makebox[18mm][r]{abc} & \makebox[18mm][r]{abc abc} & \makebox[18mm][r]{abc abc abc} \\  
\CodeAfter
  \tikz \draw [thick] (1-|4.5) |- (6.5-|10) ;
\end{NiceTabular}

\end{document}

Output of the above code

2
  • very nice solution! I thought also about using tikz to arrange individual tables placed in nodes (like Roland's suggestion). The main difficulty is that I don't know how to set fixed width and height of a cell (say, cells with numbers) so that these sizes would be the same for all sub-tables, and then build other cells. In your solution this is done automatically -- all cells are of the same table, this is probably the only way.
    – Alx
    Aug 24, 2021 at 11:39
  • may I ask one small sub-question? I would like the bottom sub-table (with abc ...) looks the same as the left one (with qwerty 1 ...) just rotated, i.e. abc are centered and bottom and numbers are rotated, centerd and up. I added \RowStyle{\rotate} before row with numbers, bu how to align those cells?
    – Alx
    Aug 25, 2021 at 9:22
1

A suggestion to make just one table:

\documentclass{article}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{threeparttable}
\renewcommand{\arraystretch}{1.2}
\usepackage{caption}
\captionsetup{font=small,labelfont=bf,justification   = justified,
    singlelinecheck = true}
\captionsetup[table]{singlelinecheck = false}
\usepackage{makecell} %<- EDIT 

\begin{document}

\setlength\tabcolsep{4pt}   
\begin{table}[]
    \begin{threeparttable}
    \caption{This is a Table}
    \label{tab:my-table}
    \begin{tabular}{ccccccccccccl}
        \cline{2-3} \cline{6-10} \cline{12-13}
        \multicolumn{1}{c|}{\multirow{5}{*}{\rotatebox[origin=c]{90}{some long text here}}} &
        \multicolumn{1}{c|}{quwerty 1} &
        \multicolumn{1}{r|}{1} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{1} &
        \multicolumn{1}{c|}{2} &
        \multicolumn{1}{c|}{3} &
        \multicolumn{1}{c|}{4} &
        \multicolumn{1}{c|}{5} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{4} &
        \multicolumn{1}{l|}{text} \\ \cline{2-3} \cline{6-10} \cline{12-13} 
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{quwerty 2} &
        \multicolumn{1}{r|}{2} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{1} &
        \multicolumn{1}{c|}{2} &
        \multicolumn{1}{c|}{3} &
        \multicolumn{1}{c|}{4} &
        \multicolumn{1}{c|}{5} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{3} &
        \multicolumn{1}{l|}{text text} \\ \cline{2-3} \cline{6-10} \cline{12-13} 
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{quwerty 3} &
        \multicolumn{1}{r|}{3} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{1} &
        \multicolumn{1}{c|}{2} &
        \multicolumn{1}{c|}{3} &
        \multicolumn{1}{c|}{4} &
        \multicolumn{1}{c|}{5} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{2} &
        \multicolumn{1}{l|}{text text text} \\ \cline{2-3} \cline{6-10} \cline{12-13} 
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{quwerty 4} &
        \multicolumn{1}{r|}{4} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{1} &
        \multicolumn{1}{c|}{2} &
        \multicolumn{1}{c|}{3} &
        \multicolumn{1}{c|}{4} &
        \multicolumn{1}{c|}{5} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{1} &
        \multicolumn{1}{l|}{text} \\ \cline{2-3} \cline{6-10} \cline{12-13} 
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{quwerty 5} &
        \multicolumn{1}{r|}{5} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{1} &
        \multicolumn{1}{c|}{2} &
        \multicolumn{1}{c|}{3} &
        \multicolumn{1}{c|}{4} &
        \multicolumn{1}{c|}{5} &
        &
        &
        \\ \cline{2-3} \cline{6-10}
        &
        &
        &
        \multicolumn{1}{c|}{} &
        &
        &
        &
        &
        &
        &
        &
        &
        \\ \cline{5-10}
        &
        &
        &
        &
        &
        &
        &
        &
        &
        &
        &
        &
        \\ \cline{6-10} \cline{12-13} 
        &
        &
        &
        &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{1} &
        \multicolumn{1}{c|}{2} &
        \multicolumn{1}{c|}{3} &
        \multicolumn{1}{c|}{4} &
        \multicolumn{1}{c|}{5} &
        \multicolumn{1}{c|}{} &
        \multicolumn{2}{c|}{\multirow{3}{*}{centered cell}} \\ \cline{6-10}
        &
        &
        &
        &
        \multicolumn{1}{c|}{} &
        \multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
        \multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
        \multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
        \multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
        \multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
        \multicolumn{1}{c|}{} &
        \multicolumn{2}{c|}{} \\ \cline{6-10}
        &
        &
        &
        &
        &
        \multicolumn{5}{c}{\thead[l]{some long text \\ more text}} & <- EDIT
        \multicolumn{1}{c|}{} &
        \multicolumn{2}{c|}{} \\ \cline{12-13} 
    \end{tabular}
\end{threeparttable}
\end{table}

    
\end{document}

enter image description here

2
  • well, but why column with "5" is not of the same width as other numbers 1, 2, 3, 4? "Corner" should be thicker and close to center table.
    – Alx
    Aug 23, 2021 at 23:22
  • @AIx this is due to the long text. You can fix this by making a new line with \usepackage{makecell} see Edit.
    – Roland
    Aug 24, 2021 at 0:02
1

Another suggestion:

If you want to have the tables seperated like you have given them in your MWE. You could also just insert them into a node and arrange them in a TIKZ picture.

\documentclass{article}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{tikz}
\renewcommand{\arraystretch}{1.4}
\begin{document}

\begin{tikzpicture}
\node (table1) {%
  \begin{tabular}{c|l|r|}
    \cline{2-3} 
    \multirow{5}{*}{\rotatebox[origin=c]{90}{some long text here}} & qwerty 1 & 1 \\
    \cline {2-3}
    & qwerty 2 & 2 \\
    \cline {2-3}
    & qwerty 3 & 3 \\
    \cline {2-3}
    & qwerty 4 & 4 \\
    \cline {2-3}
    & qwerty 5 & 5 \\
    \cline{2-3}
\end{tabular}};

\node[right of =table1, xshift=2.5cm,yshift=-1.2pt] (table2) {%
    \begin{tabular}{|r|r|r|r|r|}
        \hline
        1 & 2 & 3 & 4 & 5\\
        \hline
        1 & 2 & 3 & 4 & 5\\
        \hline
        1 & 2 & 3 & 4 & 5\\
        \hline
        1 & 2 & 3 & 4 & 5\\
        \hline
        1 & 2 & 3 & 4 & 5\\
        \hline
\end{tabular}};

\node[right of =table2, xshift=2.5cm,yshift=8.6pt] (table3) {%
    \begin{tabular}{|r|l|}
        \hline
        4 & text \\
        \hline
        3 & text text \\
        \hline
        2 & text text text \\
        \hline
        1 & text \\
        \hline
\end{tabular}};

\node[above of =table2, yshift=-4.5cm] (table4) {%
    \begin{tabular}{|r|r|r|r|r|}
        \hline
        1 & 2 & 3 & 4 & 5 \\
        \hline
        \rotatebox[origin=c]{90}{abc} & \rotatebox[origin=c]{90}{abc abc} & \rotatebox[origin=c]{90}{abc} & \rotatebox[origin=c]{90}{abc abc} & \rotatebox[origin=c]{90}{abc abc abc} \\
        \hline
        \multicolumn{5}{c}{long text here 2} \\
\end{tabular}};

\draw[thick](1.75,1.5) -- (1.75,-1.8);
\draw[thick](1.75,-1.8) -- (5.25,-1.8);

\end{tikzpicture}

\end{document}

enter image description here

2
  • looks much better! It would be even better if one can make width of cells in (table 4) the same as in (table 2)., and rows height in (table 1) is slightly different from those in (table 2). Anyway (+1)!
    – Alx
    Aug 24, 2021 at 2:05
  • Probably using tikz is a right way for such "visually constructed" complex tables, but the problem is that separate tables have slightly different cells' sizes.
    – Alx
    Aug 24, 2021 at 2:15

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.