答案1
您可以做类似的事情(我假设您正在使用 pdflatex)。在我看来,没有合理的方法可以在这样的 todonotes 内设置换行符,因此我将最大尺寸设置为 5cm。但由于它们无论如何都会破坏布局,我认为长注释中的大行距或糟糕的换行符并不重要。
代码自然会改变所有内联待办事项。
\documentclass{article}
\usepackage{todonotes,varwidth}
\makeatletter
\tikzstyle{diaanotestyle} = [
draw=\@todonotes@currentbordercolor,
fill=\@todonotes@currentbackgroundcolor,
line width=0.5pt,
inner sep = 0.8 ex,
rounded corners=4pt,align=left,
]
\renewcommand{\@todonotes@drawInlineNote}{%
{\begin{tikzpicture}[remember picture,baseline={(0,0)}]%
\draw node[diaanotestyle,font=\@todonotes@sizecommand,anchor=base west]{%
\begin{varwidth}[t]{5cm}
\if@todonotes@authorgiven%
{\@todonotes@sizecommand \@todonotes@author:\,\@todonotes@text}%
\else%
{\@todonotes@sizecommand \@todonotes@text}%
\fi
\end{varwidth}};%
\end{tikzpicture}}%
}%
\makeatother
\author{diaa}
\begin{document}
some text \todo[inline]{my note} another text \todo[inline]{a long comment a long comment a long comment a long commenta long comment a long comment} abllclc blblb blblb blblb blblb blblbl blblb
\end{document}
编辑
如果你真的需要在笔记中换行,你可以尝试使用这个答案LaTeX 中的酷炫文本突出显示。请注意,灵魂密码相当脆弱。并非所有内容都可以在不加保护的情况下放入注释文本中。阅读文档。
举个例子(我没有时间调整样式):
\documentclass{article}
\usepackage{todonotes}
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\makeatletter
\newcommand{\defhighlighter}[3][]{%
\tikzset{every highlighter/.style={color=#2, fill opacity=#3, #1}}%
}
\defhighlighter{yellow}{.5}
\newcommand{\highlight@DoHighlight}{
\fill [ decoration = {random steps, amplitude=1pt, segment length=15pt}
, outer sep = -15pt, inner sep = 0pt, decorate
, every highlighter, this highlighter ]
($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ;
}
\newcommand{\highlight@BeginHighlight}{
\coordinate (begin highlight) at (0,0) ;
}
\newcommand{\highlight@EndHighlight}{
\coordinate (end highlight) at (0,0) ;
}
\newdimen\highlight@previous
\newdimen\highlight@current
\DeclareRobustCommand*\highlight[1][]{%
\tikzset{this highlighter/.style={#1}}%
\SOUL@setup
%
\def\SOUL@preamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@BeginHighlight
\highlight@EndHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@postamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@EndHighlight
\highlight@DoHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@everyhyphen{%
\discretionary{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@sethyphenchar
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everyexhyphen##1{%
\SOUL@setkern\SOUL@hyphkern
\hbox{##1}%
\discretionary{%
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everysyllable{%
\begin{tikzpicture}[overlay, remember picture]
\path let \p0 = (begin highlight), \p1 = (0,0) in \pgfextra
\global\highlight@previous=\y0
\global\highlight@current =\y1
\endpgfextra (0,0) ;
\ifdim\highlight@current < \highlight@previous
\highlight@DoHighlight
\highlight@BeginHighlight
\fi
\end{tikzpicture}%
\the\SOUL@syllable
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}%
\SOUL@
}
\renewcommand{\@todonotes@drawInlineNote}{%
{%
\expandafter\highlight\expandafter{\@todonotes@text }%
}}%
\makeatother
\author{diaa}
\begin{document}
some text \todo[inline]{my note} another text \todo[inline]{a long comment a long comment a long comment a long commenta long comment a long comment} abllclc blblb blblb blblb blblb blblbl blblb
\end{document}
答案2
我建议定义以下命令
\newcommand{\inline}[1]{{\color{red}{#1}} \addcontentsline{tdo}{todo}{#1}}
然后,注释会被高亮显示并添加到待办事项列表中。这是一个非常简单的方法,但当注释覆盖多行时似乎很有效。
现在我无法更改文本的背景颜色,因此我选择更改文本的颜色。
\documentclass{article}
\usepackage{todonotes}
\newcommand{\inline}[1]{{\color{red}{#1}} \addcontentsline{tdo}{todo}{#1}}
\begin{document}
\listoftodos
\section{Section name}
Some text before the comment.
\inline{A comment that span several lines. A comment that
span several lines. A comment that span several lines.}
Some text after the comment.
\end{document}
答案3
您必须更改 todonotes 的一些内部结构。有以下几件事:
- 使用 tikz 绘制节点,特别是获取正确的基线
- 消除周围的 \par 和文本宽度
- 不要吞噬节点周围的空间
下面的代码可以实现这个功能:
\makeatletter
\tikzstyle{inlinenotestyle} = [
draw=\@todonotes@currentbordercolor,
fill=\@todonotes@currentbackgroundcolor,
line width=0.5pt,
inner sep = 0.8 ex,
rounded corners=4pt]
\renewcommand{\@todonotes@drawInlineNote}{%
{\begin{tikzpicture}[remember picture,baseline=(current bounding box.base)]%
\draw node[inlinenotestyle,font=\@todonotes@sizecommand, anchor=base,baseline]{%
\if@todonotes@authorgiven%
{\noindent \@todonotes@sizecommand \@todonotes@author:\,\@todonotes@text}%
\else%
{\noindent \@todonotes@sizecommand \@todonotes@text}%
\fi};%
\end{tikzpicture}}}%
\newcommand{\mytodo}[1]{\@todo[inline]{#1}}%
\makeatother
然后使用它:
Some text. \mytodo{my note} More text.