framed or colored box with text and margin notes
Update:
The notes have been requested to be inside the story box. Now I offer two options, both of them with automatic numbering for the notes and with the possibility to cross-reference them:
In this first option, the box for the story has a width equal to
\textwidth
, but the story text goes to the left of the box; the notes appear to the left of the text:\documentclass[dvipsnames]{article} \usepackage[lmargin=2.5cm,textwidth=13cm,marginparwidth=5cm]{geometry} \usepackage[many]{tcolorbox} \usepackage{tikzpagenodes} \usetikzlibrary{tikzmark} \usepackage{lipsum} \newtcolorbox{story}[1][]{ width=\textwidth, fonttitle=\bfseries, breakable, extrude right by=4cm, fonttitle=\bfseries\color{Brown}, colframe=Melon, colback=Melon!10 #1} \newcounter{mynote} \newtcolorbox[use counter=mynote] {mynote}[1][] {title=Note~\thetcbcounter, width=4cm, left=0pt, right=0pt, fonttitle=\bfseries, coltitle=black, colframe=ForestGreen!40, colback=ForestGreen!10, #1 } \newcounter{tmp} \newcommand\StoryNote[3][]{% \stepcounter{tmp}% \tikzmark{mark-\thetmp}% \begin{tikzpicture}[remember picture,overlay] \node[inner sep=0pt,anchor=north west] at ([xshift=23pt]current page text area.east|-{pic cs:mark-\thetmp}) {\begin{mynote}[label=#3] #2 \end{mynote}}; \end{tikzpicture}% } \begin{document} \lipsum*[2] As we can see in notes~\ref{testa} and \ref{testb}... \begin{story} Some text\StoryNote{Some text here to illustrate the box for the notes.}{testa} for demo. \lipsum*[3]\StoryNote{Some text here to illustrate the box for the notes.}{testb} \lipsum*[3] \end{story} \end{document}
In this second option, the notes are placed using
wrapfigure
from thewrapfig
package, so that the story text wraps around the note text; this approach, however, must be carefully used due to restrictions (imposed bywrapfig
); in particular, one must guarantee that a note won't appear near a page break, notes can't be used inside lists.\documentclass[dvipsnames]{article} \usepackage[lmargin=2.5cm,textwidth=13cm,marginparwidth=5cm]{geometry} \usepackage[many]{tcolorbox} \usepackage{wrapfig} \usepackage{lipsum} \newtcolorbox{story}[1][]{ width=\textwidth, fonttitle=\bfseries, breakable, fonttitle=\bfseries\color{Brown}, colframe=Melon, colback=Melon!10 #1} \newcounter{mynote} \newtcolorbox[use counter=mynote] {mynote}[1][] {title=Note~\thetcbcounter, width=4cm, left=0pt, right=0pt, fonttitle=\bfseries, coltitle=black, colframe=ForestGreen!40, colback=ForestGreen!10, #1 } \newcommand\StoryNote[3][]{% \begin{wrapfigure}{r}{4cm} \begin{mynote}[label=#3] #2 \end{mynote}% \end{wrapfigure}% } \begin{document} \lipsum*[2] As we can see in notes~\ref{testa} and \ref{testb}... \begin{story} \StoryNote{Some text here to illustrate the box for the notes.}{testa} \lipsum[1] \StoryNote{Some text here to illustrate the box for the notes.}{testb} \lipsum[3] \end{story} \end{document}
Initial version:
Here's another option giving you automatic numbering for the notes and possibility to cross-reference them as required:
\documentclass[dvipsnames]{article}
\usepackage[lmargin=2.5cm,textwidth=13cm,marginparwidth=5cm]{geometry}
\usepackage[many]{tcolorbox}
\usepackage{marginnote}
\usepackage{lipsum}
\newtcolorbox{story}[1][]{
width=\textwidth,
fonttitle=\bfseries,
breakable,
fonttitle=\bfseries\color{Brown},
colframe=Melon,
colback=Melon!10
#1}
\newcounter{mynote}
\newtcolorbox[use counter=mynote]
{mynote}[1][]
{title=Note~\thetcbcounter,
width=5cm,
left=0pt,
right=0pt,
fonttitle=\bfseries\color{Brown},
colframe=Melon,
colback=Melon!10,
#1
}
\newcommand\StoryNote[3][]{%
\marginnote[#1]{%
\makebox[0pt][l]{\begin{mynote}[label=#3]
#2
\end{mynote}}}%
}
\begin{document}
\lipsum*[2] As we can see in notes~\ref{testa} and \ref{testb}...
\begin{story}
Some text\StoryNote{Some text here to illustrate the box for the notes.}{testa} for demo.
\lipsum*[3]\StoryNote{Some text here to illustrate the box for the notes.}{testb}
\lipsum*[3]
\end{story}
\end{document}
Remarks:
You write the text for the story inside the
story
environment (it has an optional argument allowing you to pass options (such as an eventual tile) to thetcolorbox
used.You write the notes using the
\StoryNote
command with syntax\SoryNote{<note text>}{<label>}
where is the text for the note itself and is the string that can be used to produce cross-references (see example code above). The notes are automatically numbered.
Change colours as you wish and see the documentation for more options in tcolorbox
. This should serve as a starter.
\documentclass[12pt]{article}
\usepackage[many]{tcolorbox}
\usepackage{marginnote}
\usepackage{kantlipsum}
\tcbuselibrary{skins,breakable}
\newtcolorbox{story}[1][]{
width=\textwidth,
colback=magenta!20,
colframe=red!75!black,
colbacktitle=blue!85!black,
fonttitle=\bfseries,
left=0ex,
right=0ex,
top=0pt,
arc=0pt,
outer arc=0pt,
leftrule=0pt,
rightrule=0pt,
toprule=0pt,
bottomrule=0pt,
breakable,
enhanced jigsaw,
title= #1}
\begin{document}
\kant[2]
\begin{story}[Some story]
Some text comes here just\marginnote{some note} for demo.
\kant[3]
\end{story}
\end{document}