1

I have a column, the first two of them is short and must not be wrapped (I use l and r), whereas the other three has very long column name that must be wrapped (C|C|C).

        \begin{table}
            \begin{center}
            \begin{tabulary}{\linewidth}{l|r|C|C|C}
                \hline
                \hline
                \multicolumn{1}{c|}{CASE} &
                \multicolumn{1}{c|}{COST (\$)} &
                VERY LONG COST NAME (\unit{{MW.h}}) &
                VERY LONG COST NAME (\unit{{MW.h}}) &
                VERY LONG COST NAME (\unit{{MW.h}}) \\
                \hline
                Name   & 999999.999999 & \multicolumn{1}{r|}{999999.999999} & \multicolumn{1}{r|}{999999.999999} & \multicolumn{1}{r}{999999.999999} \\
                \hline
                \hline
            \end{tabulary}
            \end{center}
        \end{table}

It works, but the first two column did not centered vertically. How to make it centered vertically? If using tabulary is not possible, you can use other approach so long that the threee column can be wrapped.

2 Answers 2

1
  • Please always provide MWE (Minimal Working Example), a small complete, compilable document example. So far we haven't any information of used document class and document pages layout.
  • From your code fragment can be concluded, that with vertical centering should be implemented only in column headers, in other headers content is is only in one lines
  • With tabularray is vertical centering simply to get.
  • Use of multicolumn{1}{r}{...} commands in cells overwrite column settings.
  • For column I would use S columns type of siunitx.
  • What unit is MW.h? To my opinion should be MWh.
\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
\begin{table}[ht]
\sisetup{table-format=6.6}
\centering
    \begin{tblr}{colspec={l|Q[c, si]|X[c, si]|X[c, si]|X[c, si]},
                 row{1} ={guard, m}
                 }
        \toprule
        CASE    &   COST (\$)   
            &   VERY LONG COST NAME (\unit{MWh}) 
                &   VERY LONG COST NAME (\unit{MWh}) 
                    &   VERY LONG COST NAME (\unit{MWh})    \\
        \midrule
        Name    & 999999.999999 & 999999.999999 & 999999.999999 & 999999.999999 \\
        \bottomrule
    \end{tblr}
\end{table}
\end{document}

enter image description here

1
  • 1
    Numbers apparently are dummy. I doubt that cost and energy is defined with six decimals.Probaly is more correct to define table format as table-format=6.3 (3 decimal digits) or even table-format=6.2 (2 decimal digits).
    – Zarko
    Nov 30, 2022 at 5:38
1

The red lines only show the frame of the page boundary and can be removed by commenting out the ShowFrame syntax

Adding color to the header gives emphasis and the horizontal rules can be eliminated - if so desired

\documentclass{article}\usepackage{multirow, tabulary}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}

\noindent
\begin{tabulary}{\linewidth}{lrCCC}
\rowcolor{blue!40}
    \multicolumn{1}{c}{CASE} &
    \multicolumn{1}{c}{COST (\$)} &
    VERY LONG COST NAME (\unit{{MW.h}}) &
    VERY LONG COST NAME (\unit{{MW.h}}) &
    VERY LONG COST NAME (\unit{{MW.h}}) \\
    Name   & 999999.999999 & \multicolumn{1}{r}{999999.999999} & \multicolumn{1}{r}{999999.999999} & \multicolumn{1}{r}{999999.999999} \\
    \hline
    \hline
\end{tabulary}
\end{document}

enter image description here

1
  • The CASE and COST seems not centerred alligned vertically. Nov 30, 2022 at 9:35

You must log in to answer this question.

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