사이드바에 tcolorbox 사용

사이드바에 tcolorbox 사용

wrapfigure나는 내가 가지고 있는 사이드바 환경을 tcolorbox. 그러나 몇 가지 문제가 발생했습니다.

참고로 내 이전 환경은 다음과 같습니다.

\makeatletter
\newenvironment*{sidebar}[3][0.5\textwidth]
{
    % less vertical margin around wrapfigures
    \setlength{\intextsep}{0pt}
    \colorlet{savedcolor}{inline code}
    \colorlet{inline code}{inline code inverted}
    \renewcommand{\dummy}{#1}
    \wrapfigure{#2}{#1}
        \renewcommand{\@currentlabel}{#3}
        \renewcommand{\@currentlabelname}{#3}
        \phantomsection
        \rule{#1}{1pt}

        \rule{#1}{18pt}

        \vspace{-18pt}
        \centerline{\textcolor{white}{#3}}

        \vspace{5pt}
        \footnotesize
        \leftskip=5pt
        \rightskip=5pt
        \setlength{\parskip}{0.2cm}
        \setlength{\parindent}{0pt}
        % restore the inline code color for the body of the bar
        \colorlet{inline code}{savedcolor}
}
{

        \leftskip=0pt
        \rightskip=0pt
        \setlength{\parindent}{0pt}
        \rule{\dummy}{1pt}
        \rule[.19in]{\dummy}{2.5pt}
    \endwrapfigure
}
\makeatother

작동하지만 예쁘지는 않습니다. 이것이 tcolorbox제가 다른 상황에서 성공적으로 사용했기 때문에 를 사용하려고 하는 이유입니다 .

지금까지 내가 가지고 있는 MWE는 다음과 같습니다.

% !TEX program = xelatex

\documentclass{scrbook}

\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage{listings}
\usepackage{blindtext}
\usepackage{hyperref}

\definecolor{inline code}{RGB}{194,61,53}
\definecolor{inline code inverted}{RGB}{193,153,151}

\newcommand*{\code}{\lstinline[basicstyle=\fontsize{9}{11}\ttfamily\color{inline code},keywordstyle=\color{inline code},stringstyle=\color{inline code},keepspaces=true]}

\newtcolorbox{cbar}[2][]{
    parbox=false, % normal paragraph spacing
    height from=2.5cm to 100cm,
    halign=justify,
    sharp corners,
    colframe=black,
    colback=black!15!white,
    fontupper=\tiny,% font size for body of text
    title=\scriptsize \textsc{#2},
    #1
}

\begin{document}

\begin{cbar}[label=lab:testing]{Test Bar (some \code{Code})}
    Here is a test bar with some \code{Code}.

    \blindtext
\end{cbar}

Hello, \code{code}. And here is a reference to \ref{lab:testing}, which has name \nameref{lab:testing}.

\end{document}

렌더링 방법은 다음과 같습니다.

여기에 이미지 설명을 입력하세요

내 문제는 다음과 같습니다

  1. 이전 환경에서 했던 것처럼 작동하도록 참조를 얻는 방법을 모르겠습니다. 보시다시피, 내 이전 환경에서는 사이드바에 대한 참조가 사이드바 제목을 인쇄하도록 레이블 텍스트를 renewcommand및 할당했습니다( 사용 ). .​phantomsectionnamerefnewtcolorbox
  2. colorlet마찬가지로 이전에는 명령 으로 출력되는 인라인 코드의 색상을 재정의하는 데 사용했습니다 code. 이것이 질문 1의 변형인 것 같지만 어디에서 해야 할지 잘 모르겠습니다.놓다지금 내가 사용하고 있는 이 논리는 newtcolorbox.

누구든지 도와줄 수 있나요?

답변1

잘못된 nameref참조가 있는 문제의 경우 \nameref제목에 설정할 수 있는 키를 사용하세요.

관련된 카운터가 없기 때문에 label=유용한 작업을 수행할 수 있는 그립이 없습니다. auto counter새 상자 정의의 초기화 옵션으로 제공합니다 .

\documentclass{scrbook}

\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage{listings}
\usepackage{blindtext}
\usepackage{hyperref}

\definecolor{inline code}{RGB}{194,61,53}
\definecolor{inline code inverted}{RGB}{193,153,151}

\newcommand*{\code}{\lstinline[basicstyle=\fontsize{9}{11}\ttfamily\color{inline code},keywordstyle=\color{inline code},stringstyle=\color{inline code},keepspaces=true]}

\newtcolorbox[auto counter]{cbar}[2][]{
    parbox=false, % normal paragraph spacing
    height from=2.5cm to 100cm,
    halign=justify,
    sharp corners,
    colframe=black,
    colback=black!15!white,
    fontupper=\tiny,% font size for body of text
    title={\thetcbcounter\ \scriptsize \textsc{#2}},
    nameref={\scriptsize \textsc{#2}},
    #1
}

\begin{document}

\begin{cbar}[label=lab:testing]{Test Bar (some \code{Code})}
    Here is a test bar with some \code{Code}.

    \blindtext
\end{cbar}

Hello, \code{code}. And here is a reference to \ref{lab:testing}, which has name \nameref{lab:testing}.

\end{document}

관련 정보