7

I have this MWE:

\documentclass{article}
\usepackage{multirow}
\begin{document}
    \begin{table}[here]
        \begin{center}
            \begin{tabular}{|l|l|c|}
            \hline 
            \multicolumn{2}{|c|}{\textbf{SED}} & \multirow{2}{*}{\textbf{\% compressione}} \\
            \cline{1-2}
            \textbf{MC} & \textbf{DP} & \\ 
            \hline 
            \hline
            0.00016032 & 0.0001750267 & 10\%\\
            \hline
            \end{tabular} 
        \end{center}
    \end{table}
\end{document}

It realizes this image: enter image description here

The first two columns are correctly formatted to the left, but I want it so that just MC and DP will be centered, how can I do that?

11

Like you did it with the "SED": with \multicolumn:

\multicolumn{1}{|c|}{\textbf{MC}}
3

The makecell package can be handy here, as it allows to have a common formatting for all column headers declared in preamble.: the contents of a \makecell or \thead command is by default both vertically aand horizontally centred. It also defines a command for hlines of varying thickness. Consider also using the booktabs package:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[x11names]{xcolor} 

\usepackage{array, booktabs}
\usepackage{makecell}
\renewcommand{\theadfont}{\color{Tomato3}\bfseries}
\setcellgapes{3pt}


\begin{document}

{\makegapedcells
\begin{tabular}{!{\vrule width1pt}p{.5in}|p{1in}|p{1in}|p{1in}!{\vrule width1pt}}
\Xhline{1pt}
\thead{S. No.} & \thead{Book Name} & \thead{Author} &
  \thead{Publisher}\\
\hline
a & b & c & d\\
\Xhline{1pt}
\end{tabular}}
 \vskip 1cm
\begin{tabular}{p{.5in}*{3}{p{1in}}}
\toprule
\thead{S. No.} & \thead{Book Name} & \thead{Author} &
  \thead{Publisher}\\
\cmidrule(l{5pt}r{5pt}){1-4}
a & b & c & d\\
\bottomrule
\end{tabular}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.