2

I have a tabularray table that I want to keep its cell height fixed at 2 centimeters. So, if there is a rather long text entry to one of its cells, then I want the text size to be smaller.

I haven't seen such a question to accomplish that inside a table cell, so this is why I am coming up with this question.

How can I do that? Any idea would be very helpful.

MWE; cell height changed

\documentclass[11pt]{article}
\usepackage{tabularray}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\newfontfamily\englishfont{Arial}[Script=Latin,Language=English]
\begin{document}

\begin{tblr}{width=10cm,colspec={X[c]},rows={ht=2cm},hlines,vlines} A very long piece of text that should be typed in smaller font size. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation \ short entry, so cell height should be 2 cm \ item 3 \ item 4 \ item 5 \ item 6 \ item 7 \ \end{tblr} \end{document}

tush
  • 1,115

1 Answers1

4

You may try to use \tcboxfit command from tcolorbox package. I am not so familiar with this package and some code in the following answer is copied from this answer.

\documentclass[11pt]{article}
\usepackage[a4paper,margin=5mm]{geometry}
\usepackage{tabularray}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\newfontfamily\englishfont{Arial}[Script=Latin,Language=English]
\usepackage[most]{tcolorbox}
\tcbset{
  width=10cm-12.8pt,height=2cm, boxrule=0pt, frame empty,
  left=0pt, right=0pt, top=0pt, bottom=0pt,
  colback=white, nobeforeafter, valign=center, halign=center,
  size=tight,
  fit fontsize macros,
  fit algorithm=areasize
}
\begin{document}

\noindent \begin{tblr}[t]{width=10cm,colspec={X[c,cmd=\tcboxfit]},rows={ht=2cm},hlines,vlines,stretch=0} A very long piece of text that should be typed in smaller font size. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation \ short entry, so cell height should be 2 cm \ item 3 \ \end{tblr} \begin{tblr}[t]{width=10cm,colspec={X[c]},rows={ht=2cm},hlines,vlines} A very long piece of text that should be typed in smaller font size. Lorem ipsum dolor sit amet, consectetur adipiscing elit, \ short entry, so cell height should be 2 cm \ item 3 \ \end{tblr} \par\noindent \begin{tblr}[t]{width=10cm,colspec={X[c]},rows={ht=2cm},hlines,vlines} A very long piece of text that should be typed in smaller font size. Lorem ipsum dolor sit amet, consectetur adipiscing elit, \ short entry, so cell height should be 2 cm \ item 3 \ \end{tblr} \end{document}

enter image description here

L.J.R.
  • 10,932