1

I have the following table:

        \caption{Comparative Table with Related Work content}
        \label{tab:2}
        \begin{tabular}{11111111}
        \hline\noalign{\smallskip}
        Related Work & IoT Applications & IoT Architectures & IoT Features & Digital CE Analysis & CE Technologies & CE - IoT Relations & Implementation Strategies  \\
        \noalign{\smallskip}\hline\noalign{\smallskip}
            G. Nobre and E. Tavares [7] &&&&x&x&x&x \\
            P. Rosa et. al. [8] &&&&&x&x& \\
            G. Piscitelli et. al [9] &&&&&&x&x \\
            C. Romero et. al. [10] &&&x&&x&x&x \\
            U. Awan et. al. [11] &&&&x&&x&x \\
            Our Work &x&x&x&x&x&x&x \\
        \noalign{\smallskip}\hline
        \end{tabular}
    \end{table}

It's too wide for the page and I probably have to rotate it 90 degrees in order to fit. I tried the adjustbox commands, but I didn't manage to make it work. I'd appreciate some guidance on how to rotate wide tables.

Thank you in advance!

3
  • 2
    Please provide a full but minimal example that others can copy and test as is. That makes it a lot easier to help. Instead of rotating, it might be an idea to redesign the table, for example most of the column headers are much longer than the contents of the columns.
    – daleif
    Commented Dec 17, 2021 at 11:27
  • 1
    Not fixing the actual problem, but it should probably \begin{tabular}{llllllll} instead of \begin{tabular}{11111111}. Commented Dec 17, 2021 at 11:49
  • Never use adjustbox with tabular – it leads to inconsistent font sizes.
    – Bernard
    Commented Dec 17, 2021 at 12:10

2 Answers 2

3

First of all, the column type for left-aligned cells is not 1 (digit one) but l (lowercase L).

To rotate your table, you could place the tabular environment inside \begin{adjustbox}{angle=90} ... \end{adjustbox} (you would need to load the adjustbox package for this), but it turns out (no pun intended), that your table is too wide to even fit on a page vertically.

So, I would suggest you only turn the column headers for the columns that only contain x marks. There is a \rotatebox macro which is provided by the graphicx package, which you could use for this.

Further, I would suggest that you use the booktabs package which provides nice rules, instead of using \noalign{\smallskip}\hline\noalign{\smallskip} and the like.

Finally, you might want to center the tabular inside the table environment using \centering.

\documentclass{article}
\usepackage{graphicx, booktabs}

\begin{document}

    \begin{table}
        \centering
        \caption{Comparative Table with Related Work content}
        \label{tab:2}
        \begin{tabular}{llllllll}
        \toprule
        Related Work & \rotatebox{90}{IoT Applications} & \rotatebox{90}{IoT Architectures} & \rotatebox{90}{IoT Features} & \rotatebox{90}{Digital CE Analysis} & \rotatebox{90}{CE Technologies} & \rotatebox{90}{CE---IoT Relations} & \rotatebox{90}{Implementation Strategies} \\
        \midrule
            G. Nobre and E. Tavares [7] &&&&x&x&x&x \\
            P. Rosa et. al. [8] &&&&&x&x& \\
            G. Piscitelli et. al [9] &&&&&&x&x \\
            C. Romero et. al. [10] &&&x&&x&x&x \\
            U. Awan et. al. [11] &&&&x&&x&x \\
            Our Work &x&x&x&x&x&x&x \\
        \bottomrule
        \end{tabular}%
    \end{table}
    
\end{document}

enter image description here

1

You can use the makecell package to insert a manual linebreak in column content and thus can decrease the overall width of the table. The macros used to this end are thead and makecell. Their syntaxes are similar: \makecell[<align>]{<content>} and \thead[<align>]{<content>}. The optional argument is used for aligning the content horizontally or vertically.

Two approaches using the makecell package are shown below. Here page margin determined by the geometry package was assumed (as no page margin was specified in the question).

1st Approach:

Along with inserting manual linebreak, you can reduce the font size. Here font-size small is used. If the margin is bigger than the default geometry margin, you can use a smaller font size like footnotsize or scriptsize.

Code:

\documentclass{article}

\usepackage{geometry}
\usepackage{makecell}
\usepackage{array, booktabs}

%-------Shows page layout------------------- 
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
%-------------------------------------------

\begin{document}
  \begin{table}[htbp]
        \centering
        \small
        \caption{Comparative Table with Related Work content}
        \label{tab:2}
        \begin{tabular}{@{}l *{7}{c}@{}}
            \toprule
            \thead[l]{Related \\Work} & \thead[l]{IoT \\Applications} & \thead[l]{IoT \\Architectures} & \thead[l]{IoT \\Features} & \thead[l]{Digital CE \\Analysis} & \thead[l]{CE \\Technologies} & \thead[l]{CE - IoT \\Relations} & \thead[l]{Implementation\\ Strategies}  \\
            \midrule
            \makecell[l]{G. Nobre and \\E. Tavares [7]} &&&&x&x&x&x \\
            \makecell[l]{P. Rosa \\et. al. [8]} &&&&&x&x& \\
            \makecell[l]{G. Piscitelli \\et. al [9]} &&&&&&x&x \\
            \makecell[l]{C. Romero \\et. al. [10]} &&&x&&x&x&x \\
            \makecell[l]{U. Awan \\et. al. [11]} &&&&x&&x&x \\
            Our Work &x&x&x&x&x&x&x \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

enter image description here

This exceeds the textwidth but might be acceptable.

2nd Approach:

As Jasper Habicht pointed in his answer, you can rotate the table header. To do this, the makecell package offers the \rothead macro which has a similar syntax as that of thead.

To define the height of the rotated cell you can use either of the two commands:

\settowidth\rotheadsize{\theadfont <Widest head text>} or \setlength\rotheadsize{<width>}

Code:

\documentclass{article}

\usepackage{geometry}
\usepackage{rotating}
\usepackage{makecell}
\usepackage{array, booktabs}

%-------Shows page layout------------------- 
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%-------------------------------------------

\begin{document}
  \begin{table}[htbp]
        \centering
        \caption{Comparative Table with Related Work content}
        \label{tab:2}
        \settowidth\rotheadsize{\theadfont Implementation}
        \begin{tabular}{l *{7}{c}}
            \toprule
            \thead{Related Work} & \rothead{IoT \\Applications} & \rothead{IoT \\Architectures} & \rothead{IoT \\Features} & \rothead{Digital CE \\Analysis} & \rothead{CE \\Technologies} & \rothead{CE - IoT \\Relations} & \rothead{Implementation\\ Strategies}  \\
            \midrule
            G. Nobre and E. Tavares [7] &&&&x&x&x&x \\
            P. Rosa et. al. [8] &&&&&x&x& \\
            G. Piscitelli et. al [9] &&&&&&x&x \\
            C. Romero et. al. [10] &&&x&&x&x&x \\
            U. Awan et. al. [11] &&&&x&&x&x \\
            Our Work &x&x&x&x&x&x&x \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

output 2

This table doesn't exceed the textwidth and also looks nicer to me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .