fmarotta / kaobook

A LaTeX class for books, reports or theses based on https://github.com/kenohori/thesis and https://github.com/Tufte-LaTeX/tufte-latex.

Home Page:https://github.com/fmarotta/kaobook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

prevent marginfigure / sidenotes from running off page

goretkin opened this issue · comments

marginfix was removed, which fixed #77 and #169

The consequence, however, is that without marginfix, the MWE produces the following output:
image

adding it back in gives
image

I don't know what a good solution is.

\documentclass[
	letterpaper, 	% Page size
	fontsize=11pt, % Base font size
	twoside=false, % Use different layouts for even and odd pages (in particular, if twoside=true, the margin column will be always on the outside)
	%open=any, % If twoside=true, uncomment this to force new chapters to start on any page, not only on right (odd) pages
	secnumdepth=1, % How deep to number headings. Defaults to 1 (sections)
]{kaobook}

\pagestyle{centeredpagenum.scrheadings}
% \usepackage{marginfix} this makes or breaks this document

\usepackage[utf8]{inputenc}

% necessary for `kaorefs`'s `\addto` definitions
\usepackage[english]{babel} % Load characters and hyphenation


% Load mathematical packages for theorems and related environments
% needs to be included, otherwise
% `! LaTeX Error: Command \openbox already defined.`
\usepackage{kaotheorems}

% Load the package for hyperreferences
% n.b.: defines command `\refeq`, and so needs to be after `mathtools` and renaming
\usepackage{kaorefs}


\begin{document}

\chapter{Introduction}
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text, and a reference to \cref{fig:a}
\begin{marginfigure}
    \centering
    \includegraphics[width=1\textwidth]{example-image}
    \includegraphics[width=1\textwidth]{example-image}
    \includegraphics[width=1\textwidth]{example-image}
    \includegraphics[width=1\textwidth]{example-image}
	\caption[One sentence caption for list.]{
        The image already ran off the page. But if it didn't then:
        A really long caption that is going to run off the bottom of the page
        A really long caption that is going to run off the bottom of the page
        A really long caption that is going to run off the bottom of the page
        A really long caption that is going to run off the bottom of the page
        A really long caption that is going to run off the bottom of the page
        A really long caption that is going to run off the bottom of the page
        A really long caption that is going to run off the bottom of the page
    }
    \label{fig:a}
\end{marginfigure}

\appendix
\end{document}

Is there a reason to not include the graphics a little higher? The following code works fine for me, it produces the same result as in your second image.

\documentclass[
	letterpaper, 	% Page size
	fontsize=11pt, % Base font size
	twoside=false, % Use different layouts for even and odd pages (in particular, if twoside=true, the margin column will be always on the outside)
	%open=any, % If twoside=true, uncomment this to force new chapters to start on any page, not only on right (odd) pages
	secnumdepth=1, % How deep to number headings. Defaults to 1 (sections)
]{kaobook}

\pagestyle{centeredpagenum.scrheadings}
% \usepackage{marginfix} this makes or breaks this document

\usepackage[utf8]{inputenc}

% necessary for `kaorefs`'s `\addto` definitions
\usepackage[english]{babel} % Load characters and hyphenation


% Load mathematical packages for theorems and related environments
% needs to be included, otherwise
% `! LaTeX Error: Command \openbox already defined.`
\usepackage{kaotheorems}

% Load the package for hyperreferences
% n.b.: defines command `\refeq`, and so needs to be after `mathtools` and renaming
\usepackage{kaorefs}


\begin{document}

\chapter{Introduction}
\begin{marginfigure}
	\centering
	\includegraphics[width=1\textwidth]{example-image}
	\includegraphics[width=1\textwidth]{example-image}
	\includegraphics[width=1\textwidth]{example-image}
	\includegraphics[width=1\textwidth]{example-image}
\caption[One sentence caption for list.]{
			The image already ran off the page. But if it didn't then:
			A really long caption that is going to run off the bottom of the page
			A really long caption that is going to run off the bottom of the page
			A really long caption that is going to run off the bottom of the page
			A really long caption that is going to run off the bottom of the page
			A really long caption that is going to run off the bottom of the page
			A really long caption that is going to run off the bottom of the page
			A really long caption that is going to run off the bottom of the page
	}
	\label{fig:a}
\end{marginfigure}
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text\\
A lot of text, and a reference to \cref{fig:a}


\appendix
\end{document}

The reason is to produce a MWE illustrating the issue. I don't believe that the solution to move the figure up works in general. I suspect there is an MWE with multiple margin figures, where, depending on the pagination, some of them are off the page.

I can confirm that, I definitely encounter figures that run off the page instead of being moved around. I can indeed counter this by moving the figure higher, exchanging them, or radically set their placement by hand by removing their floating status. But this means that changing the text at some place can completely wreck havoc in my document further down and I have to redo the placement work again, which is really painful.

I have similar issues with long list of citations (i.e. using \sidecite{A, B, ...}).
Reactivating marginfix solves the problem.
So at least on my document the advantages of marginfix definitely outweigh its advantages.