I like to use a table layout where the width of the table is fixed to 7cm. I can do this using:
\documentclass{book}
\usepackage{array,tabularx}
\newcolumntype{+}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces}
\makeatletter
\g@addto@macro\@floatboxreset{\centering\sffamily\small}
\makeatother
\begin{document}
\begin{table}
\begin{tabular*}{7cm}{@{\extracolsep{\fill}}|>{\bfseries}+l|^c|^c|}
\hline\rowstyle{\bfseries}%
& property & number \\ \hline
Something & yes & 1554 \\
Item & no & 2 \\ \hline
\end{tabular*}\\
\vspace{.5cm}
\newcolumntype{;}{l@{}}% dummy column
\begin{tabular*}{7cm}{@{\extracolsep{\fill}}|;>{\bfseries}+l;|^c;|^c;|}
\hline\rowstyle{\bfseries}%
& && property && number & \\ \hline
&Something && yes && 1554 & \\
&Item && no && 2 & \\ \hline
\end{tabular*}\\
\vspace{.5cm}
\newcolumntype{;}{X@{}}% dummy column
\begin{tabularx}{7cm}{|+;>{\bfseries}l;|;^c;|;^c;|}
\hline\rowstyle{\bfseries}%
& &&& property &&& number & \\ \hline
&Something &&& yes &&& 1554 & \\
&Item &&& no &&& 2 & \\ \hline
\end{tabularx}\\
\vspace{.5cm}
\setlength{\tabcolsep}{.52cm}
\begin{tabular}{|>{\bfseries}+l|^c|^c|}
\hline\rowstyle{\bfseries}%
& property & number \\ \hline
Something & yes & 1554 \\
Item & no & 2 \\ \hline
\end{tabular}
\end{table}
\end{document}
In the code, the first table doesn't align nicely. The second and third table require the use complex code for formatting the table in the document. Where I'd rather separate the formatting from the contents. The fourth example works nicely, but requires manual tuning of tabcolsep.
How should I define a tabular environment that dynamically increases the cell margins to obtain the desired table width?





tabularxpackage, seetexdoc tabularx. – Christoph Sep 20 '13 at 11:14Xcolumns to get evenly distributed space across columns. – Heiko Oberdiek Sep 20 '13 at 11:26tabularxortabularypackages, but the space added by\extracolsepis evenly distributed if you add a final@{}after the|to match the@{}at the start. (or use!instead of@so it does not remove the\tabcolsepat that point. – David Carlisle Sep 20 '13 at 11:28