我试图同时使用makecell
(实现单元格内换行)和tabulary
(使表格不超过\linewidth
)来实现“threeparttables”。但是,虽然我可以tabulary
使用不使用 来实现 threeparttables makecell
(下面的第一个代码示例)和使用但不tabulary
使用 的表格(下面的第二个代码示例),但我无法构建结合这三个的文档(第三个示例)。该怎么办?makecell
threeparttable
我知道使用tabularx
而不是tabulary
会构建这个特定的表,但我有很多这样的表。我宁愿不单独检查每个表,而是使用tabulary
。另外,我并不习惯使用makecell
,但我需要能够在单元格内进行换行(并控制它们的垂直对齐)。
任何帮助将非常感激!
第一个例子(threeparttable
但tabular
不是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}
第二个例子(tabulary
但makecell
没有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}