4

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}
  • For figures you can use \includegraphics[width=\textwidth]{/path/to/image}. In your example of the table, you have only one column and you specified that it should be 16% larger than \textwidth. You should use a number between 0 and 1. – Nico Feb 11 '14 at 12:41
  • Is real example a one column table (which seems odd, why tabular at all) In that case you just want \dimexpr\textwidth+\marginparwidth+\marginparsep-2\tabcolsep But if you need to take account of l and c column natural width, it is harder (tabularx package can help – David Carlisle Feb 11 '14 at 12:41
  • @DavidCarlisle: Actual tables have at least 2 columns, of course. The example shows a table that I want not to result in a black bar in draft mode, because it doesn‘t extend beyond the margin paragraph width. – Crissov Feb 11 '14 at 13:08
  • @Crissov yes but there is a big difference (in solution method) between a table where all columns are p type (so you know the width in advance) and tables where any column is c/l/r (where the column width depends on the data) as in the latter case the desired width of the p column to fit your margin space depends on the content of the other columns of the table. – David Carlisle Feb 11 '14 at 13:37
  • 1
    @Crissov oh good that means the answer I posted is the answer you want:-) – David Carlisle Feb 11 '14 at 14:08
6

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}
|improve this answer|||||
  • Tanks. The \advance\hsize part seems to be what I was looking for, indeed. Ideally, it would just work for all floats, but widetable and widefigure environments are fine, too. – Crissov Feb 11 '14 at 14:26
  • 1
    @Crissov if you want to do all floats then \let\old@float\@float\def\@float{\advance\columnwidth\marginparwidthadvance\columnwidth\marginparsep\old@float} probably works – David Carlisle Feb 11 '14 at 14:41
3

Well, you should never have anything bleeding into the margin like this. However, you can solve the problem by adding a \hspace*:

\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}\hspace*{-0.5\textwidth}
\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}

The value 0.5\textwidth should be safe since your margin is probably not larger than half of the text width anyways. However, every time you use this in a final document, Schrödinger kills a kitten (instantly, no waiting and no probability).

|improve this answer|||||
  • If one (extensively) uses margin notes, which never appear next to floats like tables and figures, I think it’s a viable typographic choice – and not too unusual – to let floats take the same maximum width as paragraphs plus margin notes. However, your code successfully suppresses the black bar, although I don’t know exactly why and I was hoping for something to put in the preamble, like hypothetic \maxfloatwidth=\dimexpr\textwidth+\marginparwidth+\marginparsep-2\tabcolsep (see David Carlisle’s comment). Also, there are more than enough stray cats. – Crissov Feb 11 '14 at 13:18
  • @Crissov that it should be done in a systematic way, and there is surely a question about it on the site. You can do \hsize\maxfloatwidth. But then you need to determine whether it's a recto or verso page, and on verso, it's much more complicated. Is that what you want? If so, please state it more clearly. – yo' Feb 11 '14 at 13:25
  • I searched for it, of course, but unsuccessfully. Luckily, my current use case is single-sided. – Crissov Feb 11 '14 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.