多列内的项目列表未正确居中

多列内的项目列表未正确居中

我有一张表格,其中的多列项目列表不符合预期(垂直和水平居中):

\newcolumntype{C}{>{\centering\arraybackslash} m{2.3cm}}
\begin{table}
\caption{Some caption}
\label{tab:tab1}
\centering%
\begin{minipage}{\textwidth}
    \begin{tabular*}{\textwidth}{|C|C|C|C|>{\centering\arraybackslash}m{3cm}|}
        \hline
        \ & \textbf{Hellman} & \textbf{Rainbow Table} & \textbf{Proposed Method} & \textbf{Proposed Method with Compression}\\
        \hline
        Input Range & $2^{37}$ & $2^{37}$ & $2^{37}$ & $2^{37}$ \\ \hline
        Size & $1.4$ GB & $1.4$ GB & $1.4$ GB & $1.4$ GB \\ \hline
        Hash Operations & $90.3$ M & $7.4$ M & $4$ B & $3.5$ B \\ \hline
Advantages &
\multicolumn{2}{>{\centering\arraybackslash}m{4.9cm}|}{
    \begin{itemize}
        \item Few hash operations
    \end{itemize}
} &
\multicolumn{2}{>{\centering\arraybackslash}m{5.4cm}|}{
    \begin{itemize}
        \item Little disk access
        \item Disk access is serial
        \item Success is guaranteed
        \item Easily parallelizable
    \end{itemize}
} \\
\hline
    \end{tabular*}
\end{minipage}
\end{table}

其结果是:

结果

如您所见,只有第三行(哈希操作)似乎精确居中。不过,主要问题是最后一行。项目列表在任何方向上都远未居中。我该如何解决这个问题?

我也不知道为什么右侧边框放置不正确,但我可以设法通过调整单元格的宽度来获得可接受的结果(图中未显示)。

答案1

如果我简化你的代码(删除minipage,而tabular*只使用tabular)并且把美学观点放在一边,那么我会得到:

在此处输入图片描述

现在的代码是:

\documentclass[12pt]{article}
\usepackage{lmodern,caption}
\usepackage{array}
\usepackage{siunitx}

