tcolorbox의 라벨

tcolorbox의 라벨

링크에 있는 것과 같은 색상 상자가 있습니다.

라벨을 붙이는 방법은 무엇입니까? 내 간단한 코드는 다음과 같습니다

\documentclass{book}
\usepackage[listings,many]{tcolorbox}
\usetikzlibrary{calc}
\usepackage{listingsutf8}

\definecolor{myblue}{RGB}{20,105,176}

\tcbuselibrary{listingsutf8,breakable,skins}
\tcbset{listing engine=listings}
\tcbset{mystyle/.style={
  breakable,
  enhanced,
  rightrule=0pt,
  toprule=0pt,
  outer arc=0pt,
  arc=0pt,
  colframe=myblue,
  colback=white,
  attach boxed title to top left,
  boxed title style={
    colback=myblue,
    outer arc=0pt,
    arc=0pt,
    top=3pt,
    bottom=3pt,
    },
  fonttitle=\sffamily
  }
}

\newtcolorbox[auto counter,number within=section]{meubox}[1][]{
  mystyle,
  title=Example~\thetcbcounter,
  overlay unbroken and first={
      \path
        let
        \p1=(title.north east),
        \p2=(frame.north east)
        in
        node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
        at (title.east) {#1};
  }
}

\newtcblisting[use counter from=meubox]{meuboxcodigo}[2][]{
mystyle,
listing options={style=tcblatex},
listing only,
title=\thetcbcounter,
overlay unbroken and first={
  \path
    let
    \p1=(title.north east),
    \p2=(frame.north east)
    in
    node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
    at (title.east) {#1};
}
}

\newtcblisting[use counter from=meubox]{meuboxuso}[2][]{%
mystyle,
title=Exemplo \thetcbcounter,
overlay unbroken and first={
  \path
    let
    \p1=(title.north east),
    \p2=(frame.north east)
    in
    node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
    at (title.east) {#1};
  }
}

\begin{document}

\chapter{text 1}
\section{section text}

%label:box1
\begin{meubox}
Text text text
\end{meubox}

%label:box2
\begin{meuboxcodigo}[Preâmbulo para Língua Portuguesa]{}
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage[T1]{fontenc}
\usepackage{indentfirst}
\end{meuboxcodigo}

%label:box3
\begin{meuboxuso}{}
\begin{flushright}
Alinhando o texto.
\end{flushright}
\end{meuboxuso}

text text text \ref{box1}, \ref{box2},\ref{box3}
\end{document}

답변1

tcolorbox기본적으로 옵션 을 사용해야 합니다 label=. tcb 매뉴얼을 읽어보는 것이 좋습니다.

다음은 정의를 취하고 필수 인수를 사용하여 레이블을 가져오는 버전 중 하나입니다. 필요에 맞게 수정하세요.

tcolorbox 라벨

\documentclass{book}
\usepackage[listings,many]{tcolorbox}
\usetikzlibrary{calc}

\definecolor{myblue}{RGB}{20,105,176}

\tcbset{listing engine=listings}
\tcbset{mystyle/.style={
  breakable,
  enhanced,
  rightrule=0pt,
  toprule=0pt,
  outer arc=0pt,
  arc=0pt,
  colframe=myblue,
  colback=white,
  attach boxed title to top left,
  boxed title style={
    colback=myblue,
    outer arc=0pt,
    arc=0pt,
    top=3pt,
    bottom=3pt,
    },
  fonttitle=\sffamily
  }
}

\newtcolorbox[auto counter,number within=section]{meubox}[2][]{
  mystyle,
  title=Example~\thetcbcounter,
  overlay unbroken and first={
      \path
        let
        \p1=(title.north east),
        \p2=(frame.north east)
        in
        node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
        at (title.east) {#1};
  },
  label=#2
}

\newtcblisting[use counter from=meubox]{meuboxcodigo}[2][]{
mystyle,
listing options={style=tcblatex},
listing only,
title=\thetcbcounter,
overlay unbroken and first={
  \path
    let
    \p1=(title.north east),
    \p2=(frame.north east)
    in
    node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
    at (title.east) {#1};
},
label=#2
}

\newtcblisting[use counter from=meubox]{meuboxuso}[2][]{%
mystyle,
title=Exemplo \thetcbcounter,
overlay unbroken and first={
  \path
    let
    \p1=(title.north east),
    \p2=(frame.north east)
    in
    node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
    at (title.east) {#1};
  },label=#2
}

\begin{document}

\chapter{text 1}
\section{section text}

%label:box1
\begin{meubox}{box1}
Text text text
\end{meubox}

%label:box2
\begin{meuboxcodigo}[Preâmbulo para Língua Portuguesa]{box2}
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage[T1]{fontenc}
\usepackage{indentfirst}
\end{meuboxcodigo}

%label:box3
\begin{meuboxuso}{box3}
\begin{flushright}
Alinhando o texto.
\end{flushright}
\end{meuboxuso}

text text text \ref{box1}, \ref{box2},\ref{box3}
\end{document}

관련 정보