[Tex/LaTex] Making table width fit into text width

marginstables

I'm using p{} format to adjust the width of a table.

I expected using {p{0.1\textwidth}||p{0.2\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}} makes the table width smaller than the text width (1 > 0.1 + 0.2*4), but the result is not what I expect.

enter image description here

What might be wrong? Why the total width of the table is wider than text width?

This is the code.

\documentclass[oneside, openany, 10pt]{article}
%\documentclass[article, oneside, openany, 10pt]{memoir}
\newcommand{\HRule}{\rule{1.0\textwidth}{0.5mm}}
\newcommand{\Hrule}{\rule{1.0\textwidth}{0.3mm}}

\makeatletter% since there's an at-sign (@) in the command name
\renewcommand{\@maketitle}{%
  \parindent=0pt% don't indent paragraphs in the title block
  \centering
  {\Large \bfseries\textsc{\@title}}
  \HRule\par%
  \textit{\@author \hfill \@date}
  \par
}
\author{prosseek}
\title{test}

\begin{document}

\maketitle

\begin{table}[hbtp]
\footnotesize
\centering
\begin{tabular}{p{0.1\textwidth}||p{0.2\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}}  
\hline
& Function & Pre conditions & Post conditions & Constraints \\
\hline\hline
R1 & An election official is assigned for each precinct & Precincts and
elections officials are created & Unique one on one mapping from an
election official to precinct & Before voting starts\\  \hline
\end{tabular}
\caption{Requirements before voting starts}
\label{eoRequirements}
\end{table}

\end{document} 

Best Answer

With Mario's hint, I could use tabulary to get this result.

enter image description here

\maketitle
\begin{table}[hbtp]
\footnotesize
\centering
\begin{tabulary}{1.0\textwidth}{C||L|L|L|L}
\hline
& Function & Pre conditions & Post conditions & Constraints \\
\hline\hline
R1 & An election official is assigned for each precinct & Precincts and
elections officials are created & Unique one on one mapping from an
election official to precinct & Before voting starts\\  \hline
\end{tabulary}
\caption{Requirements before voting starts}
\label{eoRequirements}
\end{table}
Related Question