Paket `tcolorbox` innerhalb von `titlesec`

Paket `tcolorbox` innerhalb von `titlesec`

Es ist vielleicht keine besonders gute Idee, aber ich versuche, tcolorbox die Formatierung titlesec wie folgt durchzuführen:

\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}

Das Ergebnis ist: Bildbeschreibung hier eingeben

Wie muss ich den Code ändern, um das Feld direkt darunter zu platzieren Chapter 1, das heißt, dass es die Position einnimmt, die Autor und Übersetzer innehatten, ohne tcolorbox(Sie können es entfernen, tcolorbox um es anzuzeigen)?

===========================Bearbeiten===========================

Falls es nicht klar ist, hätte ich es gerne hier:

Bildbeschreibung hier eingeben

Antwort1

tcolorboxBoxen haben vertikale Abstände oberhalb und unterhalb der Box. Dies kann mit der Option ausgeschaltet werden nobeforeafter.

Der zusätzliche Abstand nach dem Feld ist auf \titleformatusw. zurückzuführen. Verwenden Sie , \titlespacingum den vertikalen Abstand nach dem Kapiteltitel beispielsweise auf einzustellen \baselineskip – dies ist der letzte Parameter von \titlespacing.

Um die Verwaltung von Ergänzungen/Änderungen zu vereinfachen, habe ich zusätzlich einen Befehl um die Box gewickelt.

\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}

Bildbeschreibung hier eingeben

verwandte Informationen