(サブ)ラベルのカスタム参照テキスト (ここではサブ図のような tcolorbox 用)

(サブ)ラベルのカスタム参照テキスト (ここではサブ図のような tcolorbox 用)

理由としてはtcolorbox ではフロートをネストできませんそして、私の(サブ)フィギュアをもっと派手にしたかったので、newFigureSubfigurenewtcolorbox環境をコーディングしました。以下は私のコードの簡略版です。

\documentclass[12pt,a4paper]{book}
\usepackage{lipsum}
\usepackage[skins, breakable]{tcolorbox}


\newcommand{\figref}[1]{Figure \ref{fig:#1}}

\newtcolorbox[auto counter]{Figure}[1]{
    title = {Figure~\thetcbcounter~$-$ #1}
    }
    
\newtcolorbox[
        auto counter,
        number within=tcb@cnt@Figure,
        number freestyle = {(\noexpand\alph{\tcbcounter})}
        ]
        {Subfigure}[3][]{
    width = (\linewidth - 4\dimexpr (#2pt - 1pt)\relax)/#2,
    before =,
    after = \hfill,
    box align = center,
    title = {\thetcbcounter~#3},
    #1
    }


\begin{document}

\begin{Figure}
    {Title figure}
    \begin{Subfigure}[label={fig:a}]{2}
        {Title again}
        \lipsum[1]
    \end{Subfigure}%
    %
    \begin{Subfigure}{2}
        {A nice Subfigure}
        \lipsum[2]
    \end{Subfigure}
\end{Figure}


See \figref{a}.

\end{document}

出力で

ムウェ

結果は気に入っていますが、サブ図のタイトルを変更せずに、 のFigure 1a代わりにテキストを印刷したいと思います。より正確には、サブ図のカウンターとしてを持つように newtcolorbox の引数を変更することができますが、これによりタイトルが から に変更され、これは望ましくありません。Figure (a)number freestyle1a(a) blabla1a blabla

hyperref最小限の動作例からパッケージを削除した場合でも、パッケージを使用していることに注意してください。

私は知っている同様の質問質問されましたが、私の質問とどれくらい近いのか分かりません。

\makeatletter
\newcommand{\customlabel}[2]{%
\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{}}}}
\makeatother

...をしています。

答え1

ラベルのフォーマットを変更するには\labelformatltnews30.pdf詳細については):

\documentclass[12pt,a4paper]{book}
\usepackage{lipsum}
\usepackage[skins, breakable]{tcolorbox}


\newcommand{\figref}[1]{Figure \ref{fig:#1}}

\newtcolorbox[auto counter]{Figure}[1]{
    title = {Figure~\thetcbcounter~$-$ #1}
    }
    
\newtcolorbox[
        auto counter,
        number within=tcb@cnt@Figure,
        number freestyle = {(\noexpand\alph{\tcbcounter})}
        ]
        {Subfigure}[3][]{
    width = (\linewidth - 4\dimexpr (#2pt - 1pt)\relax)/#2,
    before =,
    after = \hfill,
    box align = center,
    title = {\thetcbcounter~#3},
    #1
    }

\labelformat{tcb@cnt@Subfigure}{\arabic{tcb@cnt@Figure}\alph{tcb@cnt@Subfigure}}

\begin{document}

\begin{Figure}
    {Title figure}
    \begin{Subfigure}[label={fig:a}]{2}
        {Title again}
        \lipsum[1]
    \end{Subfigure}%
    %
    \begin{Subfigure}{2}
        {A nice Subfigure}
        \lipsum[2]
    \end{Subfigure}
\end{Figure}


See \figref{a}.

\end{document}

ここに画像の説明を入力してください

ところで、cleveref独自の を定義する代わりに、も使用することをお勧めします\figref

関連情報