指定表格中的一列并保持总宽度 \textwidth

指定表格中的一列并保持总宽度 \textwidth

我的问题与此密切相关:使表格宽度适合文本宽度

答案的代码是:

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

我想要做的是使用以下方法指定其中一列的宽度,例如:

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

这似乎使总表格宽度大于 \textwidth。如何让表格宽度保持在 \textwidth,同时使用 p{.} 指定 1 个或多个列宽?非常感谢您的回复。

答案1

p列或多或少只是一列,\parbox幸运的是,它\parbox按预期工作。(列的行为p似乎有点出乎意料)

在此处输入图片描述

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

要使用p列,我认为所需的修复如下:

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

相关内容