How can I left align a caption for a centered table?
Note the addition of @{}
to each side of the tabular.
\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}
I suggest you (a) keep loading the caption
package and (b) employ a threeparttable
environment to encase both the \caption
directive and the tabular
environment. It measures the width of the tabular
environment and limits the width of the caption string to that width.
\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}