0

I was using the code from this solution to add margin notes in color boxes next to the text in my document. When they are called "too close" to the bottom of the page they don't show at all. The problem seems to be specific to the book class (my example does not fail if I change the class to article). My guess is that they are printing outside the margins of the page but I'm not getting any warnings about overfull or underfull boxes. I tried passing "floatplacement=ht" but it didn't do anything. Any thoughts on how to fix this?

\documentclass[dvipsnames,11pt]{book}
\usepackage[margin=3.5cm,marginparwidth=3cm, marginparsep=4mm]{geometry}
\usepackage{lipsum}
\usepackage{marginnote} % Margin notes
\usepackage[many]{tcolorbox}

% Highlighted notes

\newcounter{mynote} \newtcolorbox[use counter=mynote] {mynote}[1][] {floatplacement=ht title=Highlight~\thetcbcounter, width=2.6cm, left=0pt, right=0pt, fonttitle=\bfseries\color{Black}, colframe=Goldenrod, colback=Goldenrod!10, #1 }

\newcommand\Highlight[3][]{% \marginnote[#1]{% \makebox[0pt][l]{\begin{mynote}[label=#3] #2 \end{mynote}}}% }

\begin{document} \lipsum*[3]

\lipsum*[3]

\lipsum*[3]

\lipsum*[3]

\lipsum*[3]\Highlight{Text.}{label}

\lipsum*[3]

\lipsum*[3] \end{document}

LFG
  • 41

1 Answers1

1

I suspect this is a tikzpicture inside another tikzpicture problem.

\documentclass[dvipsnames,11pt,a4paper]{book}
\usepackage[margin=3.5cm,marginparwidth=3cm, marginparsep=4mm]{geometry}
\usepackage{lipsum}
\usepackage{marginnote} % Margin notes
\usepackage[many]{tcolorbox}

\newsavebox{\mybox}

% Highlighted notes

\newcounter{mynote} \newtcolorbox[use counter=mynote] {mynote}[1][] {floatplacement=ht title=Highlight~\thetcbcounter, width=2.6cm, left=0pt, right=0pt, fonttitle=\bfseries\color{Black}, colframe=Goldenrod, colback=Goldenrod!10, #1 }

\newcommand\Highlight[3][]{% \global\setbox\mybox=\hbox{\begin{mynote}[label=#3] #2 \end{mynote}}% \marginnote[#1]{\makebox[0pt][l]{\usebox\mybox}}% }

\begin{document} \lipsum*[3]

\lipsum*[3]

\lipsum*[3]

\lipsum*[3]

\lipsum*[3]\Highlight{Text.}{label}

\lipsum*[3]

\lipsum*[3] \end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • I tried your code but if I remove the a4paper option the margin note doesn't show any more. Since I never really plan to print the document paper size is not a deal breaker but I'd like to understand the problem a bit better. – LFG Mar 06 '21 at 20:24
  • The default paper size depends on your setup. Since you said "too close to the bottom of the page" i assumed a4paper was your default.. With letter, the \marginnote executes on one page but winds up on the next page. Not sure how \marginnote handles that. Evidently, not well. – John Kormylo Mar 07 '21 at 01:42