0

I have a table with multirows and multicolumns with a long column name that needs to be wrapped. However, the resulting table leaves an unwanted space:

% \usepackage{amssymb}
% \usepackage{array}
% \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
% \def\toprule{\specialrule{1.5pt}{0pt}{0pt}}
% \def\botrule{\toprule}
% \def\headerrule{\hline\hline}
% \def\midrule{\specialrule{0.5pt}{0pt}{0pt}}

\begin{table}
\centering
\begin{tabular}{C{2cm}|C{1cm}|C{1cm}|C{1cm}|C{2cm}|C{4cm}}
\toprule
Column A & \multicolumn{3}{c|}{Column B} & Column C is a very long name & Column D \\
\cline{2-4}
& B1 & B2 & B3 & &        \\
\headerrule
blah & \checkmark & \checkmark & \checkmark & blah & blah \\
\midrule
\multirow{2}{*}{blahs} & -- & \multirow{2}{*}{\checkmark} & -- 
& \multirow{2}{*}{blahs} 
& \checkmark\\ \cline{6-6} 
& & & & & -- \\ \cline{6-6} 
\midrule
blah & \checkmark & -- & \checkmark & blah & blah \\
\botrule
\end{tabular}
\end{table}

enter image description here

When I try to specify a single multicolumn, it doesn't respect the 2cm limit (yellow highlight), it messes up the horizontal centering (blue circle), and it produces inconsistent vertical centering (red circle). How can I resolve these issues?

enter image description here

\begin{tabular}{C{2cm}|C{1cm}|C{1cm}|C{1cm}|C{2cm}|C{4cm}}
\toprule
\multicolumn{1}{c|}{Column A} & \multicolumn{3}{c|}{Column B} 
& \multicolumn{1}{c|}{Column C is a very long name} 
& \multicolumn{1}{c}{Column D} \\
\cline{2-4}
& B1 & B2 & B3 & &        \\
\headerrule
blah & \checkmark & \checkmark & \checkmark & blah & blah \\
\midrule
\multirow{2}{*}{blahs} & -- & \multirow{2}{*}{\checkmark} & -- 
& \multirow{2}{*}{blahs} 
& \checkmark\\ \cline{6-6} 
& & & & & -- \\ \cline{6-6} 
\midrule
blah & \checkmark & -- & \checkmark & blah & blah \\
\botrule
\end{tabular}

EDIT: Looking for solutions using Booktabs package

1
  • PLease extend your code fragment to complete small document that we can compile them as they are. Size of \textwidth defined by your page layout has influence on table design. At the both table fifth column headers should be write as multirow cell, what is wrong at ble marked table part, is not clear. See my answer on your previous question.
    – Zarko
    Nov 23, 2022 at 6:22

1 Answer 1

1
  • If you would consider my answer on your previous question, you would avoid your problems.
  • Since you not provide complete small document, the definition of C{...} is unknown. If it is based on p{...} column type, this should not happen.
  • It seems that both table are equal, but have different use of multirow cells, if my guessing is correct.

Edit:

  • Below are two examples of your table:
  • The first:
    • has defined horizontal lines in table preamble
    • column width are of X type with defined
  • The second :
    • for horizontal lines use rules defined in booktabs package and are inserted in table similarly as you did in your code fragment
    • Widths of columns are defined with lengths as are in your code fragment (instead C columns (which definition is Unknown) is used Q column type specifier, which is standard type defined in tabularray
    • column width are of X type with defined ratios between their width
  • Beside showed example, you can make some combination of both tables. For example, in the first table use column specification from the second table, or vice versa, use column specification from first table in the second:
\documentclass{article}
\usepackage[margin=40mm,    % just gueesed
            showframe       % remove in real document
            ]{geometry}
\usepackage[skip=1ex, 
            font=sf, labelfont=bf,
            singlelinecheck=false]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{dingbat}
\newcommand\cm{\checkmark}

\begin{document}
    \begin{table}[ht]
    \centering
\sffamily
\caption{CAPTION.}

%%%% first table
\begin{tblr}{hline{1,Z}=1pt, 
             hline{2,4-Z}=solid,
             hline{3} = {1}{-}{},
             hline{3} = {2}{-}{},
             vline{2-Y} = solid,
             colspec={X[2, c] *{3}{X[c]} X[2,c] X[4,c]},
             vspan=even
            }
\SetCell[r=2]{h}   Column A    
            & \SetCell[c=3]{c}  Column B    
                    &       &       & \SetCell[r=2]{h}   Column C is a very long name  
                                                & \SetCell[r=2]{h}   Column D  \\
            & B1    & B2    & B3    &           &           \\

blah        & \cm   & \cm   & \cm   & blah      & blah      \\
\SetCell[r=2]{m}   blah
            &   \SetCell[r=2]{m}   --
                    &   \SetCell[r=2]{m}  \cm
                            &   \SetCell[r=2]{m}  --
                                    &\SetCell[r=2]{m}  blah
                                                & \cm       \\
            &       &       &       &           & blah      \\
blah        & \cm   & --    & \cm   & blah      & blah      \\
\end{tblr}
    
%%%% second table
\bigskip
\begin{tblr}{vline{2-Y} = solid,
             colspec={Q[c, wd=2cm] *{3}{Q[c, wd=1cm]} Q[c, wd=2cm] Q[c, wd=4cm]},
             vspan=even
            }
    \toprule
\SetCell[r=2]{h}   Column A
            & \SetCell[c=3]{c}  Column B
                    &       &       & \SetCell[r=2]{h}   Column C is a very long name
                                                & \SetCell[r=2]{h}   Column D  \\
    \midrule
            & B1    & B2    & B3    &           &           \\
    \midrule
    \midrule
blah        & \cm   & \cm   & \cm   & blah      & blah      \\
    \midrule
\SetCell[r=2]{m}   blah
            &   \SetCell[r=2]{m}   --
                    &   \SetCell[r=2]{m}  \cm
                            &   \SetCell[r=2]{m}  --
                                    &\SetCell[r=2]{m}  blah
                                                & \cm       \\
    \midrule
            &       &       &       &           & blah      \\
    \midrule
blah        & \cm   & --    & \cm   & blah      & blah      \\
    \bottomrule
\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 .