3

There is always a badbox message appearing when I use the \missingfigure command of the todonotes package in LaTeX. Is an adjustment for the geometry options needed?

Error message: Overfull \hbox(2.0pt too wide) in paragraph at lines 8--10

Code:

\documentclass[12pt,a4paper]{report}
\usepackage[left=3.5cm,right=3.5cm,top=3cm,bottom=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[colorinlistoftodos, textwidth=\marginparwidth]{todonotes}

\begin{document}
Bla.
\missingfigure{This figure is missing}  
More bla.
\end{document}
1
  • 1
    This issue should be fixed in todonotes 1.0.5, which has just been uploaded to ctan.
    – midtiby
    Nov 2, 2016 at 13:14

3 Answers 3

5

The 2pt is the linewidth in the warning sign code, you can add a negative space to correct for it, or you could ignore it, presumably you will add the figure at some point. probably worth raising with the package maintainer.

\documentclass[12pt,a4paper]{report}
\usepackage[left=3.5cm,right=3.5cm,top=3cm,bottom=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[colorinlistoftodos, textwidth=\marginparwidth]{todonotes}

\makeatletter
\renewcommand{\missingfigure}[2][]{%
\setkeys{todonotes}{#1}%
\addcontentsline{tdo}{todo}{\@todonotes@MissingFigureText: #2}%
\par
\noindent\kern-2pt%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\begin{tikzpicture}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%vvvv
\draw[fill=\@todonotes@currentfigcolor, draw = black!40, line width=2pt]
    (-2, -2.5) rectangle +(\@todonotes@currentfigwidth, \@todonotes@currentfigheight);
\draw (2, -0.3) node[right, text
    width=\@[email protected]] {#2};
\draw[red, fill=white, rounded corners = 5pt, line width=10pt]
    (30:2cm) -- (150:2cm) -- (270:2cm) -- cycle;
\draw (0, 0.3) node {\@todonotes@MissingFigureUp};
\draw (0, -0.3) node {\@todonotes@MissingFigureDown};
\end{tikzpicture}\hfill
}% 
\begin{document}
Bla.
\missingfigure{This figure is missing}  
More bla.
\end{document}
1
  • You're right about adding the correct figure anyway. Although with dozens of missing figures it can spam the output messages and gets messy. Your solutions works like a charm. Thank you!
    – InDubio
    Oct 30, 2016 at 11:17
4

You can fix the bug by redefining the involved key:

\documentclass[12pt,a4paper]{report}
\usepackage[left=3.5cm,right=3.5cm,top=3cm,bottom=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[colorinlistoftodos, textwidth=\marginparwidth]{todonotes}

\makeatletter
\define@key{todonotes}%
    {figwidth}{\renewcommand{\@todonotes@currentfigwidth}{#1-2pt}}
\define@key{todonotes}%
    {figheight}{\renewcommand{\@todonotes@currentfigheight}{#1-2pt}}
\makeatother

\begin{document}
Bla.
\missingfigure{This figure is missing}
More bla.
\end{document}

This shortens both the width and the height by the thickness of the border. The hard coded thickness is 1pt.

2

Compliments, you have found a little bug of the package.

As David has already said, you can safely ignore it.

However, the package allows you to set the width of the missing figure. If you like, you may use this option to avoid the warning.

I've added \usepackage{showframe} only to show how the figure goes out of the margin. Obviously, don't add it to your document unless you need it for debugging purposes.

Moreover, I'd suggest to you to add \setlength{\marginparwidth}{2.9cm} otherwise the margin todo notes are too narrow.

\documentclass[12pt,a4paper]{report}
\usepackage[left=3.5cm,right=3.5cm,top=3cm,bottom=3cm]{geometry}
\usepackage[utf8]{inputenc}

\setlength{\marginparwidth}{2.9cm}% a suggestion
\usepackage[colorinlistoftodos, textwidth=\marginparwidth]{todonotes}

\usepackage{showframe}% only for testing purpose

\begin{document}
    Bla. 
    \missingfigure{This figure the original figure which causes the warning.} 
    \missingfigure[figwidth=\textwidth-2pt]{This is the figure with corrected width and no errors.} 
    More bla. 

    I suggest also to increase the \verb|\marginparwidth|.
    \todo{test todo note}
\end{document}

enter image description here

EDIT: If you have a lot of \missingfigure and don't like to put [figwidth=\textwidth-2pt] every time, you may add \renewcommand in your preamble:

\usepackage[colorinlistoftodos, textwidth=\marginparwidth]{todonotes}
\let\oldmissingfigure\missingfigure% save old command
\renewcommand{\missingfigure}[1]{\oldmissingfigure[figwidth=\textwidth-2pt]{#1}}% renew \missingfigure command

or, alternatively, if you need to use [figwidth=...] in some cases, you may create a \newcommand and use one or the other according to your needs:

\documentclass[12pt,a4paper]{report}
\usepackage[left=3.5cm,right=3.5cm,top=3cm,bottom=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{makecell}
\setlength{\marginparwidth}{2.9cm}% a suggestion

\usepackage[colorinlistoftodos, textwidth=\marginparwidth]{todonotes}

\newcommand{\missingfig}[1]{\missingfigure[figwidth=\textwidth-2pt]{#1}}% new \missingfigure command

\usepackage{showframe}% only for testing purpose

\begin{document}
Bla. 
\missingfig{This figure is missing with new command} 
More bla. 
\missingfigure[figwidth=0.5\textwidth]{This figure is missing half textwidth} 
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .