不能同时使用 makecell、threeparttable 和 tabulary

不能同时使用 makecell、threeparttable 和 tabulary

我试图同时使用makecell(实现单元格内换行)和tabulary(使表格不超过\linewidth)来实现“threeparttables”。但是,虽然我可以tabulary使用不使用 来实现 threeparttables makecell(下面的第一个代码示例)和使用但不tabulary使用 的表格(下面的第二个代码示例),但我无法构建结合这三个的文档(第三个示例)。该怎么办?makecellthreeparttable

我知道使用tabularx而不是tabulary会构建这个特定的表,但我有很多这样的表。我宁愿不单独检查每个表,而是使用tabulary。另外,我并不习惯使用makecell,但我需要能够在单元格内进行换行(并控制它们的垂直对齐)。

任何帮助将非常感激!

第一个例子threeparttabletabular不是makecell

\documentclass{article}
\usepackage[para]{threeparttable}
\usepackage{tabulary}
\begin{document}
  \begin{table}
    \begin{threeparttable}
      \caption{Lorem ipsum dolor sit amet, consectetur}

      {
        \begin{tabulary}{\linewidth}{L r L r}
        \textbf{Aaa} & \textbf{Bbb} & \textbf{Ccc} \tabularnewline
         & & Ccc1 & Ccc2 \tabularnewline
        Adipisicing elit, sed do eiusmod tempor & \(0.40\) & Ut labore et dolore magna aliqua & \(7.77\) \tabularnewline
        Ut enim ad minim veniam, quis nostrud exercitation & \(0.93\) & Ullamco laboris nisi ut aliquip ex ea commodo consequat & \(62.6\) \tabularnewline
        \end{tabulary}
      }
    \end{tablenotes}
  \end{threeparttable}
\end{document}

第二个例子tabularymakecell没有threeparttable

\documentclass{article}
\usepackage{tabulary}
\usepackage{makecell}
\begin{document}
  \begin{table}
    \caption{Lorem ipsum dolor sit amet, consectetur}

    {
      \begin{tabulary}{\linewidth}{L r L r}
      \textbf{Aaa} & \textbf{Bbb} & \textbf{Ccc} \tabularnewline
       & & \makecell{Ccc1} & \makecell{Ccc2 \\ Ccc2} \tabularnewline
      Adipisicing elit, sed do eiusmod tempor & \(0.40\) & Ut labore et dolore magna aliqua & \(7.77\) \tabularnewline
      Ut enim ad minim veniam, quis nostrud exercitation & \(0.93\) & Ullamco laboris nisi ut aliquip ex ea commodo consequat & \(62.6\) \tabularnewline
      \end{tabulary}
    }
  \end{table}
\end{document}

第三个例子(三者皆无效)

\documentclass{article}
\usepackage[para]{threeparttable}
\usepackage{tabulary}
\usepackage{makecell}
\begin{document}
  \begin{table}
    \begin{threeparttable}
      \caption{Lorem ipsum dolor sit amet, consectetur}

      {
        \begin{tabulary}{\linewidth}{L r L r}
        \textbf{Aaa} & \textbf{Bbb} & \textbf{Ccc} \tabularnewline
         & & \makecell{Ccc1} & \makecell{Ccc2 \\ Ccc2} \tabularnewline
        Adipisicing elit, sed do eiusmod tempor & \(0.40\) & Ut labore et dolore magna aliqua & \(7.77\) \tabularnewline
        Ut enim ad minim veniam, quis nostrud exercitation & \(0.93\) & Ullamco laboris nisi ut aliquip ex ea commodo consequat & \(62.6\) \tabularnewline
        \end{tabulary}
      }

      \begin{tablenotes}
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      \end{tablenotes}
    \end{threeparttable}
  \end{table}
\end{document}

答案1

您可以\makecell\Centerstack中的命令进行替换stackengine,该命令与其他包不冲突:

\usepackage[latin]{babel} 
\usepackage[para]{threeparttable}
\usepackage{tabulary}
\usepackage[usestackEOL]{stackengine}

\begin{document}

  \begin{table}
    \begin{threeparttable}
      \caption{Lorem ipsum dolor sit amet, consectetur}

      {
        \begin{tabulary}{\linewidth}{L r L r}
        \textbf{Aaa} & \textbf{Bbb} & \textbf{Ccc} \tabularnewline
         & & \Centerstack{Ccc1} & \Centerstack{Ccc2\\ Ccc2} \tabularnewline
        Adipisicing elit, sed do eiusmod tempor & \(0.40\) & Ut labore et dolore magna aliqua & \(7.77\) \tabularnewline
        Ut enim ad minim veniam, quis nostrud exercitation & \(0.93\) & Ullamco laboris nisi ut aliquip ex ea commodo consequat & \(62.6\) \tabularnewline
        \end{tabulary}
      }

      \begin{tablenotes}\footnotesize
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      \end{tablenotes}
    \end{threeparttable}
  \end{table}

\end{document} 

在此处输入图片描述

相关内容