2

I want to center align val and test along upper columns which are something long and temp

\begin{table*}
\centering
\begin{tabular}{l c c c c}
\hline
\toprule
\multirow{2}{4em}{\textbf{temp}} & \multicolumn{2}{c} 
{\textbf{temp}$\downarrow$}  & \multicolumn{2}{c} 
{\textbf{something long}} \\
\cline{2-5}
 & val & test & val & test \\
\hline
\verb|temp| & & 0.7758 & & 62.02 \\
\verb|temp| & & 0.9679 & & 43.44 \\
\verb|temp| & & 0.7289 & & 70.34 \\
\verb|temp| \\
\verb|temp| & & \textbf{0.6877} & & \textbf{74.75} \\
\hline
\verb|Upperbound| & \multicolumn{2}{c}{0.7758} & \multicolumn{2} 
{c}{0.7758} \\
\bottomrule
\hline
\end{tabular}
\end{table*}

I want to center align val and test along upper columns which are something long and temp

2
  • 1
    Welcome to TeX.SE.
    – Mico
    Commented Dec 3, 2022 at 10:21
  • 4
    Please clarify what you mean by "center align val and test along upper columns".
    – Mico
    Commented Dec 3, 2022 at 10:42

1 Answer 1

3

I'm not sure I understand what you mean by "table column center align along upper column using tabular" and/or "center align val and test along upper columns which are something long and temp". If you want the four data columns to have the same width, the following solution may be of interest to you.

enter image description here

\documentclass[twocolumn]{article} % or some other suitable document class
\usepackage{multirow} % for '\multirow' package
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{array}    % for 'w' column type
\newlength\mylen
\begin{document}

\begin{table*}
%% Determine value of "\mylen" (usable width of data cols):
\settowidth{\mylen}{\textbf{something long}}
  \setlength{\mylen}{\dimexpr(\mylen-2\tabcolsep)/2\relax}
   
\centering
\begin{tabular}{@{} l *{4}{wc{\mylen}} @{}} % all data cols have same, fixed width
\toprule
\multirow{2.2}{*}{\textbf{temp}} 
  & \multicolumn{2}{c}{\textbf{temp}$\downarrow$}  
  & \multicolumn{2}{c@{}}{\textbf{something long}} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
 & val & test & val & test \\
\midrule
\verb|temp| & & 0.7758 & & 62.02 \\
\verb|temp| & & 0.9679 & & 43.44 \\
\verb|temp| & & 0.7289 & & 70.34 \\
\verb|temp| & & & & \\
\verb|temp| & & \textbf{0.6877} & & \textbf{74.75} \\
\midrule
\verb|Upperbound| 
  & \multicolumn{2}{c}{0.7758} 
  & \multicolumn{2}{c@{}}{0.7758} \\
\bottomrule
\end{tabular}
\end{table*}
\end{document}

You must log in to answer this question.

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