[Tex/LaTex] Specifying one column in a tabulary and keeping total width \textwidth

tablestabulary

My question closely relates to this: Making table width fit into text width.

The answer's code is:

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

What I would like to do is specify the width of one of the columns using, for example:

\maketitle
\begin{table}[hbtp]
\footnotesize
\centering
\begin{tabulary}{1.0\textwidth}{C||L|L|L|p{10em}}
\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}

This seems to make the total table width larger than \textwidth. How can I get the table width to remain at \textwidth while also specifying 1 or more column widths with p{.}? Thanks so much for any replies.

Best Answer

a p column is more or less just a column with a \parbox and fortunately \parbox works as expected. (The behaviour of the p columns seems slightly unexpected)

enter image description here

\documentclass{article}
\usepackage{tabulary}
\setlength\extrarowheight{2pt}
\begin{document}

\begin{table}[hbtp]
\footnotesize
\centering
\begin{tabulary}{1.0\textwidth}{C||L|L|L|l}
\hline
& Function & Pre conditions & Post conditions & \parbox{10em}{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 & \parbox{10em}{Before voting starts}\\  \hline
\end{tabulary}
\caption{Requirements before voting starts}
\label{eoRequirements}
\end{table}

\noindent X\dotfill X

\end{document}

To use p columns I think the required fix is as below:

\documentclass{article}
\usepackage[debugshow]{tabulary}
\setlength\extrarowheight{2pt}

\makeatletter
\def\z#14#2!!{\def\TY@classz{#17#2}}
\expandafter\z\TY@classz!!
\makeatother

\begin{document}

\begin{table}[hbtp]
\footnotesize
\centering
\begin{tabulary}{1.0\textwidth}{C||L|L|L|p{10em}}
\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}

\noindent X\dotfill X

\end{document}