1

How can I ensure that the table fits the width of the page automatically? I assumed that the specification would take care of it, but it seems not to be the case. Unfortunately, I cannot include actual images to illustrate the problem, so I have used dummy images with enlarged sizes to demonstrate the issue.

In addition, I tried to ensure that the two images in the "Normalized coefficient" row would be of the same size by setting two columns as X[c]. However, it seems that this approach did not work as expected. Below is the MWE of the issue.

enter image description here

\documentclass[journal]{IEEEtran}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{amsmath}
\usepackage{adjustbox}
\usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf,labelformat=simple]{subfig}


\begin{document}
\lipsum[]

\adjustboxset{width=\linewidth, valign=M}

\onecolumn
\begin{longtblr}{
  width=\textwidth,
  cells = {c},
  hlines,
  colspec= {|c| X[c,m]}
}
1 & X \\
2 & y \\
3 &\begin{tblr}{
width=\linewidth,
colspec={c X[c] X[c]},
cells={},
hlines,
hline{Z}={3pt,blue5},
row{1-Z}={font=\small},
}
C1 & C2 & C3\\
{Normalized \\Coefficient} & \adjincludegraphics{example-image-a}  &   \adjincludegraphics{example-image-b} \\
 $A$ & \SetCell[c=2]{c} \adjincludegraphics{example-image-a}   \\
 $B$ & \SetCell[c=2]{c} \adjincludegraphics{example-image-a}   \\
\end{tblr} \\
\end{longtblr}

\end{document}
5
  • Instead of \onecolumn I would use table* [p] and try to fit it into one page. This will involbe saveboxes for the heights. Commented Apr 14, 2023 at 3:04
  • 1
    Also, for the internal tblr you should have used [width=\hsize] I havve no ides what X[c,m] is supposed to do. Commented Apr 14, 2023 at 3:09
  • @JohnKormylo it's hard for me to change to a different package now as the table is quite large and I would like to keep using longtblr.
    – hana
    Commented Apr 14, 2023 at 17:07
  • @JohnKormylo IMO, the notation X[c, m] indicates that the column is extendable, and c and m represent horizontal center and vertical middle alignment, respectively.
    – hana
    Commented Apr 14, 2023 at 17:09
  • Examples in tabularrray use X[2,l] and X[1,r] where the number is a width scale factor and the letter (l or r) indicates left or right alignment. This notation supposedly started in tabularx and tabu. Commented Apr 14, 2023 at 20:01

1 Answer 1

2
  • Not really an answer, but it is to long for the comment ...
  • Your problem is not trivial.
  • With adding hspan=minimal you can fix width of images, but the same time image in multicolumn cells get spurious vertical space )wjic not arrise if these cells contain a text:
\documentclass[journal]{IEEEtran}
\usepackage{lipsum}
\usepackage[caption=false,
            labelfont=sf,textfont=sf,labelformat=simple]{subfig}
\usepackage[export]{adjustbox}

\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs}
\begin{document}
\lipsum[1]
    \begin{table}[ht]
\adjustboxset{width=\linewidth,
              valign=t}
\begin{tblr}{width=\linewidth,
             hline{1-Y} = solid,
             hline{Z}={3pt,fg=blue5},
             cells={font=\small},
             colspec={Q[c,m] *{2}{Q[c, wd=30mm]} @{}},
             cell{X-Z}{2} = {c=2}{j},
             rowsep=3pt,
             hspan=minimal
             }
C1 & C2 & C3\\
{Normalized \\Coefficient} 
    & \adjincludegraphics[valign=m]{example-image-a} & \adjincludegraphics[valign=m]{example-image-b} \\
$A$ & \adjincludegraphics[valign=m]{example-image-a} &    \\
$B$ & \adjincludegraphics[valign=m]{example-image-b} &    \\
$C$ & \lipsum[66]                                 &    \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

It seems that this is caused with some bug, so we need a help of package author.

Addendum: What to do meanwhile?

Not use \tabularray package and rather stick with good old tabularx package:

\documentclass[journal]{IEEEtran}
\usepackage{lipsum}
\usepackage[caption=false,
            labelfont=sf,textfont=sf,labelformat=simple]{subfig}
\usepackage[export]{adjustbox}

\usepackage{colortbl}
   \usepackage{cellspace,   % for adding vertical space around cells' contents
                tabularx}
    \setlength\cellspacetoplimit{0pt}
    \setlength\cellspacebottomlimit{1pt}
\newcommand\mcxx[1]{\multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep\linewidth=\hsize}X @{}}{#1}}
\newlength\colwidth

\usepackage{booktabs}

\begin{document}
\lipsum[1]
    \begin{table}[ht]
\setkeys{Gin}{width=\linewidth}
\settowidth\colwidth{Coefficient}
\begin{tabularx}{\linewidth}{@{} >{\centering}p{\colwidth} *{2}{SX} @{}}
    \toprule
C1 & C2 & C3\\
    \midrule
Normalized Coefficient 
    & \includegraphics[valign=m]{example-image-a}   & \includegraphics[valign=m]{example-image-b} \\
   \midrule
$A$ & \mcxx{\includegraphics[valign=m]{example-image}}  \\
   \midrule
$B$ & \mcxx{\includegraphics[valign=m]{example-image}}  \\
   \arrayrulecolor{blue}
   \bottomrule[3pt]
\end{tabularx}
    \end{table}
\end{document}

enter image description here

6
  • Is there a different way to bypass this, would minipage help?
    – hana
    Commented Apr 14, 2023 at 0:33
  • @hana, yes, it exist different way. See addendum to answer. Anyway original part is important since you discover discrepancy in tabularray package ,,,
    – Zarko
    Commented Apr 14, 2023 at 7:25
  • Would the tabularx work as the original longtblr?
    – hana
    Commented Apr 14, 2023 at 7:44
  • @hana, did you try? On this way you will get answer immediately, yourself ... And please. one problem per question.
    – Zarko
    Commented Apr 14, 2023 at 7:46
  • @hana, of course you can nest tabularx table in the longtblr table. However, you will faced with new problems: placint longtable in document. I strongly suggest you to try this first yourself and then ask how to solve them. Or at least gives more informations about your images sizes.
    – Zarko
    Commented Apr 14, 2023 at 10:04

You must log in to answer this question.

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