Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.
share|improve this question
add comment

4 Answers

up vote 7 down vote accepted
  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
    ...
    
share|improve this answer
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 '10 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. –  Daniel Standage Dec 14 '10 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. –  Tomas Lycken Dec 15 '10 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. –  Tomas Lycken Dec 15 '10 at 13:13
    
The vspace suggestion worked perfectly. Thanks! –  Daniel Standage Dec 15 '10 at 21:16
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.