\newcolumntype{C}[1]{>{\centering\arraybackslash} m{#1}}


\begin{document}
    \begin{table}
    \centering%
\caption{Some caption}
    \label{tab:tab1}
    \begin{tabular}{|*{4}{C{2.3cm}|}C{3.1cm}|}
        \hline
        \ & \textbf{Hellman} & \textbf{Rainbow Table} & \textbf{Proposed Method} & \textbf{Proposed Method with Compression}\\
        \hline
        Input Range & $2^{37}$ & $2^{37}$ & $2^{37}$ & $2^{37}$ \\ \hline
        Size & $1.4$ GB & $1.4$ GB & $1.4$ GB & $1.4$ GB \\ \hline
        Hash Operations & $90.3$ M & $7.4$ M & $4$ B & $3.5$ B \\ \hline
Advantages &
\multicolumn{2}{C{4.9cm}|}{
    \begin{itemize}
        \item Few hash operations
    \end{itemize}
} &
\multicolumn{2}{C{5.4cm}|}{
    \begin{itemize}
        \item Little disk access
        \item Disk access is serial
        \item Success is guaranteed
        \item Easily parallelizable
    \end{itemize}
} \\
\hline
    \end{tabular}
\end{table}
\end{document}

您的表格如下:

在此处输入图片描述 编辑: 一些美学改进:

  • 在序言中添加\setlength{\extrarowheight}{3pt}。这将为表格行中的文本上方和下方提供更多空间
    • 为了获得更紧凑的逐项列表,请将其替换\begin{itemize}\begin{itemize}\firmlist,并在序言中添加定义:

\newcommand{\firmlist}{%
  \setlength{\itemsep}{0.5\itemsep}
  \setlength{\parskip}{0.2\parskip}%0.5
  \setlength{\listparindent}{3ex}%2em
                        }

答案2

这可能是常规列表缩进方式的视觉产物。也许创建自己的tabularitemize不使用太多列表格式的列表更适合您的需求:

在此处输入图片描述

\documentclass{article}
\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{array,varwidth,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash} m{2.3cm}}

\newenvironment{tabularitemize}
  {\par\addvspace{\topsep}%
   \renewcommand{\item}{\par\addvspace{\itemsep}%
     \textbullet\hspace{\labelsep}\ignorespaces}%
   \begin{varwidth}{\linewidth}}
  {\par\strut\end{varwidth}}

\begin{document}

\noindent
\begin{tabular*}{\textwidth}{|C|C|C|C|>{\centering\arraybackslash}m{3cm}|}
  \hline
  & \textbf{Hellman} & \textbf{Rainbow Table} & \textbf{Proposed Method} & \textbf{Proposed Method with Compression} \\
  \hline
  Input Range & $2^{37}$ & $2^{37}$ & $2^{37}$ & $2^{37}$ \\ \hline
  Size & $1.4$ GB & $1.4$ GB & $1.4$ GB & $1.4$ GB \\ \hline
  Hash Operations & $90.3$ M & $7.4$ M & $4$ B & $3.5$ B \\ \hline
  Advantages &
  \multicolumn{2}{>{\centering\arraybackslash}m{4.9cm}|}{
    \begin{itemize}
      \item Few hash operations
    \end{itemize}
  } &
  \multicolumn{2}{>{\centering\arraybackslash}m{5.4cm}|}{
    \begin{itemize}
      \item Little disk access
      \item Disk access is serial
      \item Success is guaranteed
      \item Easily parallelizable
    \end{itemize}
  } \\
  \hline
  Input Range & $2^{37}$ & $2^{37}$ & $2^{37}$ & $2^{37}$ \\ \hline
  Size & $1.4$ GB & $1.4$ GB & $1.4$ GB & $1.4$ GB \\ \hline
  Hash Operations & $90.3$ M & $7.4$ M & $4$ B & $3.5$ B \\ \hline
  Advantages &
  \multicolumn{2}{>{\centering\arraybackslash}m{4.9cm}|}{
    \begin{tabularitemize}
      \item Few hash operations
    \end{tabularitemize}
  } &
  \multicolumn{2}{>{\centering\arraybackslash}m{5.4cm}|}{
    \begin{tabularitemize}
      \item Little disk access
      \item Disk access is serial
      \item Success is guaranteed
      \item Easily parallelizable
    \end{tabularitemize}
  } \\
  \hline
\end{tabular*}

\bigskip

\noindent
\begin{tabular*}{\textwidth}{*{5}{C}}
  \toprule
  & \textbf{Hellman} & \textbf{Rainbow Table} & \textbf{Proposed Method} & \textbf{Proposed Method with Compression} \\
  \midrule
  Input Range & $2^{37}$ & $2^{37}$ & $2^{37}$ & $2^{37}$ \\
  \addlinespace[.5ex]
  Size & $1.4$ GB & $1.4$ GB & $1.4$ GB & $1.4$ GB \\
  \addlinespace[.5ex]
  Hash Operations & $90.3$ M & $7.4$ M & $4$ B & $3.5$ B \\
  \addlinespace[.5ex]
  Advantages &
  \multicolumn{2}{>{\centering\arraybackslash}m{4.9cm}}{
    \begin{itemize}
      \item Few hash operations
    \end{itemize}
  } &
  \multicolumn{2}{>{\centering\arraybackslash}m{5.4cm}}{
    \begin{tabularitemize}
      \item Little disk access
      \item Disk access is serial
      \item Success is guaranteed
      \item Easily parallelizable
    \end{tabularitemize}
  } \\
  \bottomrule
\end{tabularx*}

\end{document}

列表放置在varwidth环境内,以优化它们占用的水平宽度如果比给定的水平宽度短。

booktabs纯粹是为了审美价值。

相关内容