更改表格单行的行距

更改表格单行的行距

我想更改表格中某一行的行距。我的整个文档都使用了该行距,\linespread{1.3}但这个表格的行距似乎太大了。实际上,我喜欢除第一行之外的所有行都使用这个行距。我发现,通过将其包含\usepackage{setspace}在文档中,表格和浮点数的行距等于 1,而不会更改文档的文本。但我还是不喜欢这样。我想linespread{1}更改第一行、linespread{1.3}其他行和文档的其余部分。

这是我的代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pbox}
\linespread{1.3}

\begin{document}
\begin{table}[!h]
  \begin{center}       
    \begin{tabular}{lcccc} 
    \hline\hline
       Appliance  & \pbox{2cm}{\centering Max power demand (watts)} & \pbox{2cm}{\centering On power threshold (watts)} & \pbox{2cm}{\centering Min. on duration (secs)} & \pbox{2cm}{\centering Min. off duration (secs)}   \\
       \hline
       A & 3100 & 2000 & 12 & 0 \\
       B & 300 & 50 & 60 & 12 \\
       C & 2500 & 20 & 1800 & 160 \\
       D & 3000 & 200 & 12 & 30 \\
       E & 2500 & 10 & 1800 & 1800 \\
           \hline\hline
    \end{tabular}
    \end{center}
\end{table}
\end{document}

答案1

这是一个临时修复:\linespread{1}在需要的地方设置。我踢出了pbox包,array而是加载了,并定义了一个新的列类型,它的作用与您的 es 相同\pbox,但不同\linespread

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\linespread{1.3}
\newcolumntype{M}{>{\linespread{1}\selectfont\centering}m{2cm}}
\begin{document}
\begin{table}[!h]
  \begin{center}       
    \begin{tabular}{lcccc} 
    \hline\hline
       Appliance  & \multicolumn{1}{M}{Max power demand (watts)} & 
       \multicolumn{1}{M}{On power threshold (watts)} & 
       \multicolumn{1}{M}{Min. on duration (secs)} & 
       \multicolumn{1}{M}{Min. off duration (secs)}   
       \\
       \hline
       A & 3100 & 2000 & 12 & 0 \\
       B & 300 & 50 & 60 & 12 \\
       C & 2500 & 20 & 1800 & 160 \\
       D & 3000 & 200 & 12 & 30 \\
       E & 2500 & 10 & 1800 & 1800 \\
           \hline\hline
    \end{tabular}
    \end{center}
\end{table}
\end{document}

在此处输入图片描述

答案2

您可以使用该makecell包调整行间距,以及booktabs可变厚度规则和它们周围的一些垂直填充。另外,不要将环境center用于表格 - 它会增加不必要的垂直间距。请\centering改用:

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage{makecell, booktabs}
\linespread{1.3}

\begin{document}

\begin{table}[!h]
  \centering
   \renewcommand\cellset{\renewcommand{\arraystretch}{0.7}}
    \begin{tabular}{lcccc}
    \toprule\specialrule{0.5pt}{1.5pt}{\belowrulesep}
       Appliance & \makecell{Max power \\ demand \\ (watts)} & \makecell{On power \\ threshold \\ (watts)} & \makecell{Min. on \\ duration \\ (secs)} & \makecell{Min. off \\ duration \\ (secs)} \\
       \cmidrule[0.5pt](lr){1-5}
       A & 3100 & 2000 & 12 & 0 \\
       B & 300 & 50 & 60 & 12 \\
       C & 2500 & 20 & 1800 & 160 \\
       D & 3000 & 200 & 12 & 30 \\
       E & 2500 & 10 & 1800 & 1800 \\
           \specialrule{0.5pt}{\aboverulesep}{1.5pt}\bottomrule
    \end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

编辑

为了获得更宽的表格,您可以创建两行列标题:

 \begin{tabular}{lcccc}
    \toprule\specialrule{0.5pt}{1.5pt}{\belowrulesep}
       Appliance & \makecell{Max power \\ demand (watts)} & \makecell{On power \\ threshold (watts)} & \makecell{Min. on \\ duration (secs)} & \makecell{Min. off \\ duration (secs)} \\
       \cmidrule[0.5pt](lr){1-5}
       A & 3100 & 2000 & 12 & 0 \\
       B & 300 & 50 & 60 & 12 \\
       C & 2500 & 20 & 1800 & 160 \\
       D & 3000 & 200 & 12 & 30 \\
       E & 2500 & 10 & 1800 & 1800 \\
           \specialrule{0.5pt}{\aboverulesep}{1.5pt}\bottomrule
    \end{tabular}

在此处输入图片描述

相关内容