我想要将表格标题左对齐。
此代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[font=small,labelfont=bf]{caption}
\begin{document}
\begin{table}
\centering
\captionsetup{singlelinecheck = false, justification=justified}
\caption{System specifications}
\label{tab:specs}
\begin{tabular}{ll}
Processor & Intel(R) Core(TM) i7-7500U CPU @2.70GHz 2.90 GHz \\
Installed RAM & 8.00 GB (7.89 GB usable)
\end{tabular}
\end{table}
\end{document}
创建这个:
我希望标题与表格本身的左边框对齐,而不是段落:
(注意:上面的图片是在 MS paint 中编辑的……)
答案1
@{}
请注意表格每一侧的添加。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[font=small,labelfont=bf]{caption}
\begin{document}
\begin{table}
\sbox0{\begin{tabular}{@{}ll@{}}
Processor & Intel(R) Core(TM) i7-7500U CPU @2.70GHz 2.90 GHz \\
Installed RAM & 8.00 GB (7.89 GB usable)
\end{tabular}}%
\centering
\begin{minipage}{\wd0}
\captionsetup{singlelinecheck = false, justification=justified}
\caption{System specifications}
\label{tab:specs}
\usebox0
\end{minipage}
\end{table}
\end{document}
答案2
我建议您 (a) 继续加载caption
包,并且 (b) 使用threeparttable
环境来封装\caption
指令和tabular
环境。它会测量环境的宽度tabular
,并将标题字符串的宽度限制为该宽度。
\documentclass{article}
\usepackage{caption}
\usepackage{threeparttable} % see https://ctan.org/pkg/threeparttable
\begin{document}
\begin{table}[h!]
\centering
\captionsetup{singlelinecheck = false, justification=raggedright}
\begin{threeparttable}
\caption{System specifications}
\begin{tabular}{@{} ll @{}}
Processor & Intel(R) Core(TM) i7-7500U CPU @2.70\,GHz 2.90\,GHz \\
Installed RAM & 8.00 GB (7.89 GB usable)
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}