![某一节中 tcbtheorems 的标签或键](https://linux22.com/image/472484/%E6%9F%90%E4%B8%80%E8%8A%82%E4%B8%AD%20tcbtheorems%20%E7%9A%84%E6%A0%87%E7%AD%BE%E6%88%96%E9%94%AE.png)
我确信很多人已经问过这个问题,但我找不到正确的答案。
我想跟踪我提供给 tcbtheorem 的标签/键。我不知道遇到此问题的最佳做法,我希望在文档的某个地方有一个部分或章节,但我也希望在 pdf 的边距部分中有标签/键。
我看到了这个想法,最好将标签/键放在 pdf 的边缘部分。
但是当我尝试这样解决时,当我使用 \label{} 时我确实得到了预期的结果(参见下面提供的代码)
还
% Command to automatically display the reference
\newcommand{\autoNameref}[1]{\nameref{def:#1}}
\begin{document}
\tcblistof[\section*]{def}{List of Defenition}
工作正常。
但我在边距部分或其他地方看不到 def:Pi 或 def:TestRef 的给定引用。如果我像这样 \label 它:
{for example Pi\label{def:Pi2}}
我想说,这走错了方向,为什么我在做了之前的所有努力之后还要给所有事情贴上标签。
也许我必须
\usepackage{nameref}
\usepackage{showkeys}
\usepackage{showexpl}
以不同的方式启动它,但我找不到有关此的任何信息。我也在 tcolorbox - manual 中搜索了很多时间: tcolorbox - 手册
我将不胜感激任何提示或解决方案。
感谢您的帮助。
我尝试尽可能缩短我的序言,因为我确信这样是没问题的。
以下代码:
\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{nameref}
\usepackage{showkeys}
\usepackage{showexpl}
% Math packages + Access additional mathematical symbols
\usepackage{amsmath,amsfonts,amsthm,amssymb,mathtools}
% Hyperlinks and PDF properties
\usepackage{hyperref,theoremref}
% Colored boxes and tcolorbox configurations
\usepackage[most,many,breakable]{tcolorbox}
% Libraries for diagrams and plots
\usepackage{tikz-cd}
\usepackage{pgfplots}
\usetikzlibrary{
% tcolorbox some boxes
arrows,
calc,
shadows.blur}
% Conditional commands
\usepackage{xparse}
% Dummy text generator
\usepackage{lipsum} % For generating placeholder text
% store a big set of sentences
\unpacklipsum[1-100]
\ExplSyntaxOn
% unpack \lipsumexp
\seq_new:N \g_lipsum_sentences_seq
\cs_generate_variant:Nn \seq_set_split:Nnn { NnV }
\seq_gset_split:NnV \g_lipsum_sentences_seq {.~} \lipsumexp
\NewDocumentCommand{\lipsumsentence}{>{\SplitArgument{1}{-}}O{1-7}}
{
\lipsumsentenceaux #1
}
\NewDocumentCommand{\lipsumsentenceaux}{mm}
{
\IfNoValueTF { #2 }
{
\seq_item:Nn \g_lipsum_sentences_seq { #1 }.~
}
{
\int_step_inline:nnnn { #1 } { 1 } { #2 }
{
\seq_item:Nn \g_lipsum_sentences_seq { ##1 }.~
}
}
}
\ExplSyntaxOff
\setlength{\parindent}{1cm}
\tcbset{
BandarolGroundStyle/.style={
attach boxed title to top left={xshift=1cm,yshift*=1mm-\tcboxedtitleheight},
varwidth boxed title*=-3cm,
boxed title style={frame code={
\path[fill=tcbcolback]
([yshift=-1mm,xshift=-1mm]frame.north west)
arc[start angle=0,end angle=180,radius=1mm]
([yshift=-1mm,xshift=1mm]frame.north east)
arc[start angle=180,end angle=0,radius=1mm];
\path[left color=tcbcolback!60!black,right color=tcbcolback!60!black,
middle color=tcbcolback!80!black]
([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
[rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
-- (frame.south east) -- (frame.south west)
-- ([xshift=-1mm,yshift=-1mm]frame.north west)
[sharp corners]-- cycle;
}
,interior engine=empty
},
fonttitle=\bfseries,
label separator=:
},
defstyle/.style={
enhanced,
before skip=2mm,
after skip=2mm,
colback= #1!5,
colframe= #1!80!black,
colbacktitle= #1!75!black,
boxrule=0.5mm,
BandarolGroundStyle
}
}
%================================
% DEFINITION BANDAROLLED THEOREMS
%================================
% list inside={def} maybe a good idea but check it later
% \tcblistof[\section*]{def}{List of Defenition}
\newtcbtheorem[number within=section, list inside={def}]{Definition}{Definition}{defstyle=red, title={#2},#1}{def}
%================================
% xparse commands for theorems:
%================================
% reason:
% https://tex.stackexchange.com/questions/48355/latex-command-with-optional-arguments
% It is also possible to use optional Arguments:
% r = required Argument
% o = optional Argument
% O = optional Argument if empty default value
% Order of the Attributes (Ref, Titel, Body)
% not working because of \MainAttributes in command...
% \newcommand\MainAttributes{O +m +m}
% Order so it is correct with the newtcbtheorem initialisation
% not working because of \MainOrder in command...
% \edef\MainOrder{\{\#2\}\{\#1\}\#3}
% solutions:
% https://tex.stackexchange.com/questions/551429/how-to-use-newdocumentcommand
% https://tex.stackexchange.com/questions/139614/you-cant-use-macro-parameter-character-in-restricted-horizontal-mode
% https://tex.stackexchange.com/questions/393622/using-key-values-in-newdocumentcommand
% to less time maybe a revisit later...
%================================
% DEFINITION BANDAROLLED THEOREMS
%================================
\NewDocumentCommand {\dfn} {O +m +m}{
\begin{Definition}{#2}{#1}#3
\end{Definition}}
% Customize the format for displaying keys and labels
\renewcommand*\showkeyslabelformat[1]{\normalfont\small\ttfamily#1}
% Command to automatically display the reference
\newcommand{\autoNameref}[1]{\nameref{def:#1}}
\begin{document}
\tcblistof[\section*]{def}{List of Defenition}
\label{test}
\lipsum[1]
\dfn[Pi]{A defined Number }{for example Pi}
\lipsum[2]
\nameref{def:Pi} \ref{def:Pi}
\begin{LTXexample}[pos=r, width=0.5\linewidth]
\dfn[TestRef]{RefTest}{TextRefTest}
\end{LTXexample}
\end{document}
答案1
嗯,标签在那里,但它隐藏在 tcolorbox 的标题后面,因为出于某种原因 showkeys 使用了\rlap
。您可以将其移动到边距中:
\documentclass[12pt,a4paper]{book}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{showkeys}
\usepackage{hyperref}
\usepackage[most,many,breakable]{tcolorbox}
\newtcbtheorem[number within=section, list inside={def}]
{Definition}{Definition}{
frame empty,coltitle=red, %to remove the background
title={#2},#1}{def}
\begin{document}
\section{A}\label{test}
\section{B}\label{longertest}
\begin{Definition}{A defined Number }{Pi}
for example Pi
\end{Definition}
\renewcommand*\showkeyslabelformat[1]
{%
\normalfont\small\ttfamily
\llap{\fbox{#1}\hspace{\marginparsep}}%
}
\begin{Definition}{A defined Number }{ratio}
for example the golden ratio
\end{Definition}
\ref{test}, \ref{def:Pi}
\end{document}