Only \todo[inline]{...}
can be used inside anything else, otherwise you get a "Not in outer par mode" error. Alas, the inline version does not create the (inNote)
coordinate used to draw the lines.
The following fakes a \todo
note using \marginpar
and a couple of \tikzmark
s. The tcolorbox environment allows \tikzmark
inside (probably redefines it). The hardest part was centering the point where the line hits the \marginpar
.
\documentclass{article}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}
\usepackage[colorinlistoftodos]{todonotes}
\usetikzlibrary{tikzmark}
\begin{document}
\listoftodos[Notes]
Note is here\todo{Sample note!}
\marginpar{\sbox0{\todo[inline]{note doesn't show}}% measure height
\raisebox{0.5\ht0}{\tikzmark{inNote}}\usebox0}%
\begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black,title=My title]
My box with my \tikzmark{inText}title.
\end{tcolorbox}
\tikz[remember picture,overlay]{\draw[orange,thick] (pic cs:inNote) -- ++(-0.5\marginparsep,0) |- (pic cs:inText);}%
\end{document}

This version does the same thing (more or less) in more streamlined manner. It separates \todo
into \todonote
and \todomark
, where \todonote
must go outside the tcolorbox but \todomark
can go inside. The optional argument can be used to put more than one \todomark
inside a tcolorbox at a time and make sure the right marks and notes connect.
\documentclass{article}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}
\usepackage[colorinlistoftodos]{todonotes}
\newsavebox{\todobox}
\newcommand{\todonote}[2][inNote]% #1 = coordinate id (optional), #2 = note
{\marginpar{\savebox\todobox{\todo[inline]{#2}}% measure height
\begin{tikzpicture}[remember picture, overlay]
\coordinate (#1) at (0pt,0.5\ht\todobox);
\end{tikzpicture}\usebox\todobox}}
\newcommand{\todomark}[1][inNote]% #1 = coordinate id (optional)
{\begin{tikzpicture}[remember picture, overlay]
\draw[orange,thick] (#1) -- ++(-0.5\marginparsep,0)
|- (0pt,\lineskip-\dp\strutbox);
\end{tikzpicture}}
\begin{document}
\listoftodos[Notes]
Note is here\todo{Sample note!}
\todonote{note doesn't show}% must be outside tcolorbox
\begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black,title=My title]
My box with my \todomark title.
\end{tcolorbox}
\end{document}
\documentclass
. If I add\documentclass{article}
, I get (unsurprisingly) an error! LaTeX Error: Float(s) lost.
. And it is not too surprising that there are complications beyond that, after all you are nestingtikzpicture
s. (This does not mean that you can't have something sticking out of thetcolorbox
but it may be more complicated to achieve. The first step in this direction would be that you provide a complete compilable code.)\documentclass
line, but it didn't show. I have fixed it now, thanks for pointing it outLaTeX Error: Float(s) lost
. But Overleaf will still produce a PDF and will only show the error message after you click on the 'Logs and output files' button (which is highlighted with a red 1). Never ignore the tiny visual cues that try to draw your attention to the 'logs and output file' button (either red for errors or orange for warnings).