Adjust the width of the caption to the width of a table

captionsfloatrowtables

there are probably many questions similar to the one I have mentioned
Url 1
Url 2

but it turns out that it doesn't work in my case, I've read the floatrow documentation and the \FBwidth command caught my attention but I don't know how to use it. Below I present an example, the objective is that table 1 is the same as table 2 with respect to the title "fits the width of the table and its alignment in the center"

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[left=3cm,top=2.5cm,bottom=2.5cm, right=2.5cm,headheight=1cm,showframe=false]{geometry}
\usepackage{bookmark, amsmath}
\usepackage{multicol,multirow,booktabs, array}
\usepackage{threeparttable, longtable}
\usepackage{floatrow}
\floatsetup[longtable]{LTcapwidth=table}
\floatsetup[table]{position=top}
\usepackage[labelfont=bf,justification=raggedright,singlelinecheck=false]{caption}

\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[figure]{name=Fig. ,labelsep=newline, parskip=1.5cm}
\captionsetup[table]{labelsep=newline,font=normalsize,textfont=it, labelfont={bf}, parskip=2ex,justification=raggedright, singlelinecheck=false}

\begin{document}
\section{An table}

\begin{table}[ht]
\centering
\begin{threeparttable}
\caption{Cronbach alpha}
\label{tb:fiabilidad}
\begin{tabular}{lcc}\toprule
    \bfseries Scale & \bfseries Ítems &  $\pmb{\alpha}$\; \bfseries Cronbach \\ \midrule
    RPA &  20 & 0.8531 \\
    PCP* & 17 & 0.7645 \\ \bottomrule
    \multicolumn{3}{l}{\textbf{*}Items 11, 15 and 16 . } \\
\end{tabular}
\end{threeparttable}
\end{table}

\section{Another table}
\begin{longtable}[c]{lcc}
    \caption[Alpha Cronbach's]{Cronbach Alpha} \\ \toprule
\bfseries Scale &\bfseries Ítems & $\pmb{\alpha}$\; \bfseries Cronbach \\ \midrule \endfirsthead
\caption[]{(Continue)} \\ \toprule
\bfseries Variable &\bfseries N &\bfseries Frecuencia \\ \midrule \endhead \bottomrule
\endfoot \endlastfoot
Cronbach \\ \midrule
    RPA &  20 & 0.8531 \\
    PCP* & 17 & 0.7645 \\ \bottomrule
    \multicolumn{3}{l}{\textbf{*}Items 11, 15 and 16 . } \\
\end{longtable}
\end{document}

Objetive caption align width

Best Answer

Here's how to use floatrow. \ttabbox can use an optional argument to control the caption width. By default, it is set to \FBwidth, but you can choose a multiple of this value.

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[left=3cm,top=2.5cm,bottom=2.5cm, right=2.5cm,headheight=1cm,showframe=false]{geometry}
\usepackage{bookmark, amsmath}
\usepackage{multicol,multirow,booktabs, array}
\usepackage{threeparttable, longtable}
\usepackage{floatrow}
\floatsetup[longtable]{LTcapwidth=table}
\floatsetup[table]{position=top}
\usepackage[labelfont=bf,justification=raggedright,singlelinecheck=false]{caption}

\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[figure]{name=Fig. , labelsep=newline, parskip=1.5cm}
\captionsetup[table]{labelsep=newline,font=normalsize,textfont=it, labelfont={bf}, parskip=2ex,justification=raggedright, singlelinecheck=false}

\begin{document}

\begin{table}
\centering
    \ttabbox{\caption[Alpha Cronbach's]{Some rather long caption, with a nice lengthy addendum. }}
{\begin{tabular}{lcc}
    \toprule
\bfseries Scale &\bfseries Ítems & $\pmb{\alpha}$\; \bfseries Cronbach \\ \midrule
Cronbach \\ \midrule
    RPA & 20 & 0.8531 \\
    PCP* & 17 & 0.7645 \\ \bottomrule\addlinespace
    \multicolumn{3}{l}{\textbf{*}Items 11, 15 and 16 . }
\end{tabular}}
\end{table}

\end{document} 

enter image description here