相信很多人都問過這個問題,但我找不到正確的答案。
我想追蹤我給出 tcb 定理的標籤/金鑰。我不知道遇到此問題的最佳實踐,我希望在文件中的某個位置有一個部分或章節,但我也對 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 的給定參考。如果我像這樣標記它:
{for example Pi\label{def:Pi2}}
我想說,這走向了錯誤的方向,為什麼當我完成了之前的所有努力後,我應該給一切貼上標籤。
也許我必須
\usepackage{nameref}
\usepackage{showkeys}
\usepackage{showexpl}
以不同的方式開始,但我沒有找到任何相關資訊。我也在tcolorbox - 手冊中搜尋了很多時間: 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}