6

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} 
1
  • 3
    Because you are not counting some other spaces (such as tabcolsep). You could work around this by using either tabulary or tabularx... or simply considering the missing space (check the array documentation ) Commented Sep 27, 2013 at 15:40

1 Answer 1

5

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} 
1
  • I think you should write it like 1.0*\textwidth Commented Apr 30, 2015 at 3:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.