![将 tcolorbox 覆盖书签设置为位于其父级上方](https://linux22.com/image/428114/%E5%B0%86%20tcolorbox%20%E8%A6%86%E7%9B%96%E4%B9%A6%E7%AD%BE%E8%AE%BE%E7%BD%AE%E4%B8%BA%E4%BD%8D%E4%BA%8E%E5%85%B6%E7%88%B6%E7%BA%A7%E4%B8%8A%E6%96%B9.png)
我为我的添加了一个新环境康奈尔风格的笔记:titlednote
它允许为注释添加标题,注释还应在其下方生成书签term
。但由于terms
使用覆盖层实现,因此定义 的tcolorbox
书签不在覆盖层下方。titlednote
term
Date
以下是书签应位于下方的示例Meeting Context
本cornell.cls
示例如下:
\ProvidesClass{cornell}
\LoadClass[a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary
{
breakable,% Allows tcolorboxes to break across pages
hooks,% Allows usage of hooks, like having an overlay only for the first part of a broken box
skins,% Used to style the boxes with tikz
xparse% Used to define document environments and commands
}
\usepackage[margin=2cm]{geometry} % Change geometry of pages
\usepackage[parfill]{parskip} % Modify parindent and parskip
\usepackage{enumitem} % Modify itemize spacing
\setitemize
{
itemsep=0pt,
parsep=2pt,
}
\usepackage{bookmark} % Add bookmarks to the resulting PDF
\usepackage{hyperref}
\hypersetup
{
colorlinks = true, % Colour links instead of ugly boxes
urlcolor = blue, % Colour for external hyperlinks
linkcolor = blue, % Colour of internal links
citecolor = red % Colour of citations
}
\date{}
\tcbset
{
colframe=black,
colupper=black,
opacitybacktitle=1,
opacitytext=1,
fonttitle=\large\bfseries\sffamily,
}
\NewTColorBox[]{titlebox}{ o }
{
width=\textwidth,
lowerbox=invisible,
bookmark*={level=0}{\@title}
}
\renewcommand{\maketitle}
{
\vspace{-3em}
\begin{titlebox}
\Huge{\sffamily{\@title}}
\end{titlebox}
}
\NewTColorBox[]{extra}{ m }
{
width=\textwidth,
title=#1,
bookmark*={level=1}{#1},
}
\NewTColorBox[]{term}{ m }
{
width=.325\textwidth,
bookmark*={level=1}{#1},
}
\NewTColorBox[]{note}{ o }
{
enhanced,
breakable,
enlarge left by=.34\textwidth,
width=.66\textwidth,
parbox=false,% restore main text formatting behavior
overlay unbroken={
\IfNoValueF{#1} {%
\node[anchor=north west, outer sep=0pt, inner sep=0pt] at ([xshift=-.34\textwidth]frame.north west) {
\begin{term}{#1}
#1
\end{term}
};
}{}
},
overlay first app={
\IfNoValueF{#1} {%
\node[anchor=north west, outer sep=0pt, inner sep=0pt] at ([xshift=-.34\textwidth]frame.north west) {
\begin{term}{#1}
#1
\end{term}
};
}{}
}
}
\NewTColorBox[]{titlednote}{ om }
{
enhanced,
breakable,
title=#2,
bookmark*={level=2}{#2},
enlarge left by=.34\textwidth,
width=.66\textwidth,
parbox=false,% restore main text formatting behavior
overlay unbroken={
\IfNoValueF{#1} {%
\node[anchor=north west, outer sep=0pt, inner sep=0pt] at ([xshift=-.34\textwidth]frame.north west) {
\begin{term}{#1}
#1
\end{term}
};
}{}
},
overlay first app={
\IfNoValueF{#1} {%
\node[anchor=north west, outer sep=0pt, inner sep=0pt] at ([xshift=-.34\textwidth]frame.north west) {
\begin{term}{#1}
#1
\end{term}
};
}{}
}
}
生成截图的样本如下:
\documentclass{cornell}
\title{Some meeting notes}
\begin{document}
\maketitle
\begin{titlednote}[Meeting Context]{Date}
Wednesday
\end{titlednote}
\begin{titlednote}{Moderator}
Max Mustermann
\end{titlednote}
\begin{titlednote}{Participants}
\begin{itemize}
\item A
\item B
\item C
\item D
\end{itemize}
\end{titlednote}
\end{document}
我尝试titlednode
通过将 从一个覆盖更改term
为一个单独的 来修改环境tcolorbox
。这解决了书签的问题,但它引入了一个布局问题:
\NewDocumentEnvironment{titlednote}{ om }
{
\IfNoValueF{#1}{
\begin{term}{#1}
#1
\end{term}
}
\begin{tcolorbox}[
enhanced,
breakable,
title=#2,
bookmark*={level=2}{#2},
enlarge left by=.34\textwidth,
width=.66\textwidth,
parbox=false,% restore main text formatting behavior
]
}
{
\end{tcolorbox}
}
结果如下:
我没有找到一种方法来计算(动态)高度term
tcolorbox
以便使用负数vspace
。这可以解决问题,但一定有办法解决这个问题。
答案1
@ThomasF.Sturm 在评论中提供了该问题的解决方案。为了完整起见,这里将其应用于我的问题。
不要在覆盖层中定义书签,而是在父级中定义书签tcolorbox
。为了做到这一点,可以检查是否提供了术语的可选参数。
\NewTColorBox[]{term}{ m }
{
width=.325\textwidth,
% bookmark*={level=1}{#1}, %<< Redundant, now set by titlednote environment
}
\NewTColorBox[]{titlednote}{ om }
{
enhanced,
breakable,
title=#2,
IfValueT={#1}{bookmark*={level=1}{#1}}, %<< Set term bookmark only if it was provided
bookmark*={level=2}{#2},
enlarge left by=.34\textwidth,
width=.66\textwidth,
parbox=false,
overlay unbroken={
\IfNoValueF{#1} {%
\node[anchor=north west, outer sep=0pt, inner sep=0pt] at ([xshift=-.34\textwidth]frame.north west) {
\begin{term}{#1}
#1
\end{term}
};
}{}
},
overlay first app={
\IfNoValueF{#1} {%
\node[anchor=north west, outer sep=0pt, inner sep=0pt] at ([xshift=-.34\textwidth]frame.north west) {
\begin{term}{#1}
#1
\end{term}
};
}{}
}
}