Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use the titlesec package for styling the sectioning commands. But I have a problem with the chapter width or right margin:

Chapter Title

The width of the text should only reach to the blue line, "Organisation" and "Display" should break. I know \\ is an option, but in the footer is also the chapter name referred:

enter image description here

So, if I use \\, the text in the footer is: "Konzepte für die semantische"...

The styling ist:

% > 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]
share|improve this question
1  
Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  lockstep Mar 16 at 15:25
    
Note that, even if you introduce a \\ in your title, it will be converted to space in your header/footer with the newlinetospace option. –  Bernard Mar 16 at 16:17

1 Answer 1

up vote 6 down vote accepted

You can use the explicit option for titlesec to place the title inside a \parbox of the desired length; notice that now you need to use #1 (typically in the last mandatory argument for \titleformat) to get the title for the sectional unit. I used \textwidth-3em as the width for the box, but you can change this value according to your needs. In the example below I provided some definitions for the colors used since they were not given in the question:

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

enter image description here

As egreg has pointed out in his comment, one can avoid using the explicit option using an auxiliary macro:

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

I added \sectfont to your definitions so you can keep the boldfaced sansseerf font used by default in KOMA sectional units:

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

enter image description here

Notice that titlesec and KOMA-Script might not be fully compatible (you'll get a warning from the KOMA classes when loading titlesec); see Incompatibilities between KOMA-Script and titlesec

share|improve this answer
    
explicit is not necessary; the last token in the relevant argument of \titleformat can be a macro taking an argument, so you can just say \mychapformat defining \newcommand{\mychapformat}[1]{\parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedr‌​ight#1}}. –  egreg Mar 16 at 16:49
    
@egreg Ah, that's nice. I've added your suggetion to my answer. Thanks you. –  Gonzalo Medina Mar 16 at 16:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.