2

I would like to create the same table in latex: Table

The first two and last two columns consist of a few words, but the two in the middle are made up of longer text. In my code, I chose landscape orientation for the table. Here is my code:

\documentclass[]{article}
\usepackage{rotating}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{lipsum}
\usepackage{booktabs}

\newcolumntype{s}{>{\hsize=.15\hsize}X}
\newcommand{\heading}[1]{\multicolumn{1}{c}{#1}}

\begin{document}

\begin{sidewaystable}
\caption{Metrics}
\begin{tabularx}{\textheight}{s|s|X||X|s|s}
\multirow{8}{*}{\rotatebox[origin=c]{90}{Connectivity 1}} & \multirow{4}{*}{\rotatebox[origin=c]{90}{\shortstack[c]{Type of \\connection 1}}} 
& blabal blabal blabalbl abalblabal blabalbla balblaba lblabalbl abalbl abalbla balblabal   & blabal blabal blabalbl abalblabal blabalbla balblaba lblabalbl abalbl abalbla balblabal   
& \multirow{4}{*}{\rotatebox[origin=c]{-90}{\shortstack[c]{Type of \\connection 2}}} 
& \multirow{8}{*}{\rotatebox[origin=c]{-90}{Connectivity 2}} \\

&                    & 2      & 2.1     &                    & \\
&                    & 3      & 3.1     &                    & \\
&                    & 4      & 4.1     &                    & \\
\cmidrule{2-3}\cmidrule{4-5}
& \multirow{4}{*}{\rotatebox[origin=c]{90}{\shortstack[c]{Privileges \\ and rights 1}}}  
& 5                  & 5.1          
& \multirow{4}{*}{\rotatebox[origin=c]{-90}{\shortstack[c]{Privileges \\ and rights 2}}} & \\
&                    & 6      & 6.1    &                    &  \\
&                    & 7      & 7.1    &                    &  \\
&                    & 8      & 8.1    &                    &  \\
\cmidrule{2-5}
\end{tabularx}
\end{sidewaystable}
\end{document}

And the output:

enter image description here

There are several issues that I want to correct:

  1. Despite the origin=c use in \rotatebox, it seems that the rotated texts are not centered
  2. I must not use the midrule properly
  3. Maybe there is a better way to define column types

Thank's for your help.

4
  • Horizontal lines from the booktabs package, such as \midrule are intended to be used without vertical lines, hence the small gaps around intersections that you observe.
    – leandriis
    Apr 18, 2021 at 9:17
  • Entirely unrelated, but I wouldn't use rotated text inside of rotated table. If you print the page containing the table, the rotated text will appear upside down if you look as the page in portrait orientation. It might be better to try to make sure the table fits onto the page in portrait orientation.
    – leandriis
    Apr 18, 2021 at 9:19
  • The issue regarding non centered rotated text is due to the uwe of \multirow. The first argument of \multirow is the number of lines of text, the \multirow cell spans, not the number of table rows. Thus, use \multirow{10}{*}{\rotatebox[origin=c]{90}{Connectivity 1}} instead of \multirow{8}{*}{\rotatebox[origin=c]{90}{Connectivity 1}} and adapt the other \multirow commands accordingly.
    – leandriis
    Apr 18, 2021 at 9:23
  • Regarding the column types: I'd replace s with a simple c column type. If you plan on using s, which is basically just a narrower version of X, you must make sure that the sum of \hsize coefficient equals the number of X or derived column types in your table. (Currently, you use 6 X or similar type columns, but the coefficients only add up to 2.6) Using regular c type columns instead of s would be alot easier here.
    – leandriis
    Apr 18, 2021 at 9:26

1 Answer 1

0

Here is a way to do that table with {NiceTabular} of nicematrix.

\documentclass[]{article}
\usepackage{rotating}
\usepackage{nicematrix}
\usepackage{caption}

\begin{document}

\begin{sidewaystable}
\caption{Metrics}
\NiceMatrixOptions{cell-space-limits=3pt}
\begin{NiceTabular}[hvlines]{*{2}{w{c}{1cm}}*{2}{p{(\textwidth-4cm-12\tabcolsep-7\arrayrulewidth)/2}}*{2}{w{c}{1cm}}}
\Block{8-1}{\rotate \bfseries Connectivity 1}
& \Block{4-1}{\rotate Type of connection 1}
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& \Block{4-1}{\rotate \rotatebox{180}{Type of connection 2}}
& \Block{8-1}{\rotate \bfseries \rotatebox{180}{Connectivity 2}} \\
&& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \\
&& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \\
&& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \\
& \Block{4-1}{\rotate Type of connection 1}
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& \Block{4-1}{\rotate \rotatebox{180}{Type of connection 2}}\\
&& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \\
&& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \\
&& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
& blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \\
\end{NiceTabular}
\end{sidewaystable}
\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

2
  • Thanks for your answer, I compiled your code several times but I still have compilation errors. I'm working on Overleaf and I compiled it with pdfLateX compiler and other proposed compilers but it doesn't work.
    – nicope13
    Apr 19, 2021 at 6:25
  • Overleaf has not the latest version of nicematrix. You should upload the latest version of the file nicematrix.sty in the repertory of the Overleaf project. You can download that file on the SVN server of TeXLive : www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty Apr 19, 2021 at 8:28

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.