![倒金字塔标题,但表格未居中](https://linux22.com/image/331665/%E5%80%92%E9%87%91%E5%AD%97%E5%A1%94%E6%A0%87%E9%A2%98%EF%BC%8C%E4%BD%86%E8%A1%A8%E6%A0%BC%E6%9C%AA%E5%B1%85%E4%B8%AD.png)
我设法想出了一个办法,解决了“我的大学要求使用倒金字塔式标题”这个老问题。但是,这个办法并不完善。我可以将标题设为倒金字塔式,也可以让它们随表格宽度缩放(这也是一个要求)。但是,如果表格比最小标题宽度窄,表格将不再位于标题下方的中央。
我使用 caption 包来定义自定义对齐方式(InvertedPyramid)。threeparttable 重新定义 \linewidth 以匹配当前表格,这就是 InvertedPyramid 对齐方式的缩放方式。将 TPTminimum 设置为 3 英寸可防止窄表格的标题看起来不合理。但是,当表格宽度小于 3 英寸时,它不再位于标题下方的中央。我尝试过 \makebox 解决方案,但结果却出现了错误。
在我的 MWE 中,我有很多对于 MWE 来说不是严格必要的包,但是我用来解决这个问题的任何东西都需要不与这些包冲突(至少,它应该与尽可能少的包冲突)。
\documentclass[12pt,twoside]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{caption}
\usepackage[calcwidth = \columnwidth]{caption}
\usepackage{booktabs,threeparttable}
\usepackage{subcaption}
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{cite}
\usepackage{mathptmx}
\usepackage{textcomp}
\usepackage{float}
\usepackage{rotating}
\usepackage{tikz}
\usepackage[obeyspaces]{url}
\DeclareCaptionJustification{InvertedPyramid}{\hsize=\linewidth
\parindent=0pt
\leftskip=0pt plus.5fil
\rightskip=0pt plus-0.5fil
\parfillskip=0pt plus1fil
\emergencystretch=1in
\parshape10
0.00in \linewidth
0.025\linewidth 0.95\linewidth
0.05\linewidth 0.9\linewidth
0.075\linewidth 0.85\linewidth
0.1\linewidth 0.8\linewidth
0.125\linewidth 0.75\linewidth
0.15\linewidth 0.70\linewidth
0.175\linewidth 0.65\linewidth
0.2\linewidth 0.60\linewidth
0.225\linewidth 0.55\linewidth
\strut
}
\renewcommand{\TPTminimum}{3in}
\captionsetup[table]{justification=InvertedPyramid}
\begin{document}
\begin{table}[b!]
\centering
\begin{threeparttable}
\caption[Values of the $\beta_i$ coefficients to describe the stiffness of lattice-flexured CAFPs.]{Values of the $\beta_i$ coefficients used in an Equation, and $R^2$ values for each set of coefficients. These coefficients are used to describe the stiffness of X-type and V-type lattice flexures subjected to lateral loads.}
\begin{tabular}{lcr}
& X-type & V-type \\
\hline
\hline
$\beta_1$ & -0.2263 & -0.2280 \\ %updated
$\beta_2$ & -0.0911 & -0.0541 \\
$\beta_3$ & 2.0862 & 2.0502 \\
$\beta_4$ & -0.0031 & -0.0027 \\
$\beta_5$ & -0.0029 & -0.0026 \\
$R^2$ & 0.9949 & 0.9964 \\
\hline
\end{tabular}
\label{tab:betas}
\end{threeparttable}
\end{table}
\end{document}
答案1
下面的操作与 非常相似threepartable
,只是居中位置\hfil
是在框外部而不是内部。
\documentclass[12pt,twoside]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{caption}
\usepackage[calcwidth = \columnwidth]{caption}
\usepackage{booktabs,threeparttable}
\usepackage{subcaption}
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{cite}
\usepackage{mathptmx}
\usepackage{textcomp}
\usepackage{float}
\usepackage{rotating}
\usepackage{tikz}
\usepackage[obeyspaces]{url}
\DeclareCaptionJustification{InvertedPyramid}{\hsize=\linewidth
\parindent=0pt
\leftskip=0pt plus.5fil
\rightskip=0pt plus-0.5fil
\parfillskip=0pt plus1fil
\emergencystretch=1in
\parshape10
0.00in \linewidth
0.025\linewidth 0.95\linewidth
0.05\linewidth 0.9\linewidth
0.075\linewidth 0.85\linewidth
0.1\linewidth 0.8\linewidth
0.125\linewidth 0.75\linewidth
0.15\linewidth 0.70\linewidth
0.175\linewidth 0.65\linewidth
0.2\linewidth 0.60\linewidth
0.225\linewidth 0.55\linewidth
\strut
}
\renewcommand{\TPTminimum}{3in}
\captionsetup[table]{justification=InvertedPyramid}
\newsavebox{\tempbox}
\newlength{\tempwidth}
\usepackage{showframe}% to check centering only
\begin{document}
\begin{table}[b!]
% calculate size of tabular
\savebox{\tempbox}{\begin{tabular}{lcr}
& X-type & V-type \\
\hline
\hline
$\beta_1$ & -0.2263 & -0.2280 \\ %updated
$\beta_2$ & -0.0911 & -0.0541 \\
$\beta_3$ & 2.0862 & 2.0502 \\
$\beta_4$ & -0.0031 & -0.0027 \\
$\beta_5$ & -0.0029 & -0.0026 \\
$R^2$ & 0.9949 & 0.9964 \\
\hline
\end{tabular}}
% set width
\ifdim\wd\tempbox<\TPTminimum\relax \tempwidth=\TPTminimum\relax
\else\tempwidth=\wd\tempbox
\fi
% format
\hfil\begin{minipage}{\tempwidth}
\caption[Values of the $\beta_i$ coefficients to describe the stiffness of lattice-flexured CAFPs.]{Values of the $\beta_i$ coefficients used in an Equation, and $R^2$ values for each set of coefficients. These coefficients are used to describe the stiffness of X-type and V-type lattice flexures subjected to lateral loads.}
\label{tab:betas}
\hfil\usebox{\tempbox}
\end{minipage}
\end{table}
\end{document}