如何在 tabularx 表中垂直拉伸每一行或整个表格

如何在 tabularx 表中垂直拉伸每一行或整个表格

我希望我的 LaTeX 制作的表格看起来垂直拉伸更多,这样它就不会显得垂直紧凑。我希望它看起来更像 google docs 的版本(见图)。我该怎么做呢?

\usepackage{tabularx} 
\usepackage{booktabs}
\usepackage{array

\begin{center}
\begin{tabularx}{\textwidth}{ 
   >{\raggedright\arraybackslash\hsize=0.348\hsize}X 
   >{\centering\arraybackslash\hsize=0.1\hsize}X
   >{\raggedleft\arraybackslash\hsize=0.138\hsize}X 
   >{\raggedleft\arraybackslash\hsize=0.138\hsize}X 
   >{\raggedleft\arraybackslash\hsize=0.138\hsize}X 
   >{\raggedleft\arraybackslash\hsize=0.138\hsize}X }
    \setlength\cellspacetoplimit{6pt}
    \setlength\cellspacebottomlimit{6pt}
  & & Unrestricted Funds 2019 & Restricted Funds 2019 & Total Funds 2019 & Total Funds 2018\\
  & \small{Note} & £ & £ & £ & £\\
  \textsc{Income} &&&&&\\ 
  \hspace{3mm} Voluntary Income & \footnotesize{2} & 43,933 & - & 43,933 & 36,196\\
  \hspace{3mm} Investment Income & \footnotesize{2} & - & - & - & 31\\
  \hspace{3mm} Charitable Activities & \footnotesize{2} & 597 & - & 597 & 530\\ \cmidrule{3-6}
  \textsc{Total Income} && 44,530 & - & 44,530 & 36,757\\[10mm]
  \textsc{Expenditure} &&&&&\\
  \hspace{3mm} Charitable Activities & \footnotesize{3,4,5,6} & 39,359 & - & 39,359 & 28,343\\
  \hspace{3mm} Governance Costs & \footnotesize{4} & 412 & - & 412 & 110\\ \cmidrule{3-6}
  \textsc{Total Expenditure} && 39,771 & - & 39,771 & 28,453\\[10mm]
  \textsc{Net Income (Expenditure)} && 4,759 & - &4,759 & 8,304\\
  \textsc{Net Movement in Funds} && 4,759 & - &4,759 & 8,304\\[10mm]
  \textsc{Reconciliation of Funds} &&&&&\\
  Total Funds Brought Forward && 35,356 & - &35,356 & 27,052\\
  Total Funds Carried Forward && 40,115 & - &40,115 & 35,356\\ \cmidrule{3-6}
\end{tabularx}
\end{center}

Tabularx Latex


Google Docs 版本: 谷歌文档

答案1

您为 定义了值\cellspacetop/bottomlimits,这没问题,因为单元格内容将垂直居中。但是您没有加载cellspace定义这些长度的包。此外,单元格将具有此垂直填充的列必须以字母作为前缀S(或者C如果您加载siunitx)。它适用于所有标准说明符,但不适用于X列类型,必须将其添加到可识别说明符列表中。

所以这里有一个可以运行的代码。我借此机会简化了您的代码。请注意,您不必array在加载时加载tabularx - 后者会为您完成。此外,您对系数的计算\hsize=...是错误的。它们不是完全的比例系数,因为它们必须加起来等于总列数X,而是重心坐标。

\documentclass{article}
\usepackage{geometry} 
\usepackage{tabularx,booktabs, cellspace}
\setlength\cellspacetoplimit{6pt}
\setlength\cellspacebottomlimit{6pt}
\addparagraphcolumntypes{X}

\begin{document}

\begin{center}%\footnotesize
\setlength{\tabcolsep}{4pt}\small
\begin{tabularx}{\textwidth}{
@{} S{>{\raggedright\arraybackslash\hsize=2\hsize}X}
   >{\centering\arraybackslash\hsize=0.48\hsize}X
   *{4}{>{\raggedleft\arraybackslash\hsize=0.88\hsize}X}}
& &\multicolumn{2}{c}{ Funds 2019 } & \multicolumn{2}{c}{Total} \\[-0.5ex]
\cmidrule(lr){3-4} \cmidrule(lr){5-6}
  & & Unrestricted& Restricted & Funds 2019 & Funds 2018\\
  & \small{Note} & £ & £ & £ & £\\
  \textsc{Income} &&&&&\\
  \hspace{3mm} Voluntary Income & \footnotesize{2} & 43,933 & - & 43,933 & 36,196\\
  \hspace{3mm} Investment Income & \footnotesize{2} & - & - & - & 31\\
  \hspace{3mm} Charitable Activities & \footnotesize{2} & 597 & - & 597 & 530\\ \cmidrule(l){3-6}
  \textsc{Total Income} && 44,530 & - & 44,530 & 36,757\\[10mm]
  \textsc{Expenditure} &&&&&\\
  \hspace{3mm} Charitable Activities & \footnotesize{3,4,5,6} & 39,359 & - & 39,359 & 28,343\\
  \hspace{3mm} Governance Costs & \footnotesize{4} & 412 & - & 412 & 110\\ \cmidrule(l){3-6}
  \textsc{Total Expenditure} && 39,771 & - & 39,771 & 28,453\\[10mm]
  \textsc{Net Income (Expenditure)} && 4,759 & - &4,759 & 8,304\\
  \textsc{Net Movement in Funds} && 4,759 & - &4,759 & 8,304\\[10mm]
  \textsc{Reconciliation of Funds} &&&&&\\
  Total Funds Brought Forward && 35,356 & - &35,356 & 27,052\\
  Total Funds Carried Forward && 40,115 & - &40,115 & 35,356\\ \cmidrule(l){3-6}
\end{tabularx}
\end{center}

\end{document} 

在此处输入图片描述

答案2

设置\renewcommand{\arraystretch}{1.5}

\documentclass[a4paper]{article}
\usepackage{tabularx} 
\usepackage{booktabs}
\usepackage{array}
\begin{document}

\renewcommand{\arraystretch}{1.5}

\begin{center}
\begin{tabularx}{\textwidth}{ 
   >{\raggedright\arraybackslash\hsize=0.348\hsize}X 
   >{\centering\arraybackslash\hsize=0.1\hsize}X
   >{\raggedleft\arraybackslash\hsize=0.138\hsize}X 
   >{\raggedleft\arraybackslash\hsize=0.138\hsize}X 
   >{\raggedleft\arraybackslash\hsize=0.138\hsize}X 
   >{\raggedleft\arraybackslash\hsize=0.138\hsize}X }

  & & Unrestricted Funds 2019 & Restricted Funds 2019 & Total Funds 2019 & Total Funds 2018\\
  & \small{Note} & £ & £ & £ & £\\
  \textsc{Income} &&&&&\\ 
  \hspace{3mm} Voluntary Income & \footnotesize{2} & 43,933 & - & 43,933 & 36,196\\
  \hspace{3mm} Investment Income & \footnotesize{2} & - & - & - & 31\\
  \hspace{3mm} Charitable Activities & \footnotesize{2} & 597 & - & 597 & 530\\ \cmidrule{3-6}
  \textsc{Total Income} && 44,530 & - & 44,530 & 36,757\\[10mm]
  \textsc{Expenditure} &&&&&\\
  \hspace{3mm} Charitable Activities & \footnotesize{3,4,5,6} & 39,359 & - & 39,359 & 28,343\\
  \hspace{3mm} Governance Costs & \footnotesize{4} & 412 & - & 412 & 110\\ \cmidrule{3-6}
  \textsc{Total Expenditure} && 39,771 & - & 39,771 & 28,453\\[10mm]
  \textsc{Net Income (Expenditure)} && 4,759 & - &4,759 & 8,304\\
  \textsc{Net Movement in Funds} && 4,759 & - &4,759 & 8,304\\[10mm]
  \textsc{Reconciliation of Funds} &&&&&\\
  Total Funds Brought Forward && 35,356 & - &35,356 & 27,052\\
  Total Funds Carried Forward && 40,115 & - &40,115 & 35,356\\ \cmidrule{3-6}
\end{tabularx}
\end{center}
\end{document}

相关内容