将表格单元格的内容水平和垂直居中

将表格单元格的内容水平和垂直居中

我将非常感激您能帮助我将最上面一行的内容垂直和水平地置于单元格的中心(?)。我尝试使用 \multicolumn,但没有成功。

    \documentclass[10pt,a4paper]{scrreprt}

    \usepackage{classicthesis-ldpkg}
    \usepackage{multicol}
    \usepackage{multirow}
    \usepackage{rotating}

    \begin{document}

            \begin{sidewaystable}
             \centering
                \renewcommand\multirowsetup{\centering}
                \begin{tabular}{|>{\centering}p{20mm}|>{\centering}p{18mm}|>{\centering}p{20mm}|>{\centering}p{18mm}|>{\centering}p{20mm}|>{\centering}p{20mm}|>{\centering}m{15mm}|>{\centering}m{20mm}|>{\centering}m{15mm}|m{20mm}<{\centering}|} \hline
                \multirow{2}{20mm}{Head Model} & \# SG computed & \# Computed directly & \# SG Corrected & \# SG Approximated & SMAS triangle count & \multicolumn{2}{>{\centering}p{35mm}|}{Machine~1} & \multicolumn{2}{>{\centering}p{35mm}|}{Machine~2} \\ \cline{7-10}
                 & & & & & & Runtime & \% spent calc geodesics  & Runtime & \% spent calc geodesics \\ \hline
                African & 1102 & 994 & 102 & 56 & -- & 499~sec. (8.3~min.) & 77\% & -- & -- \\ \hline
                \end{tabular}
            \end{sidewaystable}        
    \end{document} 

答案1

在第一个参数中使用\multirow适当的值:

\documentclass[10pt,a4paper]{scrreprt}
\usepackage{classicthesis-ldpkg}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{rotating}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{sidewaystable}
  \centering
  \renewcommand\multirowsetup{\centering}
  \begin{tabular}{|M{20mm}|P{18mm}|P{20mm}|P{18mm}|P{20mm}|P{20mm}|M{15mm}|M{20mm}|M{15mm}|M{20mm}|} \hline
    \multirow{3}{20mm}{Head Model} & \multirow{3}{20mm}{\# SG computed} 
      & \multirow{3}{20mm}{\# Computed directly} & \multirow{3}{20mm}{\# SG Corrected} 
      & \multirow{3}{20mm}{\# SG Approximated} & \multirow{3}{20mm}{SMAS triangle count} 
      & \multicolumn{2}{P{35mm}|}{Machine~1} 
      & \multicolumn{2}{P{35mm}|}{Machine~2} \\ \cline{7-10}
    & & & & & & Runtime & \% spent calc geodesics  & Runtime & \% spent calc geodesics \\ \hline
    African & 1102 & 994 & 102 & 56 & -- & 499~sec. (8.3~min.) & 77\% & -- & -- \\ \hline
  \end{tabular}
\end{sidewaystable}        

\end{document}

避免在表格中使用垂直线是一种很好的做法;在这方面,书签包会引起人们的兴趣。

相关内容