答案1
看tcolorbox
手动的对于参数的解释。
\documentclass{book}
%\usepackage{showframe}% only for testing purpose
\usepackage[most]{tcolorbox}
\tcbset{
opacityback=0,
enhanced jigsaw,
opacitybacktitle=0,
coltitle=black,
fonttitle=\bfseries,
titlerule=0pt,
titlerule style=white,
toptitle=4pt,
bottomtitle=0pt,
top=2pt,
left=1mm,
right=1mm,
}
\newtcolorbox{mydef}{
title=Definition,
grow to left by=2.5mm,% sum of the values: 1mm left margin + 1mm box sep + 0.5mm box rule = 2.5mm
grow to right by=2.5mm,
arc=3mm
}
\newtcolorbox{mymarpar}[1]{
title={\centering #1},
sharp corners,
grow to left by=-2.5mm
}
\usepackage{mwe}% only for testing purpose
\begin{document}
\chapter{A chapter}
\section{A section}
\blindtext% only for testing purpose
\begin{mydef}
This is my definition. Blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah.
\end{mydef}
Some text blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah
\marginpar{\begin{mymarpar}{The title of my first margin par}
Some text in my first marigin par blah blah blah
\end{mymarpar}}
Some other text blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah
\marginpar{\begin{mymarpar}{The title of my second margin par}
Some text in my second marigin par blah blah blah
\end{mymarpar}}
\blindtext % only for testing purpose
\end{document}
正如 Skillmon 在他的评论中所建议的那样,如果您使用,\marginnote
您可以更好地控制边距中框的垂直位置。
\documentclass{book}
\usepackage{marginnote}
%\usepackage{showframe}% only for testing purpose
\usepackage[most]{tcolorbox}
\tcbset{
opacityback=0,
enhanced jigsaw,
opacitybacktitle=0,
coltitle=black,
fonttitle=\bfseries,
titlerule=0pt,
titlerule style=white,
toptitle=4pt,
bottomtitle=0pt,
top=2pt,
left=1mm,
right=1mm,
}
\newtcolorbox{mydef}{
title=Definition,
grow to left by=2.5mm,% sum of the values: 1mm left margin + 1mm box sep + 0.5mm box rule = 2.5mm
grow to right by=2.5mm,
arc=3mm
}
\newtcolorbox{mymarpar}[1]{
title={\centering #1},
sharp corners,
grow to left by=-2.5mm
}
\usepackage{mwe}% only for testing purpose
\begin{document}
\chapter{A chapter}
\section{A section}
\blindtext% only for testing purpose
\begin{mydef}
This is my definition. Blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah.
\end{mydef}
Some text blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah
\marginnote{\begin{mymarpar}{The title of my first margin par}
Some text in my first marigin par blah blah blah
\end{mymarpar}}[-102pt]
Some other text blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah
\marginnote{\begin{mymarpar}{The title of my second margin par}
Some text in my second marigin par blah blah blah
\end{mymarpar}}[14pt]
\blindtext % only for testing purpose
\end{document}