`titlesec` 내의 `tcolorbox` 패키지

`titlesec` 내의 `tcolorbox` 패키지

별로 좋은 생각은 아닐지 모르지만 다음과 같이 tcolorbox 서식을 지정하여 사용하려고 합니다.titlesec

\documentclass[10pt,twoside]{book}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}

\newcommand{\chaptauthor}{}
\newcommand{\chaptrans}{}

\tcbset{
    enhanced,
    colback=red!5!white,
    boxrule=0.1pt,
    colframe=red!75!black,
    fonttitle=\bfseries
}

\titleformat{\chapter}% command to format the chapter titles
[display]% shape/type of title
{}% formatting commands applied to both label and title
{\flushright \normalsize \color[rgb]{0.5,0,0.1} \MakeUppercase  \chaptertitlename  \hspace{1 ex}  {\fontsize{60}{60} \selectfont \color[rgb]{0.5,0,0.1} \sffamily  \thechapter} }
{0em}% separation between number and chapter title; we've already covered this with the box
{\LARGE\bfseries}% additional formatting command for title itself not applied to number
[% everything inside [...] below comes after the title
\hfill% 
\normalsize\normalfont% reset font formatting
%\vspace{0.5\baselineskip}% add a half-space of vertical space before author
%\hspace*{0.5in}% indent author name width of chapter number box 
{\begin{tcolorbox}[width=5cm]%
\begin{tabular}{rl}%
Author: & \kern-0.5em\chaptauthor \\
Translator: & \kern-0.5em\chaptrans\\
\end{tabular}%
\end{tcolorbox}%
}]% end of what comes after title


%\titlespacing*{\chapter}% spacing commands for chapter titles; the star unindents first line afterwards
%     {0em}% spacing to left of chapter title
%     {0ex}% vertical space before title 
%     {3\baselineskip}% vertical spacing after title; here set to 3 lines 


\begin{document}
\title{A title}
\maketitle

\frontmatter
\setcounter{tocdepth}{0}
\tableofcontents

\mainmatter
\renewcommand{\chaptauthor}{Author}
\renewcommand{\chaptrans}{Translator}
\chapter{One chapter}
\lipsum[5-9]
\chapter{Another chapter}
\lipsum[4-7]
\end{document}

결과는 다음과 같습니다. 여기에 이미지 설명을 입력하세요

상자를 바로 아래에 배치하려면 Chapter 1, 즉 상자가 없이 저자와 번역자가 차지한 위치를 차지하도록 코드를 어떻게 변경해야 합니까( 이 내용을 보려면 tcolorbox제거할 수 있음 )?tcolorbox

=========================편집======================== ====

명확하지 않은 경우를 대비해 제가 원하는 위치는 다음과 같습니다.

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

답변1

tcolorbox상자에는 상자 위와 아래에 수직 간격이 있습니다. 옵션을 사용하여 끌 수 있습니다 nobeforeafter.

상자 뒤의 추가 공간은 \titleformat등 으로 인해 발생합니다. \titlespacing예를 들어 장 제목 뒤의 세로 간격을 설정하는 데 사용합니다. \baselineskip -- 이것은 의 마지막 매개변수입니다 \titlespacing.

추가/변경 사항을 더 쉽게 유지 관리할 수 있도록 상자 주위에 명령을 추가로 래핑했습니다.

\documentclass[10pt,twoside]{book}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{ragged2e}
\usepackage[most]{tcolorbox}

\newcommand{\chaptauthor}{}
\newcommand{\chaptrans}{}

\tcbset{
    enhanced,
    colback=red!5!white,
    boxrule=0.1pt,
    colframe=red!75!black,
    fonttitle=\bfseries
}

\newtcolorbox{myauthorbox}[1][]{%
    enhanced,
    colback=red!5!white,
    boxrule=0.1pt,
    colframe=red!75!black,
    fonttitle=\bfseries,
    nobeforeafter,
    #1
}%

\newcommand{\authorbox}[3][width=5cm]{%
\begin{myauthorbox}[#1]
    \begin{tabular}{rl}
      Author:     & \kern-0.5em #2 \\
      Translator: & \kern-0.5em #3 \\
    \end{tabular}
  \end{myauthorbox}%
}


\titleformat{\chapter}% command to format the chapter titles
[display]% shape/type of title
{}% formatting commands applied to both label and title
{\flushright \normalsize \color[rgb]{0.5,0,0.1} \MakeUppercase  \chaptertitlename  \hspace{1 ex}  {\fontsize{60}{60} \selectfont \color[rgb]{0.5,0,0.1} \sffamily  \thechapter} }
{0em}% separation between number and chapter title; we've already covered this with the box
{\LARGE\bfseries}% additional formatting command for title itself not applied to number
[% everything inside [...] below comes after the title
\hfill%  For right alignment of the box
\normalsize\normalfont% reset font formatting
%\vspace{0.5\baselineskip}% add a half-space of vertical space before author
%\hspace*{0.5in}% indent author name width of chapter number box 
{%
  \authorbox[width=5cm]{\chaptauthor}{\chaptrans}%
}]% end of what comes after title


\titlespacing*{\chapter}% spacing commands for chapter titles; the star unindents first line afterwards
     {0em}% spacing to left of chapter title
     {0ex}% vertical space before title 
     {1\baselineskip}% vertical spacing after title; here set to 3 lines 


\begin{document}
\title{A title}
\maketitle

\frontmatter
\setcounter{tocdepth}{0}
\tableofcontents

\mainmatter
\renewcommand{\chaptauthor}{Author}
\renewcommand{\chaptrans}{Translator}
\chapter{One chapter}
\lipsum[5-9]
\chapter{Another chapter}
\lipsum[4-7]
\end{document}

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

관련 정보