[Tex/LaTex] Tables extending into the right/outer margin

marginstables

I have some wide tables (might be figures, too) that don’t fit into \textwidth. If the draft document option is active, there’s a black border on the right indicating that it’s wider than allowed.

How can I calculate the maximum width, i.e. the distance from text start at the left to margin paragraph end at the right?

How can I tell LaTeX to respect this maximum width for tables and figures?

\documentclass[draft]{scrartcl}
\usepackage[showframe]{geometry}
\usepackage{blindtext}

\begin{document}
\blindtext
\marginpar{This is a \texttt{marginpar} with multiple lines}
\blindtext

\begin{table}
\begin{tabular}{p{1.16\textwidth}}    % <-- trial-and-error value
\blindtext
\end{tabular}
\caption{A wide table that shall extend into the right margin,
         but no wider than margin notes or margin paragraphs do.}
\end{table}
\end{document}

Best Answer

You can define a widetable environment that stretches to the outer margin. (To simplify things I'm assuming oneside with the marginpar space on the right). That allows the content, including the caption, to extend into the marginpar space.

Then you can use @{} to suppress the column padding and:

enter image description here

\documentclass[draft]{scrartcl}
\usepackage[showframe]{geometry}
\usepackage{blindtext}

\makeatletter
\newenvironment{widetable}
{\table
 \advance\hsize\marginparwidth
 \advance\hsize\marginparsep
 \@parboxrestore}
{\endtable}
\makeatother

\begin{document}
\blindtext
\marginpar{This is a \texttt{marginpar} with multiple lines}
\blindtext

\begin{widetable}
\begin{tabular}{@{}p{\linewidth}@{}}    % <-- trial-and-error value
\blindtext
\end{tabular}
\caption{A wide table that shall extend into the right margin,
         but no wider than margin notes or margin paragraphs do.}
\end{widetable}
\end{document}