titlesec이 있는 \chapter 섹션의 너비

titlesec이 있는 \chapter 섹션의 너비

저는 titlesec섹션화 명령의 스타일을 지정하기 위해 패키지를 사용합니다. 하지만 장 너비나 오른쪽 여백에 문제가 있습니다.

장 제목

텍스트의 너비는 파란색 선까지만 도달해야 하며, "조직"과 "디스플레이"는 깨져야 합니다. 나는 \\그것이 옵션이라는 것을 알고 있지만 바닥글에는 참조된 장 이름도 있습니다.

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

따라서 를 사용하면 \\바닥글의 텍스트는 "Konzepte für die semantische"...입니다.

스타일링은 다음과 같습니다.

% > formats: \chapter
\titleformat{\chapter}[display]%
{\usekomafont{chapter}}%
{\vspace{-8em}\raggedleft{%
    {\color{ctcolorchapterline}%
        \rule[-5pt]{2pt}{5cm}}\quad%
    {\color{ctcolorchapternum}
        \fontsize{60}{60}\selectfont\thechapter}%
    }%
}%
{-2.1em}%
{\raggedright}%
[\phantomsection]

답변1

explicittitlesec 옵션을 사용하여 \parbox원하는 길이의 제목을 내부에 배치 할 수 있습니다. 이제 단면 단위의 제목을 얻으려면 #1(일반적으로 의 마지막 필수 인수에서 ) 를 사용해야 합니다 . \titleformat저는 \textwidth-3em상자의 너비로 사용했지만 필요에 따라 이 값을 변경할 수 있습니다. 아래 예에서는 질문에 제공되지 않았기 때문에 사용된 색상에 대한 몇 가지 정의를 제공했습니다.

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

\titleformat{\chapter}[display]%
  {\usekomafont{chapter}}%
  {\vspace{-8em}\raggedleft{%
    {\color{ctcolorchapterline}%
        \rule[-5pt]{2pt}{5cm}}\quad%
    {\color{ctcolorchapternum}
        \fontsize{60}{60}\selectfont\thechapter}%
    }%
  }%
  {-2.1em}%
  {\parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}%
  [\phantomsection]

\begin{document}

\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]

\end{document}

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

처럼egreg에서 지적했다그의 코멘트explicit, 보조 매크로를 사용하는 옵션 사용을 피할 수 있습니다 .

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

\newcommand\mychapformat[1]{%
  \parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
  {\usekomafont{chapter}}%
  {\vspace{-8em}\raggedleft{%
    {\color{ctcolorchapterline}%
        \rule[-5pt]{2pt}{5cm}}\quad%
    {\color{ctcolorchapternum}
        \fontsize{60}{60}\selectfont\thechapter}%
    }%
  }%
  {-2.1em}%
  {\mychapformat}%
  [\phantomsection]

\begin{document}

\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]

\end{document}

\sectfontKOMA 섹션 단위에서 기본적으로 사용되는 굵은 sansseerf 글꼴을 유지할 수 있도록 정의를 추가했습니다 .

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

\newcommand\mychapformat[1]{%
  \parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
  {\usekomafont{chapter}\sectfont}%
  {\vspace{-8em}\raggedleft{%
    {\color{ctcolorchapterline}%
        \rule[-5pt]{2pt}{5cm}}\quad%
    {\color{ctcolorchapternum}
        \fontsize{60}{60}\selectfont\thechapter}%
    }%
  }%
  {-2.1em}%
  {\mychapformat}%
  [\phantomsection]

\begin{document}

\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]

\end{document}

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

KOMA-Script 는 titlesec완전히 호환되지 않을 수 있습니다(로드할 때 KOMA 클래스에서 경고를 받게 됩니다 titlesec). 보다KOMA-Script와 titlesec 간의 비호환성

관련 정보