我有一个 LaTeX 问题困扰着我。我一直在尝试让列表环境在表格环境中正确显示。到目前为止,除了一件事之外,我已经得到了我喜欢的一切:列表的顶部与表中的其他条目不对齐,事实上它看起来像是在列表上方添加了一行...我希望将这些列表放在顶部。这就是我所拥有的,一个自定义列表环境:
\newenvironment{flushemize}{
\begin{list}{$\bullet$}
{\setlength{\itemsep}{1pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}
\setlength{\partopsep}{0pt}
\setlength{\topsep}{0pt}
\setlength{\leftmargin}{12pt}}}{\end{list}}
重命名为右边不规则:
\newcommand{\rr}{\raggedright}
这是我的表格:
\begin{table}[H]\caption{Tank comparisons}\label{tab:tanks}
\centering
\rowcolors{2}{white}{tableShade}
\begin{tabular}{p{1in}p{1.5in}p{1.5in}rr}
\toprule
{\bf Material} & {\bf Pros} & {\bf Cons} & {\bf Size} & {\bf Cost} \\
\midrule
\rr Reinforced concrete &\rr \begin{flushemize}\item Strong \item Secure \end{flushemize}&\rr \begin{flushemize}\item Prone to leaks \item Relatively expensive to install \item Heavy \end{flushemize} & 100,000 gal & \$299,400 \\
\rr Steel & \begin{flushemize}\item Strong \item Secure \end{flushemize} & \begin{flushemize}\item Relatively expensive to install \item Heavy \item Require painting to prevent rusting \end{flushemize} & 100,000 gal & \$130,100 \\
\rr Polypropylene & \begin{flushemize}\item Easy to install \item Mobile \item Inexpensive \item Prefabricated \end{flushemize} & \begin{flushemize}\item Relatively insecure \item Max size available 10,000 gal \end{flushemize} & 10,000 gal & \$5,000 \\
\rr Wood & \begin{flushemize}\item Easy to install \item Mobile \item Cheap to install \end{flushemize} & \begin{flushemize}\item Prone to rot \item Must remain full once constructed \end{flushemize} & 100,000 gal & \$86,300\\
\bottomrule
\end{tabular}
\end{table}
谢谢你的建议:)
答案1
这是工作代码。还请阅读 Stefan Kottwitz 上面发布的链接。我还更改了其他一些内容。请不要写{\bf ...}
但\textbf{...}
。请注意新的列类型。阅读手册以array
了解它们。
\documentclass{article}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{array}
% Define your own types for special columns:
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\makeatletter
\newcolumntype{F}[1]{>{\raggedright\arraybackslash\@minipagetrue\flushemize}p{#1}<{\endflushemize}}
\makeatother
\newenvironment{flushemize}{%
% You should put this outside the `list`. The new environment will make them local anyway:
\setlength{\itemsep}{1pt}%
\setlength{\parskip}{0pt}%
\setlength{\parsep}{0pt}%
\setlength{\partopsep}{0pt}%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{12pt}%
% Use \list ... \endlist instead of \begin{list} ... \end{list} inside another environment
\list{$\bullet$}\unskip}
{\endlist}
\begin{document}
\begin{table}[H]% Please don't use 'H' or 'h'.
\centering
\setlength{\belowcaptionskip}{\abovecaptionskip}% Correct skip for caption on top
\caption{Tank comparisons}
\label{tab:tanks}% Yes! The \label comes after \caption, not before
%\rowcolors{2}{white}{tableShade}% Always include all packages in your example
\makebox[\textwidth][c]{% Centers an overwide tabular
\begin{tabular}{P{1in}F{1.5in}F{1.5in}rr}
\toprule
\textbf{Material} & \multicolumn{1}{p{1.5in}}{\textbf{Pros}} & \multicolumn{1}{p{1.5in}}{\textbf{Cons}} & \textbf{Size} & \textbf{Cost} \\
\midrule
Reinforced concrete & \item Strong \item Secure & \item Prone to leaks \item Relatively expensive to install \item Heavy & 100,000 gal & \$299,400 \\
Steel & \item Strong \item Secure & \item Relatively expensive to install \item Heavy \item Require painting to prevent rusting & 100,000 gal & \$130,100 \\
Polypropylene & \item Easy to install \item Mobile \item Inexpensive \item Prefabricated & \item Relatively insecure \item Max size available 10,000 gal & 10,000 gal & \$5,000 \\
Wood & \item Easy to install \item Mobile \item Cheap to install & \item Prone to rot \item Must remain full once constructed & 100,000 gal & \$86,300\\
\bottomrule
\end{tabular}%
}
\end{table}
\end{document}