3

I have the following table with title which is wider than the width of the tabular material. How do I make the title fit the the width of the table?

\documentclass{article}
\usepackage{caption,booktabs,array}
\usepackage[flushleft]{threeparttable}
\newcommand{\rowgroup}[1]{\hspace{-1em}#1}
\usepackage{geometry}
\geometry{
    a4paper,
    total={170mm,257mm},
    left=20mm,
    top=20mm,
}

\usepackage[width=.75\textwidth]{caption}
\begin{document}
\pagenumbering{gobble}
\begin{table}
\caption{Quite a long title for the table that tends to be wider than the table}
\centering
\begin{threeparttable}
\begin{tabular}{>{\quad}ll}
% \toprule
%& \multicolumn{1}{c}{} \\
\midrule
\rowgroup{Tests} \\
test1 &0.2\\
test2&0.2\\
test3&3.03\\
test3&0.006\\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

x

1
  • 1
    The proper solution is to place the \caption directive inside rather than outside the threeparttable environment.
    – Mico
    Jul 15, 2019 at 8:01

3 Answers 3

6

You're not using the threeparttable environment correctly: You should place the \caption statement inside rather than outside the threeparttable environment. That way, the caption's width will be restricted automatically to that of the tabular environment.

More generally, the three formal parts of a threeparttable environment are the \caption directive, the tabular environment (also possible: tabular* and tabularx), and the tablenotes environment. By placing the caption and the tablenotes material inside rather than outside the threeparttable environment, their widths will be adjusted automatically not to exceed the width of the tabular material.

enter image description here

\documentclass{article}
\usepackage{caption,booktabs,array,ragged2e}
\usepackage[flushleft]{threeparttable}
\newcommand{\rowgroup}[1]{\hspace{-1em}#1}
\usepackage{geometry}
\geometry{a4paper,total={170mm,257mm},left=20mm,top=20mm}

\usepackage[width=.75\textwidth]{caption}
\begin{document}
\begin{table}
%\captionsetup{justification=RaggedRight} % optional
\centering
\begin{threeparttable} % note that this comes before "\caption"
\caption{Quite a long title that's no longer wider than the subsequent tabular environment}
\begin{tabular}{>{\quad}ll}
\midrule
\rowgroup{Tests} \\
test1 &0.2\\
test2&0.2\\
test3&3.03\\
test3&0.006\\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}
2
  • Mico's suggestion is better than all the suggestion which are posted here, better to use it...
    – MadyYuvi
    Jul 15, 2019 at 8:37
  • 1
    Indeed, Thank you @Mico
    – ecjb
    Jul 15, 2019 at 8:39
3

A simple solution is just add minipage into your tags, e.g.,

\documentclass{article}
\usepackage{caption,booktabs,array}
\usepackage[flushleft]{threeparttable}
\newcommand{\rowgroup}[1]{\hspace{-1em}#1}
\usepackage{geometry}
\geometry{
    a4paper,
    total={170mm,257mm},
    left=20mm,
    top=20mm,
}


\begin{document}
\pagenumbering{gobble}
\begin{table}
\begin{minipage}{80pt}
    \caption{Quite a long title for the table that tends to be wider than the table}
\centering
\begin{threeparttable}
\begin{tabular}{>{\quad}ll}
% \toprule
%& \multicolumn{1}{c}{} \\
\midrule
\rowgroup{Tests} \\
test1 &0.2\\
test2&0.2\\
test3&3.03\\
test3&0.006\\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{minipage}
\end{table}
\end{document}

May be some experts will gives the auto fit option for this...

4
  • 1
    Why use a separate minipage environment if it suffices to place the \caption after than before \begin{threeparttable}?
    – Mico
    Jul 15, 2019 at 7:59
  • @Mico Thanks for correcting me....
    – MadyYuvi
    Jul 15, 2019 at 8:01
  • To make your answer more self-contained, it would help if you stated explicitly how you arrived at 80pt as the width of the minipage environment.
    – Mico
    Jul 15, 2019 at 8:06
  • 1
    @Mico I just measured the table body width, and entered the approximate value, nothing else intentionally...
    – MadyYuvi
    Jul 15, 2019 at 8:36
0

You can add backslash \\ in the caption:

\documentclass{article}
    \usepackage{caption,booktabs,array}
    \usepackage[flushleft]{threeparttable}

\newcommand{\rowgroup}[1]{\hspace{-1em}#1}

\usepackage{geometry}

\geometry{
        a4paper,
        total={170mm,257mm},
        left=20mm,
        top=20mm,
    }

\usepackage[width=.75\textwidth]{caption}

\begin{document}

\pagenumbering{gobble}

\begin{table}
        \caption{Quite a long title \\ for the table that tends \\ to be wider than
 the table}
    \centering
    \begin{threeparttable}
    \begin{tabular}{>{\quad}ll}
    % \toprule
    %& \multicolumn{1}{c}{} \\
    \midrule
    \rowgroup{Tests} \\
    test1 &0.2\\
    test2&0.2\\
    test3&3.03\\
    test3&0.006\\
    \bottomrule
    \end{tabular}
    \end{threeparttable}
    \end{table}

\end{document}

You can control the width of the caption by controlling the backslash location

1
  • This is not feasible for large documents, and produces less-than-optimal results. Automatic justification would be preferred.
    – AJF
    Jul 15, 2019 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .