使用包 todonotes 和命令 missingfigure 时出现 Badbox

使用包 todonotes 和命令 missingfigure 时出现 Badbox

\missingfigure当我在 LaTeX 中使用该包的命令时,总是会出现 badbox 消息todonotes。是否需要调整几何选项?

错误信息:Overfull \hbox(2.0pt too wide) in paragraph at lines 8--10

代码:

\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

2pt 是警告标志代码中的线宽,您可以添加负空间来纠正它,或者您可以忽略它,大概您会在某个时候添加图形。可能值得向软件包维护者提出。

\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}

答案2

您可以通过重新定义所涉及的键来修复该错误:

\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}

这会将宽度和高度都缩短边框的厚度。硬编码厚度为 1pt。

答案3

恭喜,您发现了包中的一个小错误。

正如 David 已经说过的,您可以放心地忽略它。

但是,该包允许您设置缺失图形的宽度。如果您愿意,可以使用此选项来避免警告。

我添加它\usepackage{showframe}只是为了显示图形如何超出边距。显然,除非出于调试目的需要,否则不要将其添加到文档中。

此外,我建议您添加\setlength{\marginparwidth}{2.9cm},否则待办事项注释的边距太窄了。

\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}

在此处输入图片描述

编辑:如果您有很多\missingfigure并且不喜欢[figwidth=\textwidth-2pt]每次都放,您可以\renewcommand在序言中添加:

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

或者,如果您在某些情况下需要使用[figwidth=...],您可以根据需要创建\newcommand并使用其中一个:

\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}

相关内容