kaobook icon indicating copy to clipboard operation
kaobook copied to clipboard

prevent marginfigure / sidenotes from running off page

Open goretkin opened this issue 2 years ago • 4 comments

marginfix was removed, which fixed https://github.com/fmarotta/kaobook/issues/77 and https://github.com/fmarotta/kaobook/issues/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}

goretkin avatar Jan 09 '22 20:01 goretkin

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}

AlexanderZeilmann avatar Jan 10 '22 09:01 AlexanderZeilmann

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.

goretkin avatar Jan 10 '22 23:01 goretkin

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.

MevenBertrand avatar Mar 23 '22 14:03 MevenBertrand

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.

jmkuebler avatar Jun 15 '22 14:06 jmkuebler