1

I have the table on the left, whereas what I want is the table on the right.

That is, spread or span the table cells across the minipage environment.

How do I do that?

enter image description here

Code:

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\newfontfamily\englishfont{Arial}[Script=Latin,Language=English]
\begin{document}

\begin{minipage}[b][14cm][t]{10cm}
  \begin{tabularx}{\textwidth} { 
    | >{\centering\arraybackslash}X   |
  }
 \hline
 item 1 \\
 \hline
 item 2 \\
 \hline
 item 3 \\
 \hline
 item 4 \\
\hline
 item 5 \\
\hline
 item 6 \\
\hline
 item 7 \\
\hline

  \end{tabularx}
\end{minipage}

\end{document}
4
  • minipage environments have a pre-set width, but no pre-set height.
    – Mico
    Jun 23 at 19:06
  • @Mico In other words, this is not possible? Or at least not possible the way I try to do it with minipage and tabular inside it?
    – tush
    Jun 23 at 19:07
  • The height of a minipage is given by the heights of whatever objects are in it. If your goal is to set the overall height of a tabular environment to some value, there's no point in taking a minipage-based detour.
    – Mico
    Jun 23 at 19:14
  • All right. But neither tabularx nor tabular accept height in one of its argument. Only width. So if I agree to give up minipage, how do I get it done?
    – tush
    Jun 23 at 19:16

1 Answer 1

2

Here is an alternative solution with tabularray package: you can easily set row heights in tblr environment:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\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}
 item 1 \\
 item 2 \\
 item 3 \\
 item 4 \\
 item 5 \\
 item 6 \\
 item 7 \\
\end{tblr}

\newcommand*\getrowht[1]{%
  \dimexpr
    (
      #1
       - 4pt * \value{rowcount}         % rowsep sizes
       - 0.4pt * (\value{rowcount} + 1) % hrule sizes
    ) / \value{rowcount}
  \relax
}

\begin{tblr}{
  width=10cm,colspec={X[c]},hlines,vlines,
  rows={ht=\getrowht{14cm}}
}
 item 1 \\
 item 2 \\
 item 3 \\
 item 4 \\
 item 5 \\
 item 6 \\
 item 7 \\
\end{tblr}

\end{document}

enter image description here

2
  • +1! I have another question: If I have a text which is a bit long ( ~ 40 words), it causes the cell height to fit it. Is it possible to constraint the cell's height in such a case?
    – tush
    Jun 24 at 12:42
  • @tush Sorry, I can do it if the text wrap.
    – L.J.R.
    Jun 24 at 12:56

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.