在 LaTeX beamer 中将复杂表格的内容居中对齐

在 LaTeX beamer 中将复杂表格的内容居中对齐

Latex beamer 1. 如何使此表格单元格中的内容居中对齐?请参阅下面的屏幕截图和代码。

  1. 如何以简单的方式增加行高?

在此处输入图片描述

\documentclass[17pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usetheme{default}

\begin{document}
    %\author{}
    %\title{}
    %\subtitle{}
    %\logo{}
    %\institute{}
    %\date{}
    %\subject{}
    %\setbeamercovered{transparent}
    %\setbeamertemplate{navigation symbols}{}
    \author{XXYYZZ}
    \title{Test YYYZZUU}

    \begin{frame}[plain]
        \maketitle
    \end{frame}

\begin{frame}
    \frametitle{corrosivity}
    \footnotesize
    \begin{center}

        \begin{tabular}{|l|c|c|c|}
            \hline
            Soil Type&  Resistivity ($\Omega$/cm) & Resistance& Corrosivity\\
            \hline
            Clay&   500 -- 2,000    & &\\
            \cline{1-2}
            Silt&   1,000 -- 2,000& Low &   Severe\\
            \hline
            Loam&   3,000 -- 10,000&    &\\
            \cline{1-2}
            Organic & & Medium& Moderate\\
            \cline{1-1}
            Fine Silt & 2,000 -- 10,000 & &\\
            \hline
            &   10,000 -- 30,000&   High&   Mild\\
            \cline{2-4}
            Sand&   30,000 -- 100,000& Very High & Unlikely\\
            \hline
            Gravel& 40,000 -- 200,000&  Very High&  Unlikely\\
            \hline
        \end{tabular}
    \end{center}
\end{frame}

\end{document}

答案1

\multirow您可以使用以下示例所示的方法垂直对齐单元格中的内容。我还提供了另一种方法,即使用更少的行,siunitx对于单位,使用不同的单位来减少表格中的零数量……

在此处输入图片描述

\documentclass[17pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usetheme{default}
\usepackage{multirow} % For first example

\usepackage{booktabs}  % For second example
\usepackage[per-mode=symbol]{siunitx}
\usepackage{makecell}

\begin{document}
\begin{frame}
    \frametitle{corrosivity}
    \footnotesize
    \begin{center}

        \begin{tabular}{|l|c|c|c|}
            \hline
            Soil Type&  Resistivity ($\Omega$/cm) & Resistance& Corrosivity\\
            \hline
            Clay&   500 -- 2,000    & &\\
            \cline{1-2}
            Silt&   1,000 -- 2,000& \multirow{-2}{*}{Low} &   \multirow{-2}{*}{Severe}\\
            \hline
            Loam&   3,000 -- 10,000&    &\\
            \cline{1-2}
            Organic & & Medium& Moderate\\
            \cline{1-1}
            Fine Silt & \multirow{-2}{*}{2,000 -- 10,000} & &\\
            \hline
            &   10,000 -- 30,000&   High&   Mild\\
            \cline{2-4}
            \multirow{-2}{*}{Sand}&   30,000 -- 100,000& Very High & Unlikely\\
            \hline
            Gravel& 40,000 -- 200,000&  Very High&  Unlikely\\
            \hline
        \end{tabular}
    \end{center}
\end{frame}


\begin{frame}
    \frametitle{corrosivity}
%    \footnotesize
\small
    \begin{center}

        \begin{tabular}{lr@{~--~}lcc}
            \toprule
            Soil Type& \multicolumn{2}{c}{\makecell{Resistivity\\ (\si{\kilo\ohm\per\cm})}} & Resistance& Corrosivity\\
            \midrule
            Clay&   0.5 & 2  &  Low &   Severe\\
            Silt&   1 & 2& \\
            \addlinespace
            Loam&   3 & 10& Medium& Moderate\\
            Organic & 2 & 10 \\
            Fine Silt &  2 & 10 &\\
            \addlinespace
            \multirow{2}{*}{Sand} &   10 & 30&   High&   Mild\\
            &   30 & 100& Very High & Unlikely\\
            \addlinespace
            Gravel& 40 & 200&  \\
            \bottomrule
        \end{tabular}
    \end{center}
\end{frame}

\end{document}

相关内容