这就是我所拥有的:
我需要的是表格标题与表格左侧对齐(居中)。像这样:
我正在寻找的答案必须包含居中的表格。这是我的一些代码:
\documentclass[11pt, openany]{book}
\usepackage[top = 2cm, bottom = 1.5cm, left = 1.5cm, right = 1.5cm]{geometry}
\usepackage{booktabs} % \toprule y \bottomrule
\usepackage[scr = rsfso]{mathalfa}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{float}
\usepackage{caption}
\captionsetup{labelfont = bf, justification = raggedright, singlelinecheck = false, format = hang}
\captionsetup[sub]{labelfont = up, justification = centering}
\usepackage{subcaption}
\begin{document}
\begin{table}[H] \centering
\caption{Term\'ometros usuales.}
\begin{tabular}{llc} \toprule
Term\'ometro & Propiedad Termom\'etrica & Notaci\'on \\ \hline
Gas (volumen constante) & Presi\'on & $p$ \\
Resistencia de platino (tensi\'on constante) & Resistencia El\'ectrica & $R'$ \\
Termopar (tensi\'on constante) & Fem t\'ermica & $E$ \\
Vapor de helio (saturado) & Presi\'on & $p$ \\
Sal paramagn\'etica & Susceptibilidad magn\'etica & $\chi$ \\
Radiaci\'on de cuerpo negro & Emitancia radiante & $R_{b, \lambda}$ \\ \bottomrule
\end{tabular}
\label{CyT:tempGases:tiposTermometros}
\end{table}
\end{document}
感谢您的帮助!
答案1
(1)为了使标题与表格对齐,添加包threeparttable
并将标题放在threeparttable
环境中。
(2)表格不适合行宽。一个选项(有几种)是通过定义新的列类型来减小第一列的宽度。
\documentclass[11pt, openany]{book}
\usepackage{booktabs} % \toprule y \bottomrule
\usepackage[scr = rsfso]{mathalfa}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{float}
\usepackage{caption}
\captionsetup{labelfont = bf, justification = raggedright, singlelinecheck = false, format = hang}
\captionsetup[sub]{labelfont = up, justification = centering}
\usepackage{subcaption}
%\usepackage[left=3.00cm, right=3.00cm, top=4.00cm, bottom=3.00cm,showframe]{geometry}% added for larger margins
\usepackage{showframe} % ONLY to show the margins}
\usepackage{threeparttable} % added
\usepackage{array} % added <<<<<<<<<
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\begin{document}
\begin{table}[H] \centering
\begin{threeparttable}
\caption{Term\'ometros usuales.}
\begin{tabular}{L{0.4\linewidth}lc}% changed <<<<<<<<<<
\toprule
Term\'ometro & Propiedad Termom\'etrica & Notaci\'on \\ \hline
Gas (volumen constante) & Presi\'on & $p$ \\
Resistencia de platino (tensi\'on constante) & Resistencia El\'ectrica & $R'$ \\
Termopar (tensi\'on constante) & Fem t\'ermica & $E$ \\
Vapor de helio (saturado) & Presi\'on & $p$ \\
Sal paramagn\'etica & Susceptibilidad magn\'etica & $\chi$ \\
Radiaci\'on de cuerpo negro & Emitancia radiante & $R_{b, \lambda}$ \\ \bottomrule
\end{tabular}
\label{CyT:tempGases:tiposTermometros}
\end{threeparttable}
\end{table}
\end{document}
答案2
您的代码存在一个比标题字符串开头未与表格材料左边缘对齐更大的问题。这个更大的问题是,代码无法保证表格材料实际上适合文本块的宽度。事实上,对于您发布的最小示例,表格材料明显超出了文本块的宽度(由参数给出\textwidth
)。
为了解决这个大问题,我建议你从 a 环境切换tabular
到 atabularx
环境,将其整体宽度设置为\textwidth
,并为第一列使用X
列类型。这样,LaTeX 会自动选择第一列的合适宽度。(实际上,在下面的代码中,我使用了列X
类型的修改版本,它也会自动执行悬挂缩进。)
这一改变带来的一个令人欣喜的副作用是,您不再需要做任何特殊的事情来将标题的开头与表格的左边缘对齐。
\documentclass[11pt, openany]{book}
\usepackage[T1]{fontenc} % <-- new
\usepackage{tabularx} % <-- new
\newcolumntype{L}{>{\raggedright\arraybackslash\hangindent=1em\hangafter=1}X}
\usepackage{booktabs} % \toprule y \bottomrule
\usepackage[scr = rsfso]{mathalfa}
\usepackage{mathtools}
\usepackage{amssymb}
%\usepackage{float}
\usepackage{caption,subcaption}
\captionsetup{labelfont = bf,
justification = raggedright,
singlelinecheck = false,
format = hang,
skip=0.333\baselineskip} % <-- new option
\captionsetup[sub]{labelfont = up,
justification = centering}
\begin{document}
\begin{table}[ht]
%%\centering % no longer needed
\caption{Term\'ometros usuales.}
\label{CyT:tempGases:tiposTermometros}
\begin{tabularx}{\textwidth}{@{} Llc @{}}
\toprule
Term\'ometro & Propiedad Termom\'etrica & Notaci\'on \\
\midrule % why use "\hline"??
Gas (volumen constante) & Presi\'on & $p$ \\
Resistencia de platino (tensi\'on constante) & Resistencia el\'ectrica & $R'$ \\
Termopar (tensi\'on constante) & Fem t\'ermica & $E$ \\
Vapor de helio (saturado) & Presi\'on & $p$ \\
Sal paramagn\'etica & Susceptibilidad magn\'etica & $\chi$ \\
Radiaci\'on de cuerpo negro & Emitancia radiante & $R_{b, \lambda}$ \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}