5

I have a few questions about tables that are probably pretty basic. Here is the code for my table.

\begin{table}
  \begin{tabular}{| r | l | l |}
    \hline
    \textbf{Species} & \textbf{Abbrev.} & \textbf{Common Name} \\ \hline
    \textit{Arabidopsis thaliana} & At & Thale cress \\
    \textit{Oryza sativa} & Os & Rice \\
    \textit{Brachypodium distachyon} & Bd & Purple false brome \\
    \textit{Glycine max} & Gm & Soybean \\
    \textit{Vitis vinifera} & Vv & Grape \\
    \textit{Sorghum bicolor} & Sb & Sorghum \\
    \textit{Medicago truncatula} & Mt & Barrel clover \\
    \textit{Zea mays} & Zm & Maize \\ \hline
  \end{tabular}
  \caption{This study presents a comprehensive analysis of the intron distribution in these 8 model plant species.}
\end{table}

Here are my questions.

  1. How can I change the alignment of the first row of headers (center) without affecting the alignment of the subsequent rows?
  2. How can I add space between the bottom of the table and the caption? The caption text is right up against the bottom of the table.
  3. How can I horizontally center this table in the available space? I tried the \begin{center} environment but that did not work.

4 Answers 4

7
  1. It's a bit of a hack, but you could use the multirow package, and just use a multicolumn with colspan 1 that centers its content.

  2. Why not just add another table row? Again, using the multirow package you can alter the column separators for a single row - in this case removing them and just adding a row of whitespace.

  3. Add \centering at the top of your table float:

    \begin{table}
    \centering
    ...
    
5
  • 3
    Good! However, the multicol package is not required, \multicolumn is part of standard LaTeX. multicol is for non-tabular text in columns.
    – Stefan Kottwitz
    Dec 14, 2010 at 21:53
  • Thanks. I'm going to be picky here! Regarding your solution to 2, Is there a way that I can control the height of this row? The default row height is a bit more than I would like. Dec 14, 2010 at 22:10
  • @Stefan: You're right about the multicol package - I seem to always mix it up with the multirow package, since I mostly use multirow for colspans :P However, I've never been able to do multi-column cells in tabular environments without the multirow package. Dec 15, 2010 at 13:11
  • 2
    @Daniel: You could try adding \small or \tiny to affect the font size - that should probably make the entire row smaller in height. Another option is of course to use a \vspace{3mm} between the tabular environment and the caption (instead of the empty row, that is), but my knowledge of floats is too limited to know if that will suit your needs. Dec 15, 2010 at 13:13
  • The vspace suggestion worked perfectly. Thanks! Dec 15, 2010 at 21:16
6

Thomas's suggestion of using \multicolumn is the right way to go for the first question.

For the second, you could use the caption package. In particular the skip option controls the vertical space between the table and the caption.

For the third, \centering is the right way to go, but as Matthew pointed out, if your table is too wide, it won't be centered. One way to solve this is to do something like

\hbox to\linewidth{\hfil\begin{tabular}{...} ... \end{tabular}\hfil}

Finally, for the question you didn't ask, you should consider reading the booktabs documentation. I've found that it produces nicer looking tables than you get using the LaTeX defaults. It also contains a number of helpful rules to making publication-quality tables such as never use vertical rules and never use doubled rules.

2

The usual cause of tables not centering is an overfull \hbox. Search this site for questions about centering and you should find some solutions. This one: Center flow chart horizontally is pretty useful.

2

alt text

\documentclass[final,cmyk,table]{article}
\usepackage%
[%
margin=1cm%
]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{array}
\usepackage{longtable}
\usepackage{calc}

\makeatletter
\newcommand\ratio[2]{%
  \strip@pt\dimexpr#1pt/#2\relax
}
\makeatother  


\setlength{\arrayrulewidth}{0.4pt}%border width
\setlength{\tabcolsep}{5pt}%padding 
\arrayrulecolor{red}%frame color

\newcolumntype{S}[1]%
{%
        >{%
            \begin{minipage}%
        {%
                #1\linewidth-2\tabcolsep-2\arrayrulewidth%
        }%
        \vspace{\tabcolsep}%
    }%
    c%
    <{%
            \vspace{\tabcolsep}%
        \end{minipage}%
    }%
}%

\newcolumntype{O}[1]%
{%
        >{%
            \begin{minipage}%
        {%
                #1\linewidth-2\tabcolsep-1.5\arrayrulewidth%
        }%
        \vspace{\tabcolsep}%
    }%
    c%
    <{%
            \vspace{\tabcolsep}%
        \end{minipage}%
    }%
}%

\newcolumntype{I}[1]%
{%
        >{%
            \begin{minipage}%
        {%
                #1\linewidth-2\tabcolsep-\arrayrulewidth%
        }%
        \vspace{\tabcolsep}%
    }%
    c%
    <{%
            \vspace{\tabcolsep}%
        \end{minipage}%
    }%
}%



\newenvironment{MyTable}[4]%
{%    
    \begin{longtable}%
    {%
        |>{\raggedleft\textit\bgroup}O{\ratio{#2}{#1}}<{\egroup}%
        |>{}I{\ratio{#3}{#1}}<{}%
        |>{}O{\ratio{#4}{#1}}<{}%
        |%
    }%
    \hline\ignorespaces%
}%
{%
    \end{longtable}%
}

\begin{document}

\begin{table}
    %HORIZONTAL fraction distribution:
    %margin left        : 1 
    %margin right       : 1
    %first column       : 4
    %second column  : 1
    %third column       : 2
    %TOTAL                  : 9

    %format: {Total}{first}{second}{third}
  \begin{MyTable}{9}{4}{1}{2}   
        ~\hfill\bf Species\hfill~ & ~\hfill\bf Abbrev.\hfill~ &~\hfill\bf Common Name\hfill~\tabularnewline\hline
        Arabidopsis thaliana            & At            & Thale cress \tabularnewline
        Oryza sativa                            & Os            & Rice \tabularnewline
        Brachypodium distachyon     & Bd            & Purple false brome \tabularnewline
        Glycine max                             & Gm            & Soybean \tabularnewline
        Vitis vinifera                      & Vv            & Grape \tabularnewline
        Sorghum bicolor                     & Sb            & Sorghum \tabularnewline
        Medicago truncatula             & Mt            & Barrel clover \tabularnewline
        Zea mays                                    & Zm            & Maize \tabularnewline
        \hline
  \end{MyTable}
  \caption{This study presents a comprehensive analysis of the intron distribution in these 8 model plant species.}
\end{table}

\end{document}

You must log in to answer this question.

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