2

I have created the following table, but will need to rotate it in landscape mode. This is because the "Comments" column will contain a lot of text, and won't fit in a normal table. I have tried to use \usepackage{rotating} and \begin{sidewaystable}, but being a recent Latex user, I have no idea where I am going wrong.

The initial table I have made is:

Image

Thank you so much in advance

PS: For future reference, how can I

(a) ensure that all of my tables fit my document margin? (b) change individual column widths in tabularray?

Again, any help is highly appreciated.

My MWE is shown below:

\usepackage[margin=3cm]{geometry}
\usepackage[font=scriptsize,
            labelfont=bf]{caption}
\usepackage[xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{rotating}
\UseTblrLibrary{siunitx}


\begin{document}


\begin{table}[ht]
\fontsize{9}{10}\selectfont
\centering
\caption{Comparison between AA and BB mean values (wt\%)}
\begin{tblr}{hlines, vlines,
             colspec = {r l *{2}{S[table-format=-1.2]} *{6}{S[table-format=1.2]}},
             column{1} = {font=\bfseries},
             column{2-Z}={font=\fontsize{7}{9}\selectfont},
             row{1} = {ht = 6ex},
             row{1} = {font =\bfseries},
             row{1} = {bg = green7},
             row{1} = {font =\fontsize{9}{6}\selectfont},
             hspan=minimal}                                                                                                                                                                                                                                                             
\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}   & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%    \end{tabular}}}}} & {{{\textbf{R\ $^{2}$}}}} & {{{\textbf{Comments}}}}       \\
\multicolumn{1}{l}{ \textbf{AA\ $-$ BB}}        &3675 & 7.18 & 8.22  & 3.29 & 3.16 & 0.03 & \multirow{4}{*}{} \\ \cline{1-7}  
\multicolumn{1}{l}{ \textbf{AA\ $-$ BB}}        &2195 & 4.51 & 7.33  & 2.96 & 2.55 & 0.08 &       \\ \cline{1-7}
\multicolumn{1}{l}{ \textbf{AA \ $-$ BB}}       &3075 & 5.63 & 7.25  & 3.28 & 3.77 & 0.03 &   \\ \cline{1-7}
\multicolumn{1}{l}{ \textbf{AA \ $-$ BB}}       &3400 & 4.29 & 10.24 & 1.94 & 2.44 & 0.004 &    
\end{tblr}
    \end{table}
    
\end{document}

2 Answers 2

4

What about one of the following two suggestions?

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage[font=scriptsize,
            labelfont=bf]{caption}
\usepackage[xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{rotating}
\UseTblrLibrary{siunitx}

\usepackage{pdflscape}
\usepackage{lipsum}
\begin{document}


\begin{table}[ht]
\fontsize{9}{10}\selectfont
\centering
\caption{Comparison between AA and BB mean values (wt\%)}
\begin{tblr}{hlines, vlines,vspan=even,
             colspec = {l S[table-format=4] *{4}{S[table-format=2.2]}S[table-format=1.3]X},
             column{1} = {font=\bfseries},
             column{2-Z}={font=\fontsize{7}{9}\selectfont},
             row{1} = {ht = 6ex},
             row{1} = {font =\bfseries},
             row{1} = {bg = green7},
             row{1} = {font =\fontsize{9}{6}\selectfont},
             hspan=minimal}                                                                                                                                                                                                                                                             
\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}   & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%    \end{tabular}}}}} & {{{$\mathbf{R^{2}}$}}} & {{{\textbf{Comments}}}}       \\
AA -- BB & 3675 & 7.18 & 8.22  & 3.29 & 3.16 & 0.03  & \multirow{4}{*}{\lipsum[1][1-5]} \\ \cline{1-7}  
AA -- BB & 2195 & 4.51 & 7.33  & 2.96 & 2.55 & 0.08  &       \\ \cline{1-7}
AA -- BB & 3075 & 5.63 & 7.25  & 3.28 & 3.77 & 0.03  &   \\ \cline{1-7}
AA -- BB & 3400 & 4.29 & 10.24 & 1.94 & 2.44 & 0.004 &    
\end{tblr}
    \end{table}
    
    
    
\begin{landscape}

\begin{table}[ht]
\fontsize{9}{10}\selectfont
\centering
\caption{Comparison between AA and BB mean values (wt\%)}
\begin{tblr}{hlines, vlines,vspan=even,
             colspec = {l S[table-format=4] *{4}{S[table-format=2.2]}S[table-format=1.3]X},
             column{1} = {font=\bfseries},
             column{2-Z}={font=\fontsize{7}{9}\selectfont},
             row{1} = {ht = 6ex},
             row{1} = {font =\bfseries},
             row{1} = {bg = green7},
             row{1} = {font =\fontsize{9}{6}\selectfont},
             hspan=minimal}                                                                                                                                                                                                                                                             
\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}    & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Column\\ Header\end{tabular}}}}} & {{{\textbf{\begin{tabular}[c]{@{}c@{}}Variable\\ \%    \end{tabular}}}}} & {{{$\mathbf{R^{2}}$}}} & {{{\textbf{Comments}}}}       \\
AA -- BB & 3675 & 7.18 & 8.22  & 3.29 & 3.16 & 0.03  & \multirow{4}{*}{\lipsum[1][1-8]} \\ \cline{1-7}  
AA -- BB & 2195 & 4.51 & 7.33  & 2.96 & 2.55 & 0.08  &       \\ \cline{1-7}
AA -- BB & 3075 & 5.63 & 7.25  & 3.28 & 3.77 & 0.03  &   \\ \cline{1-7}
AA -- BB & 3400 & 4.29 & 10.24 & 1.94 & 2.44 & 0.004 &    
\end{tblr}
    \end{table}
    
    
 \end{landscape}
\end{document}
1
  • Amazing, it worked perfectly. I used your second code, and it did just as what was required. Thank you so much!
    – user249942
    Aug 29, 2021 at 15:31
4

Unfortunately I am not allowed to comment :) I just wanted to add, that you should use the \SetCell[]{} command instead of \multirow in the tblr environment. P.5 in the documentation.

... & \multirow{4}{*}{\lipsum[1][1-8]} &... % old
... & \SetCell[r=4]{c} \lipsum[1][1-8] & ... % better

You must log in to answer this question.

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