# Specifying one column in a tabulary and keeping total width \textwidth

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.

• hmm that seems wrong. who wrote that package.... – David Carlisle Oct 29 '14 at 21:21

## 1 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)

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

• Thanks so much David. It's so great how nice people are on here. One thing I noticed is that the behavior doesn't quite work right if I specify tymin too large: \setlength{\tymin}{0.25\textwidth} seems to mess your solution up. – kennyB Oct 31 '14 at 6:00
• @kennyB hmm will look later,but tymin=.25\textwidth isn't achievable so best you could hope for there would be some kind of warning. you have 4 LCR columns and if they are all at least .25\textwidth they will total at least \textwidth, then you have 10em from the p column the width of 5 rules, one rule sep and 10 tabcolsep cell padding, all specified to total \textwidth, which can't work..... – David Carlisle Oct 31 '14 at 8:47