[Tex/LaTex] Let caption float into margin

captionsfloatsmargins

I searched for a long time to find a solution to let a caption of a figure and/or a table expand into the outside margin. I'm able to get a figure/table where the width is textwidth plus marginparwidth. See my MWE down below using a solution on stackexchange.

EDIT: Thanks to Steven B. Segletes, who found the right question, I was able to fix this with the command \captionsetup{margin={0pt,-\marginparwidth}} using the caption-package. I edited the code below, too.

\documentclass[%
    12pt,
    BCOR=15mm,
    captions=tableheading,
    DIV=current,
    ]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[demo]{graphicx}

\usepackage[
    top=30mm,
    bottom=40mm,
    inner=30mm,
    outer=55mm,
    marginparsep=5mm,
    marginparwidth=30mm,
    ]{geometry}

\usepackage[leqno, fleqn]{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{booktabs}
\usepackage{array, tabularx}

\usepackage{ifoddpage}
\newlength\fullwidth\fullwidth=\textwidth \advance\fullwidth by \marginparwidth

\begin{document}

\begin{figure}
    \checkoddpage
    \edef\side{\ifoddpage l\else r\fi}
    \makebox[\textwidth][\side]{% 
        \includegraphics[width=\fullwidth]{figure}
    }%
    \captionsetup{margin={0pt,-\marginparwidth}}
    \caption{Long captiontext do get two lines, so I can see, if the caption expands into the margin.\label{fig:label}}
\end{figure}

\begin{table}[h]
    \captionsetup{margin={0pt,-\marginparwidth}}
    \caption{Instabile Isotope können unter Aussendung von Kernteilchen zerfallen. Dabei bilden sie neue Isotope.\label{tab:radiozerfall}}
    \checkoddpage
    \edef\side{\ifoddpage l\else r\fi}
    \makebox[\textwidth][\side]{% 
        \begin{tabularx}{1.01\fullwidth}{>{\kern-\tabcolsep}XXXXXX<{\kern-\tabcolsep}}
        \toprule
        Produkt       & \multicolumn{2}{c}{Strahlungs-} & \multicolumn{3}{c}{Eigenschaften der Strahlungsteilchen}  \\
                       & teilchen           & bezeichnung          & Kernladungs\-zahl & Nukleonen\-zahl & Durchdrin\-gung \\
        $^{A-4}_{Z-2}\text{E}$ & He-Kern            & $\alpha$-Strahlung   & $+2$              & 4               & gering          \\
        $^{A}_{Z+1}\text{E}$   & Elektron           & $\beta$-Strahlung    & $-1$              & 0               & mittel          \\
        unverändert            & Photon             & $\gamma$-Strahlung   & $\phantom{-}0$    & 0               & groß            \\ \bottomrule
        \end{tabularx}}
\end{table}

\end{document}

Thanks in advance.

Best Answer

Here's an options using the caption package and its margin key (I added the showframe option to geometry so as to have a visual help for the page layout; I also added \marginparsep to the width of the figure, table and captions, but this is optional):

\documentclass[%
    12pt,
    BCOR=15mm,
    captions=tableheading,
    DIV=current,
    ]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[demo]{graphicx}

\usepackage[
showframe,
    top=30mm,
    bottom=40mm,
    inner=30mm,
    outer=55mm,
    marginparsep=5mm,
    marginparwidth=30mm,
    ]{geometry}

\usepackage[leqno, fleqn]{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{booktabs}
\usepackage{array, tabularx}

\usepackage{ifoddpage}
\newlength\fullwidth\fullwidth=\textwidth \advance\fullwidth by \marginparwidth
\advance\fullwidth by \marginparsep
\usepackage{caption}

\newlength\extraWd
\setlength\extraWd{\dimexpr\marginparwidth+\marginparsep\relax}

\begin{document}

\begin{figure}
    \captionsetup{margin={0cm,-\extraWd}}
    \checkoddpage
    \edef\side{\ifoddpage l\else r\fi}
    \makebox[\textwidth][\side]{% 
        \includegraphics[width=\fullwidth]{figure}
    }%
    \caption{Long captiontext do get two lines, so I can see, if the caption expands into the margin.\label{fig:label}}
\end{figure}

\begin{table}[h]
    \captionsetup{margin={0cm,-\extraWd}}
    \caption{Instabile Isotope können unter Aussendung von Kernteilchen zerfallen. Dabei bilden sie neue Isotope.\label{tab:radiozerfall}}
    \checkoddpage
    \edef\side{\ifoddpage l\else r\fi}
    \makebox[\textwidth][\side]{% 
        \begin{tabularx}{1.01\fullwidth}{>{\kern-\tabcolsep}XXXXXX<{\kern-\tabcolsep}}
        \toprule
        Produkt       & \multicolumn{2}{c}{Strahlungs-} & \multicolumn{3}{c}{Eigenschaften der Strahlungsteilchen}  \\
                       & teilchen           & bezeichnung          & Kernladungs\-zahl & Nukleonen\-zahl & Durchdrin\-gung \\
        $^{A-4}_{Z-2}\text{E}$ & He-Kern            & $\alpha$-Strahlung   & $+2$              & 4               & gering          \\
        $^{A}_{Z+1}\text{E}$   & Elektron           & $\beta$-Strahlung    & $-1$              & 0               & mittel          \\
        unverändert            & Photon             & $\gamma$-Strahlung   & $\phantom{-}0$    & 0               & groß            \\ \bottomrule
        \end{tabularx}}
\end{table}

\end{document}

The result:

enter image description here

Related Question