1

I want to have the Alphabet 'P' above 'B' in the output of the following code borrowed from here and modified:

\begin{table}
\centering
\caption{Vehicle info}
\label{tab:my_label}
\begin{tabular}{@{\hspace{1cm}}l ccc}
\toprule 
\multirow{2}{*}{Parameters}  &
\multicolumn{3}{c}{\textbf{Values}} \\
\cmidrule{2-4}
&  $X$ (mm) & $Y$ (mm) & $Z$ (mm)  \\
\midrule
\multicolumn{1}{l}{\textbf{B}}\\\cmidrule{1-1}
\textbf{A} & 0.0 & 0.0 & 0.0  \\ 
\addlinespace
\textbf{T}  & 0.0 & 0.0 & 0.0  \\ 
\bottomrule
\end{tabular}
\end{table}

The output is:

enter image description here

I want to have something similar to this: enter image description here

Can someone please tell what changes needs to be made to the exiting code to get the desired output?

1
  • 1
    Probably, the simplest would be to replace @{\hspace{1cm}} with a supplementary l column.
    – Bernard
    Aug 5, 2021 at 11:55

2 Answers 2

1

Does this satisfy the requirement

enter image description here

\documentclass{article}

\usepackage{booktabs}
\usepackage{multirow, makecell}

\begin{document}
    \noindent
    \begin{tabular}{l l ccc}
        \toprule 
        \multicolumn{2}{l}{\multirow{2.5}{*}{\makecell[l]{Multiple\\Parameters}}}  &
        \multicolumn{3}{c}{\textbf{Values}} \\
        \cmidrule{3-5}
        & & $X$ (mm) & $Y$ (mm) & $Z$ (mm)  \\
        \midrule
        \textbf{B}\\\cmidrule{1-1}
        & \textbf{A} & 0.0 & 0.0 & 0.0  \\ 
        \addlinespace
        & \textbf{T}  & 0.0 & 0.0 & 0.0  \\ 
        \bottomrule
    \end{tabular}
    \\[1cm]
    \begin{tabular}{@{\hspace{1cm}}l ccc}
        \toprule 
        \multicolumn{1}{l}{\multirow{2.5}{*}{\makecell[l]{Multiple\\Parameters}} } &
        \multicolumn{3}{c}{\textbf{Values}} \\
        \cmidrule{2-4}
        &  $X$ (mm) & $Y$ (mm) & $Z$ (mm)  \\
        \midrule
        \multicolumn{1}{l}{\textbf{B}}\\\cmidrule{1-1}
        \textbf{A} & 0.0 & 0.0 & 0.0  \\ 
        \addlinespace
        \textbf{T}  & 0.0 & 0.0 & 0.0  \\ 
        \bottomrule
    \end{tabular}
    
\end{document}

EDIT

\documentclass{article}

\usepackage{booktabs}
\usepackage{multirow, makecell}

\begin{document}
    \noindent
    \begin{tabular}{l l ccc}
        \toprule 
        P&\multicolumn{1}{l}{\multirow{1}{*}{\makecell[l]{Multiple\\Parameters}}}  &
        \multicolumn{3}{c}{\textbf{Values}} \\
        \cmidrule{3-5}
        & & $X$ (mm) & $Y$ (mm) & $Z$ (mm)  \\
        \midrule
        \textbf{B}\\\cmidrule{1-1}
        & \textbf{A} & 0.0 & 0.0 & 0.0  \\ 
        \addlinespace
        & \textbf{T}  & 0.0 & 0.0 & 0.0  \\ 
        \bottomrule
    \end{tabular}

\end{document}

enter image description here

2
  • @ js bibra, Thank you for the answer. I also need the alphabet "P" above "B" as here.
    – Aim
    Aug 6, 2021 at 10:14
  • @Aim please see the edit above
    – js bibra
    Aug 6, 2021 at 11:11
1

EDIT: I adapted my solutions to add the extra P before the 'Parameters' entry. I had erroneously understood to shift the 'Parameters' entry leftward.

My first solution is the the simplest: Just put an extra \multirow{2}{*}{P} in front of 'Parameters'. The second solution can be done by putting the P in a \makebox, but this \makebox must be slightly smaller than 1cm to compensate for the extra \tabcolsep that the tabular environment inserts. I think the first solution is the best, but I leave the second solution in because it may be a useful technique for is miller situations.

END OF EDIT

The suggestion by @Bernard would work. To use this idea, you must put the \multirow{2}{*}{Parameters}} inside a \multicolumn{2} to compensate for the extra column, and put empty cells before the A and T.

Another method would be to keep the original tabular format, but put the \multirow{2}{*}{Parameters} inside a \multicolumn{1}{l} to get rid of the `\hspace{1cm}. But then the line under B would be longer. But that may actually be nicer, in my opinion.

Here are both solutions. I left out the table environment to keep things simpler.

\documentclass{article}

\usepackage{booktabs}
\usepackage{multirow}

\begin{document}
\noindent
\begin{tabular}{l l ccc}
\toprule 
\multirow{2}{*}{P} & \multirow{2}{*}{Parameters}  &
\multicolumn{3}{c}{\textbf{Values}} \\
\cmidrule{3-5}
& & $X$ (mm) & $Y$ (mm) & $Z$ (mm)  \\
\midrule
\textbf{B}\\\cmidrule{1-1}
& \textbf{A} & 0.0 & 0.0 & 0.0  \\ 
\addlinespace
& \textbf{T}  & 0.0 & 0.0 & 0.0  \\ 
\bottomrule
\end{tabular}
\\[1cm]
\begin{tabular}{@{\hspace{1cm}}l ccc}
\toprule 
\multicolumn{1}{l}{\multirow{2}{*}{\makebox[\dimexpr 1cm-\tabcolsep][l]{P}Parameters}}  &
\multicolumn{3}{c}{\textbf{Values}} \\
\cmidrule{2-4}
&  $X$ (mm) & $Y$ (mm) & $Z$ (mm)  \\
\midrule
\multicolumn{1}{l}{\textbf{B}}\\\cmidrule{1-1}
\textbf{A} & 0.0 & 0.0 & 0.0  \\ 
\addlinespace
\textbf{T}  & 0.0 & 0.0 & 0.0  \\ 
\bottomrule
\end{tabular}

\end{document}

enter image description here

0

You must log in to answer this question.

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