我正在尝试对齐“mylib”tcolorbox(如在这篇文章中所示:如何在 tcolorbox 中重现此框) 及其周围的文本(见下图)。但是,我无法使用 nobeforeafter 或负数“before skip”获得正确的垂直间距
我需要一些帮助才能让它工作,
感谢您的帮助,
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcbox{\mylib}[1]{parbox=true,enhanced,nobeforeafter,tcbox raise base,boxrule=0.4pt,top=-0.5mm,bottom=0mm,height=2.5mm,
right=0mm,left=4mm,arc=1pt,boxsep=2pt,
colframe=black,coltext=black,colback=black!10!white,
overlay={\begin{tcbclipinterior}\fill[black!75] (frame.south west)
rectangle node[text=white,font=\sffamily\bfseries\tiny] {#1} ([xshift=4mm]frame.north west);\end{tcbclipinterior}}}
\begin{document}
\scriptsize{
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula \mylib{\fontsize{1.5}{1}{XX}}{YY} augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices.
}
\end{document}
答案1
我找到了如何手动设置与基线的对齐方式:
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcbox{\mylib}[1]{parbox=true,enhanced,nobeforeafter,tcbox raise base,boxrule=0.4pt,top=-0.5mm,bottom=0mm,height=2.5mm,
right=0mm,left=4mm,arc=1pt,boxsep=2pt,baseline=0.4mm,
colframe=black,coltext=black,colback=black!10!white,
overlay={\begin{tcbclipinterior}\fill[black!75] (frame.south west)
rectangle node[text=white,font=\sffamily\bfseries\tiny] {#1} ([xshift=4mm]frame.north west);\end{tcbclipinterior}}}
\begin{document}
\scriptsize{
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula \mylib{\fontsize{1.5}{1}{XX}}{YY} augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices.
}
\end{document}