8

I have a LaTeX question that is bugging me. I have been trying to get a list environment to appear correctly inside the tabular environment. So far I have gotten everything to my liking except one thing: the top of the list does not align with other entries in the table, in fact it looks like it adds one line above the list... I would like to have these lists at the top. This is what I have, a custom list environment:

  \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}}

Renamed ragged right:

\newcommand{\rr}{\raggedright}

and here is my table:

\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}

Thank you for any advice :)

2

1 Answer 1

4

Here the working code. Please also read the links Stefan Kottwitz posted above. I also changed a couple of other things. Please do not write {\bf ...} but \textbf{...}. Note the new columns types. Read the manual for array to learn about them.

\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}
4
  • thank you. What's the difference between \textbf{} and {\bf }?
    – Usagi
    Commented Feb 11, 2011 at 22:20
  • 2
    @Usagi: \bf is outdated LaTeX2.09 syntax. It doesn't stack, e.g. {\bf\it Text} does not do bold italic text, but only italic, because the last command overwrites the earlier ones. However, \textbf{\textif{Text}} works. There are also \bfseries and \itshape as well as \ttfamily if you do not want a macro which takes an argument. Commented Feb 11, 2011 at 22:26
  • Is there a similar approach for \begin{enumerate}[label=...] ... \end{enumerate} as well?
    – Cubi73
    Commented Dec 7, 2020 at 14:25
  • @Cubi73: Please post a new question for this. You can link backward to this in the question. Commented Dec 8, 2020 at 8:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .