2

I have a big project were the package floatrow are used. I discovered that when this package are used, the caption put inside my tables are now show outside. I can't find any way of getting it back inside.

Here is my MWE:

\documentclass{article} % Document class
\usepackage{hyperref} % For hyperlinks
\usepackage{siunitx} % For typesetting numbers and units
\usepackage{nicematrix} % For creating tables
\usepackage{caption} % For customizing captions
\usepackage{xcolor} % For custom colors
\usepackage{floatrow} % For customizing float environments

%%% Color definition
\definecolor{gray-100}{HTML}{f3f4f6}
\definecolor{gray-200}{HTML}{e5e7eb}
\definecolor{gray-600}{HTML}{4b5563}
\definecolor{gray-800}{HTML}{1f2937}
\definecolor{slate-50}{HTML}{f8fafc}

\begin{document}

\begin{table}
   \centering % Center the table
   \renewcommand{\arraystretch}{1.5} % Adjust row height
\captionsetup[table]{font={bf,sf,color=gray-600,small}, skip=0pt} % Customize table caption
\begin{NiceTabular}{lcS}[hvlines, rounded-corners=6pt, rules/color=gray-200] % Create NiceTabular with specified properties
\CodeBefore % LaTeX code before the table
\rowcolor{gray-100}{1-2} % Colorize the first row
   \rowcolors{3}{}{slate-50} % Alternate row colors starting from the third row
\Body % Body of the table
   \Block{1-3}{\begin{minipage}{50mm}\captionof{table}{Table Title 1}\label{tab:title1}\end{minipage}} \\ % Multi-column cell for caption
   \RowStyle[bold]{\color{gray-600}} % Style for the first data row
    Town & Correspondant & {Value} \\ % Table headers
    \RowStyle[nb-rows=*,color=gray-800]{} % Style for the remaining data rows
    Paris & Peter & 1.23 \\ % Data rows
    London & Helena & 23.23\\
    Madrid & Georges &12.5 \\
    Moscou & Henry & 4.77 \\
    Tokyo & Selena & 85.3 \\
    Lima & Victoria & 13.2 \\
    Cap Town & Alexandra & 6 \\
    Chicago & Vladimier & 1.34
\end{NiceTabular}
\end{table}

\end{document}

I use NiceTabular, but I am also able to get the same issue using tcolorbox.

The expected result:

Expected result, where caption are on the first row

Actual:

Actual result with floatrow package: the caption is outside the table

2

2 Answers 2

4

Wrapping the \captionof in floatrow command \RawCaption does the trick:

\RawCaption{\captionof{table}{Table Title 1}\label{tab:title1}}

From floatrow's package manual (v0.3b, 2009-08-02), sec. 2.4.1 "Raw Caption—Printing in Unusual Way"

\RawCaption

This command allows to “release” caption contents from special box register created by floatrow package for the creation of necessary layout. The caption is placed as argument of \RawCaption:

\RawCaption{\caption\marg{contents}\label{...}}` .
\documentclass{article} % Document class
\usepackage{siunitx} % For typesetting numbers and units
\usepackage{nicematrix} % For creating tables
\usepackage{caption} % For customizing captions
\usepackage{xcolor} % For custom colors
\usepackage{floatrow} % For customizing float environments

\usepackage{hyperref} % For hyperlinks; load hyperref last

%%% Color definition
\definecolor{gray-100}{HTML}{f3f4f6}
\definecolor{gray-200}{HTML}{e5e7eb}
\definecolor{gray-600}{HTML}{4b5563}
\definecolor{gray-800}{HTML}{1f2937}
\definecolor{slate-50}{HTML}{f8fafc}

\begin{document}

\begin{table}
   \centering % Center the table
   \renewcommand{\arraystretch}{1.5} % Adjust row height
\captionsetup[table]{font={bf,sf,color=gray-600,small}, skip=0pt} % Customize table caption
\begin{NiceTabular}{lcS}[hvlines, rounded-corners=6pt, rules/color=gray-200] % Create NiceTabular with specified properties
\CodeBefore % LaTeX code before the table
\rowcolor{gray-100}{1-2} % Colorize the first row
   \rowcolors{3}{}{slate-50} % Alternate row colors starting from the third row
\Body % Body of the table
   \Block{1-3}{%
    \begin{minipage}{50mm}
      \RawCaption{\captionof{table}{Table Title 1}\label{tab:title1}}
    \end{minipage}} \\ % Multi-column cell for caption
   \RowStyle[bold]{\color{gray-600}} % Style for the first data row
    Town & Correspondant & {Value} \\ % Table headers
    \RowStyle[nb-rows=*,color=gray-800]{} % Style for the remaining data rows
    Paris & Peter & 1.23 \\ % Data rows
    London & Helena & 23.23\\
    Madrid & Georges &12.5 \\
    Moscou & Henry & 4.77 \\
    Tokyo & Selena & 85.3 \\
    Lima & Victoria & 13.2 \\
    Cap Town & Alexandra & 6 \\
    Chicago & Vladimier & 1.34
\end{NiceTabular}
\end{table}

\end{document}

enter image description here

1
  • Thank you 🙏 it solved the problem.
    – Heziode
    Commented Mar 14 at 23:40
2

The basic principle works, although in this case you aren't putting the caption inside a minipage. OTOH, \RawCaption was added to floatrow specifically to handle this problem.

\documentclass{article} % Document class
\makeatletter
  \let\old@makecaption=\@makecaption
\makeatother
\usepackage{siunitx} % For typesetting numbers and units
\usepackage{nicematrix} % For creating tables
\usepackage{caption} % For customizing captions
\usepackage{xcolor} % For custom colors
\usepackage{floatrow} % For customizing float environments
\usepackage{hyperref} % For hyperlinks

%%% Color definition
\definecolor{gray-100}{HTML}{f3f4f6}
\definecolor{gray-200}{HTML}{e5e7eb}
\definecolor{gray-600}{HTML}{4b5563}
\definecolor{gray-800}{HTML}{1f2937}
\definecolor{slate-50}{HTML}{f8fafc}

\begin{document}

\begin{table}
\makeatletter
  \let\@makecaption=\old@makecaption
\makeatother
\centering % Center the table
\renewcommand{\arraystretch}{1.5} % Adjust row height
\captionsetup[table]{font={bf,sf,color=gray-600,small}, skip=0pt} % Customize table caption
\begin{NiceTabular}{lcS}[hvlines, rounded-corners=6pt, rules/color=gray-200] % Create NiceTabular with specified properties
\CodeBefore % LaTeX code before the table
\rowcolor{gray-100}{1-2} % Colorize the first row
   \rowcolors{3}{}{slate-50} % Alternate row colors starting from the third row
\Body % Body of the table
   \Block{1-3}{\begin{minipage}{50mm}\captionof{table}{Table Title 1}\label{tab:title1}\end{minipage}} \\ % Multi-column cell for caption
   \RowStyle[bold]{\color{gray-600}} % Style for the first data row
    Town & Correspondant & {Value} \\ % Table headers
    \RowStyle[nb-rows=*,color=gray-800]{} % Style for the remaining data rows
    Paris & Peter & 1.23 \\ % Data rows
    London & Helena & 23.23\\
    Madrid & Georges &12.5 \\
    Moscou & Henry & 4.77 \\
    Tokyo & Selena & 85.3 \\
    Lima & Victoria & 13.2 \\
    Cap Town & Alexandra & 6 \\
    Chicago & Vladimier & 1.34
\end{NiceTabular}
\end{table}

\end{document}

You must log in to answer this question.

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