如何使乳胶中的多行单元格垂直居中?

如何使乳胶中的多行单元格垂直居中?

我想要多行单元格垂直居中。

该问题是由细胞被强行包裹引起的。

在此处输入图片描述

\begin{table*}[!h]
    \caption{Distinguish success rate according to types of variable used in dummy operations.}
    \label{table:success rate}
    \renewcommand{\arraystretch}{1.05}
    \setlength{\tabcolsep}{0.5em}
    \centering
    \begin{tabular}{|c|c|c|}
        \hline
        \multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}Types of variable used in \\ dummy operations\end{tabular}} & \multicolumn{2}{c|}{Distinguish success rate} \\ \cline{2-3}
        & \begin{tabular}[c]{@{}c@{}}XMEGA128D4 \\ microprocessor\end{tabular} & \begin{tabular}[c]{@{}c@{}}STM32F303 \\ microprocessor\end{tabular} \\ \hline \hline
        Local variable & 99.92\% & ??.??\% \\ \hline
        Global variable & 93.76\% & ??.??\% \\ \hline
        Separated function argument & 99.86\% & ??.??\% \\ \hline
        United function argument & 73.72\% & ??.??\% \\ \hline
    \end{tabular}
\end{table*}

答案1

以下是表格的两个版本:

在此处输入图片描述

\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}

\begin{table*}[!h]
    \caption{Distinguish success rate according to types of variable used in dummy operations.}
    \label{table:success rate}
    \renewcommand{\arraystretch}{1.05}
    \setlength{\tabcolsep}{0.5em}
    \centering
    \begin{tabular}{|c|c|c|}
        \hline
        \multirow{3}{*}{\begin{tabular}[c]{@{}c@{}}Types of variable used in \\ dummy operations\end{tabular}} & \multicolumn{2}{c|}{Distinguish success rate} \\ \cline{2-3}
        & \begin{tabular}[c]{@{}c@{}}XMEGA128D4 \\ microprocessor\end{tabular} & \begin{tabular}[c]{@{}c@{}}STM32F303 \\ microprocessor\end{tabular} \\ \hline \hline
        Local variable & 99.92\% & ??.??\% \\ \hline
        Global variable & 93.76\% & ??.??\% \\ \hline
        Separated function argument & 99.86\% & ??.??\% \\ \hline
        United function argument & 73.72\% & ??.??\% \\ \hline
    \end{tabular}
\end{table*}


\begin{table*}[!h]
    \caption{Distinguish success rate according to types of variable used in dummy operations.}
    \label{table:success rate}
    \centering
    \begin{tabular}{lcc}
        \toprule
        \multirow{2}{*}{\begin{tabular}[c]{@{}l@{}}Types of variable used in \\ dummy operations\end{tabular}} & \multicolumn{2}{c}{Distinguish success rate in \%} \\ \cmidrule{2-3}
        & \begin{tabular}[c]{@{}c@{}}XMEGA128D4 \\ microprocessor\end{tabular} & \begin{tabular}[c]{@{}c@{}}STM32F303 \\ microprocessor\end{tabular} \\ \midrule
        Local variable & 99.92 & ??.?? \\ 
        Global variable & 93.76 & ??.?? \\ 
        Separated function argument & 99.86 & ??.?? \\ 
        United function argument & 73.72 & ??.?? \\ 
        \bottomrule
    \end{tabular}
\end{table*}

\end{document}

答案2

@Leandriis 答案中第二个例子的变体:

在此处输入图片描述

  • 使用的是tabularx表环境
  • “微处理器”一词被移至表格标题
  • multirow单元格的使用=选项
\documentclass{article}
\usepackage{booktabs, multirow, tabularx}
\usepackage[skip=1ex]{caption}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}[htb]
    \caption{Distinguish success rate according to types of variable used in dummy operations with microprocessors.}
    \label{table:success rate}
    \centering
    \begin{tabularx}{.84\linewidth}{Xcc}
        \toprule
\multirow{2.4}{=}{Types of variable used in dummy operations}
                            & \multicolumn{2}{c}{Distinguish success rate in \%}    \\
        \cmidrule{2-3}
                            & XMEGA128D4    &   STM32F303   \\
        \midrule
Local variable              & 99.92         & ??.??         \\
Global variable             & 93.76         & ??.??         \\
Separated function argument & 99.86         & ??.??         \\
United function argument    & 73.72         & ??.??         \\
        \bottomrule
    \end{tabularx}
\end{table}
\end{document}

相关内容