我有一些列,第一列有非常短的条目,而第二列有相当长的条目。
\begin{ctabular}{\textwidth}{ll}
\toprule
Name & Recipe\\
\midrule
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
\bottomrule
\end{ctabular}
该表实际上有很多行,并且跨越多页,这就是我使用ctabular
(来自memoir
类)的原因。我想将表的宽度设置为\textwidth
。我会对 LaTeX 为第一列选择的任何内容感到满意,以便将名称放在一行中,并希望第二列占据剩余的空间。我该如何实现这一点?
我不想单独设置每列的大小,这样当我添加具有较长名称的新行或更改字体大小时它不会中断。
答案1
您可以借助该eqparbox
包来实现这一点。其文档中实际上有一个该类型的示例,但它使用的是自定义列表环境,而不是表格环境。
在下面我使用了 also ,因为出于我不知道的原因,当我尝试使用水平规则longtable
执行完全相同的操作时,结果出现了错误。用替换解决了这个问题。需要运行两次才能使表格正确。ctabular
ctabular
longtable
\documentclass{memoir}
\usepackage{eqparbox}
\usepackage{longtable}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
\newsavebox{\firstentrybox}
\newcolumntype{S}{%
>{\begin{lrbox}{\firstentrybox}}%
l%
<{\end{lrbox}%
\eqmakebox[firstentry][l]{\unhcopy\firstentrybox}}}
\begin{longtable}{S p{\dimexpr(\textwidth-\eqboxwidth{firstentry}-4\tabcolsep)}}
\toprule
Name & Recipe\\
\midrule
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Freezing media & 91\% FCS; 10\% DMSO \\
Growth medium (HeLa) & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
Growth medium (horse) & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
\bottomrule
\end{longtable}
\end{document}