2
\documentclass{article}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}
\usepackage[colorinlistoftodos]{todonotes}


\begin{document}
\listoftodos[Notes]
Note is here\todo{Sample note!}
\begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black,title=My title]
  My box with my \todo{note doesn't show}title.
\end{tcolorbox}
\end{document}

Output: enter image description here

What happened to my todo note? It seems that it is being forced into the background when I put the tcolorbox, but i'd like to have a todo note sticking out from inside the tcolorbox. What can I do to fix this?

4
  • Your code misses a \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 nesting tikzpictures. (This does not mean that you can't have something sticking out of the tcolorbox but it may be more complicated to achieve. The first step in this direction would be that you provide a complete compilable code.)
    – user121799
    Jun 7, 2019 at 0:22
  • The code works for me (I am using overleaf). I had the \documentclass line, but it didn't show. I have fixed it now, thanks for pointing it out
    – Evan Kim
    Jun 7, 2019 at 0:29
  • Well, it does not work on my TeXLive installation. I understand that this is not your fault but I added this code to this discussion, hoping that overleaf will eventually fix this issue that costs all of us time and nerves for no obvious reason.
    – user121799
    Jun 7, 2019 at 0:33
  • On Overleaf v2 this code will produce an error: LaTeX 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).
    – moewe
    Jun 7, 2019 at 7:12

1 Answer 1

6

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

demo


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}

You must log in to answer this question.

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