我正在尝试使用包创建一个表格tabularx
。我希望第一列具有一定的宽度(38 毫米),而所有其他列具有另一个宽度(15 毫米)。但最后一列似乎有一个固定的宽度值,如图 1 所示,无论我为其设置的值是什么。
代码如下:
\documentclass[12pt]{report}
\usepackage{multirow,multicol}
\usepackage{tabularx}
\begin{document}
Some text! Some text! Some text! Some text! Some text! Some text! Some
text! Some text!
\renewcommand{\arraystretch}{1.5}
% Definning column specifications:
\renewcommand{\tabularxcolumn}[1]{>{\normalsize}m{#1}}
\newcolumntype{A}{>{\normalsize\centering\arraybackslash}m{38mm}}
\newcolumntype{B}{>{\normalsize\centering\arraybackslash}m{15mm}}
\begin{table}[!hbt]
\centering
\caption{Shape functions for quadrilateral elements.} \label{tab.:2DQuadShapeFunc}~\\[-3mm]
%\begin{tabular}{lc*{4}c}
\begin{tabularx}{\textwidth}{ABBBBB}
\multicolumn{1}{c}{} & \multicolumn{5}{c}{Included only if node $i$ is defined} \\
\multicolumn{1}{c|}{} & \multicolumn{1}{c|}{$i=5$} & \multicolumn{1}{c|}{$i=6$}
& \multicolumn{1}{c|}{$i=7$} & \multicolumn{1}{c|}{$i=8$}
& \multicolumn{1}{c|}{$i=9$} \\ \hline
\multicolumn{1}{l|}{$h_1=\frac{1}{4}(1-r)(1-s)$} & \multicolumn{1}{c|}{$-\frac{1}{2}h_5$} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_8$} &
\multicolumn{1}{c|}{$-\frac{1}{4}h_9$} \\
\multicolumn{1}{l|}{$h_2=\frac{1}{4}(1+r)(1-s)$} & \multicolumn{1}{c|}{$-\frac{1}{2}h_5$} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_6$} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$-\frac{1}{4}h_9$} \\
\multicolumn{1}{l|}{$h_3=\frac{1}{4}(1+r)(1+s)$} & \multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_6$} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_7$} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{$-\frac{1}{4}h_9$} \\
\multicolumn{1}{l|}{$h_4=\frac{1}{4}(1-r)(1+s)$} & \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{$-\frac{1}{2}h_7$} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_8$} &
\multicolumn{1}{c|}{$-\frac{1}{4}h_9$} \\ \cline{1-1}
$h_5=\frac{1}{2}(1-r^2)(1-s)$ & \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{$-\frac{1}{2}h_9$} \\ \cline{1-2}
$h_6=\frac{1}{2}(1-s^2)(1+r)$ & & \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_9$} \\ \cline{1-3}
$h_7=\frac{1}{2}(1-r^2)(1+s)$ & & & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_9$} \\ \cline{1-4}
$h_8=\frac{1}{2}(1-s^2)(1-r)$ & & &
& \multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_9$} \\ \cline{1-5}
$h_9=(1-r^2)(1-s^2)$ & & &
& & \multicolumn{1}{c|}{}
\\ \hline
\end{tabularx}
\end{table}
\renewcommand{\arraystretch}{1}
Some text! Some text! Some text! Some text! Some text! Some text! Some
text! Some text!
\end{document}
谁能帮我吗?
答案1
不需要tabularx
!您将用 覆盖每一行的最后一列规范c
,它不使用 的原因是m{1.5cm}
:
\documentclass[12pt]{report}
\usepackage{multirow,multicol}
\usepackage{ragged2e,array}
\begin{document}
Some text! Some text! Some text! Some text! Some text! Some text! Some
text! Some text!
\renewcommand{\arraystretch}{1.5}
\newcolumntype{A}{>{\Centering}m{38mm}}
\newcolumntype{B}{>{\Centering}m{15mm}}
\begin{table}[!hbt]
\centering
\caption{Shape functions for quadrilateral elements.}\label{tab.:2DQuadShapeFunc}~\\[-3mm]
%\begin{tabular}{lc*{4}c}
\begin{tabular}{A*5B | }
& \multicolumn{5}{c}{Included only if node $i$ is defined} \\
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$i=5$} & \multicolumn{1}{c|}{$i=6$}
& \multicolumn{1}{c|}{$i=7$} & \multicolumn{1}{c|}{$i=8$}
& $i=9$ \\ \hline
\multicolumn{1}{l|}{$h_1=\frac{1}{4}(1-r)(1-s)$} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_5$} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_8$} &
$-\frac{1}{4}h_9$ \\
\multicolumn{1}{l|}{$h_2=\frac{1}{4}(1+r)(1-s)$} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_5$} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_6$} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} &
$-\frac{1}{4}h_9$ \\
\multicolumn{1}{l|}{$h_3=\frac{1}{4}(1+r)(1+s)$} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_6$} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_7$} & \multicolumn{1}{c|}{}
& $-\frac{1}{4}h_9$ \\
\multicolumn{1}{l|}{$h_4=\frac{1}{4}(1-r)(1+s)$} &
\multicolumn{1}{c|}{} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{$-\frac{1}{2}h_7$} &
\multicolumn{1}{c|}{$-\frac{1}{2}h_8$} &
$-\frac{1}{4}h_9$ \\ \cline{1-1}
$h_5=\frac{1}{2}(1-r^2)(1-s)$ &
\multicolumn{1}{c|}{} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{}
& $-\frac{1}{2}h_9$ \\ \cline{1-2}
$h_6=\frac{1}{2}(1-s^2)(1+r)$
& &
\multicolumn{1}{c|}{} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} &
$-\frac{1}{2}h_9$ \\ \cline{1-3}
$h_7=\frac{1}{2}(1-r^2)(1+s)$
& & &
\multicolumn{1}{c|}{}
& \multicolumn{1}{c|}{} &
$-\frac{1}{2}h_9$ \\ \cline{1-4}
$h_8=\frac{1}{2}(1-s^2)(1-r)$ & & & &\multicolumn{1}{c|}{} & $-\frac{1}{2}h_9$ \\
\cline{1-5}
$h_9=(1-r^2)(1-s^2)$
& &
&
& & \\ \hline
\end{tabular}
\end{table}
\renewcommand{\arraystretch}{1}
Some text! Some text! Some text! Some text! Some text! Some text! Some
text! Some text!
\end{document}
也许定义垂直线然后在\multicolumn
不应该出现的地方使用它更容易!这里我展示了前七行:
\documentclass[12pt]{report}
\usepackage{multirow,multicol}
\usepackage{ragged2e,array}
\begin{document}
Some text! Some text! Some text! Some text! Some text! Some text! Some
text! Some text!
\renewcommand{\arraystretch}{1.5}
\newcolumntype{A}{m{38mm}}
\newcolumntype{B}{>{\Centering}m{15mm}}
\let\MC\multicolumn
\begin{table}[!hbt]
\centering
\caption{Shape functions for quadrilateral elements.}\label{tab.:2DQuadShapeFunc}~\\[-3mm]
%\begin{tabular}{lc*{4}c}
\begin{tabular}{A | *5{B|} }
\MC{1}{c}{} & \multicolumn{5}{c}{Included only if node $i$ is defined} \\
& $i=5$ & $i=6$ & $i=7$ & $i=8$ & $i=9$ \\ \hline
$h_1=\frac{1}{4}(1-r)(1-s)$ & $-\frac{1}{2}h_5$ & & & $-\frac{1}{2}h_8$ &
$-\frac{1}{4}h_9$ \\
$h_2=\frac{1}{4}(1+r)(1-s)$ & $-\frac{1}{2}h_5$ & $-\frac{1}{2}h_6$ & & &
$-\frac{1}{4}h_9$ \\
$h_3=\frac{1}{4}(1+r)(1+s)$ & & $-\frac{1}{2}h_6$ & $-\frac{1}{2}h_7$ & &
$-\frac{1}{4}h_9$ \\
$h_4=\frac{1}{4}(1-r)(1+s)$ & & & $-\frac{1}{2}h_7$ & $-\frac{1}{2}h_8$ &
$-\frac{1}{4}h_9$ \\ \cline{1-1}
\MC{1}{l}{$h_5=\frac{1}{2}(1-r^2)(1-s)$} & & & & & $-\frac{1}{2}h_9$ \\ \cline{1-2}
\MC{1}{l}{$h_6=\frac{1}{2}(1-s^2)(1+r)$} & \MC{1}{c}{} & & & & $-\frac{1}{2}h_9$ \\
\cline{1-3}
\MC{1}{l}{$h_7=\frac{1}{2}(1-r^2)(1+s)$} & \MC{1}{c}{}& \MC{1}{c}{}& & &
$-\frac{1}{2}h_9$ \\ \cline{1-4}
\end{tabular}
\end{table}
\renewcommand{\arraystretch}{1}
Some text! Some text! Some text! Some text! Some text! Some text! Some
text! Some text!
\end{document}
答案2
:tabularx
第一列宽度设置为所需的 38 毫米(不过,我的意见是最好使用列类型l
,其余列的宽度留给tabularx
计算:
\documentclass[12pt]{report}
\usepackage{makecell, multirow, tabularx}
\setcellgapes{3pt}
\let\MC\multicolumn
\usepackage{lipsum}
\begin{document}
\lipsum[11]
\begin{table}[!hbt]
\centering
\caption{Shape functions for quadrilateral elements.}
\label{tab.:2DQuadShapeFunc}
\makegapedcells
\begin{tabularx}{\linewidth}{>{\centering $}p{38 mm}<{$} |
*{5}{>{\centering\arraybackslash $}X<{$}|}}
\MC{1}{c}{} & \MC{5}{c}{Included only if node i is defined} \\
& i=5 & i=6 & i=7 & i=8 & i=9 \\
\hline
h_1=\frac{1}{4}(1-r)(1-s)
& -\frac{1}{2}h_5 & & & -\frac{1}{2}h_8 & -\frac{1}{4}h_9 \\
h_2=\frac{1}{4}(1+r)(1-s)
& -\frac{1}{2}h_5 & -\frac{1}{2}h_6 & & & -\frac{1}{4}h_9 \\
h_3=\frac{1}{4}(1+r)(1+s)
& & -\frac{1}{2}h_6 & -\frac{1}{2}h_7 & & -\frac{1}{4}h_9 \\
h_4=\frac{1}{4}(1-r)(1+s)
& & & -\frac{1}{2}h_7 & -\frac{1}{2}h_8 & -\frac{1}{4}h_9 \\
\cline{1-1}
\MC{1}{l}{$h_5=\frac{1}{2}(1-r^2)(1-s)$}
& & & & & -\frac{1}{2}h_9 \\
\cline{1-2}
\MC{1}{l}{$h_6=\frac{1}{2}(1-s^2)(1+r)$}
& \MC{1}{c}{} & & & & -\frac{1}{2}h_9 \\
\cline{1-3}
\MC{1}{l}{$h_7=\frac{1}{2}(1-r^2)(1+s)$}
& \MC{2}{c}{} & & & -\frac{1}{2}h_9 \\
\cline{1-4}
\end{tabularx}
\end{table}
\lipsum[12]
\end{document}
\makegapedcells
为了在单元格中使用更多的垂直空间,从包中使用宏makecell
,删除了列定义(因为它们没有使用)
笔记:
- 如果你使用
tabularx
至少一个列必须是X
类型 - 由于宏
\makegapedcells
与列类型不兼容,因此删除了列m
的重新定义。X
\renewcommand{\tabularxcolumn}[1]{>{\normalsize}m{#1}}
- 如果新命令旨在全局使用(在整个文档中),则应在序言中定义它们(这样更容易找到它们),如果它们仅在环境中有效,则在本地定义它们是合理的,在哪里定义