0

I spent too much time on this already, please check:

\documentclass{article}

\usepackage{geometry}
 \geometry{
 a4paper,
 left=25.4mm,
 top=25.4mm,
 }

\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{tabularray}
\usepackage{float}
\usepackage{booktabs}
\usepackage{multirow}

\begin document

\noindent
\begin{tabularx}{\linewidth}{|X|c|c|c|c|X|X|X|X|X|}
\hline
\multirow{2}{*}{ID} & \multirow{2}{1cm}{\# of sections} & \multirow{2}{1cm}{\# cylinders per section} & \multirow{2}{1cm}{Total \# of cylinders} & \multirow{2}{1cm}{Storage capacity} & \multicolumn{2}{c|}{Pressure range (MPa)} & \multicolumn{3}{c|}{Dimensions (mm)}\\
\cline{6-10}
 & & & & & minimum & maximum & L & W & H\\
\hline
 1 & 4 & 1 & 4 & 53 & 1 & 70 & 1,200 & 1,200 & 2,700\\ 
\hline
\end{tabularx}

\end{document}

requirements:

  1. to fit the entire table on the page width (this is why tabularx is used instead of tabular I belive),
  2. wrap the text nicely in columns #2,3,4,5;
  3. evenly spread the remaining width across columns 1, 6, 7, 8, 9, 10.
1
  • 1
    Welcome to SE. Your code isn't compilable, as it's missing both preamble and document environment. Please make it easier for people willing to help you by providing a Minimal Working Example as is customary on this site.
    – Miyase
    Jun 26, 2022 at 10:23

2 Answers 2

2

Here's a solution with tabularray, which merges most features from most previous tabular-related packages, including tabularx. The syntax makes it easy to tweak.

  • Specifying width isn't really necessary when it's \textwidth.
  • If \textwidth is too low, the package will start looking for space to reduce where it can, and X columns will no longer be of equal width.
\documentclass{article}
\usepackage{tabularray}
\usepackage[margin=1.2cm]{geometry}

\begin{document}

\noindent
\begin{tblr}{
    width=\textwidth,
    colspec={X[1,c]Q[c,1.2cm]Q[c,1.2cm]Q[c,1.2cm]Q[c,1.2cm]X[1,c]X[1,c]X[1,c]X[1,c]X[1,c]},
    hlines,
    vlines,
    cell{1}{1-5}={r=2}{m},
    cell{1}{6}={c=2}{c},
    cell{1}{8}={c=3}{c},
}
ID & \# of sections & \# cylinders per section & Total \# of cylinders & Storage capacity & Pressure range (MPa) & & Dimensions (mm) & & \\
& & & & & minimum & maximum & L & W & H\\
1 & 4 & 1 & 4 & 53 & 1 & 70 & 1,200 & 1,200 & 2,700
\end{tblr}

\end{document}

result

1
  • thanks, had to implement some adjustments to the table width to fit it on page, but in principle it worked
    – arty
    Jun 27, 2022 at 12:27
1

With tabularx package (as desired):

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow, tabularx}
\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}

\begin{document}
    \begin{table}[ht]
\setlength\tabcolsep{3pt}
\small
\begin{tabularx}{\linewidth}{|c|C{0.9}| C{1.3}| C{1.2}|C{1}| C{1.1}|C{1.1}| C{0.8}|C{0.8}|C{0.8}|}
\hline
\multirow{2}{*}{ID} 
    & \multirow{2}{=}{\# of sections} 
        & \multirow{2}{=}{\# cylinders per section} 
            & \multirow{2}{=}{Total \# of cylinders} 
                & \multirow{2}{=}{Storage capacity} 
                    & \multicolumn{2}{c|}{Pressure range (MPa)} 
                        & \multicolumn{3}{c|}{Dimensions (mm)}\\
\cline{6-10}
    &   &   &   &   & minimum & maximum & L & W & H\\
\hline
 1  & 4 & 1 & 4 &53 & 1 & 70 & 1,200 & 1,200 & 2,700\\
\hline
\end{tabularx}
    \end{table}
\end{document}

enter image description here

Edit:

Assuming, that table has more than one row and that data in last three columns (dimensions (mm)) are different, than may make sense that for last three columns are of S type columns. This may valid also for other columns too, but in lack of information about table content this is no so evident). This time with tabularray package:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{table}[ht]
\sisetup{table-format=4.0,
         group-minimum-digits=4,
         group-separator={,}
         }
\small
\begin{tblr}{hlines, vlines,
             colspec = {c X[0.9,c] X[1.3,c] X[1.2,c] X[c]
                        *{2}{X[1.1,c]} *{3}{X[c, si]} },
             colsep = 3pt,
             cell{1}{1-5}={r=2}{m},
             cell{1}{6}={c=2}{c},
             cell{1}{8}={c=3}{c},
             row{1,2} = {guard}
            }
ID  &   \# of sections   
        &   \# cylinders per section 
            &   Total \# of cylinders 
                &   Storage capacity 
                    &   Pressure range (MPa) 
                        &   &   Dimensions (mm)
                                &   &               \\
    &   &   &   &   & minimum & maximum & L & W & H \\
 1  & 4 & 1 & 4 &53 & 1 &70 & 1200 & 1200 & 2700 \\
 2  & 4 & 1 & 4 &53 & 1 &70 &  920 &  880 &  880 \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

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