3

I'm trying to reproduce the example below on the right margin, but have come into serious errors.

\documentclass[a4paper,DIV=classic]{scrbook}
   \usepackage{scrpage2}
   \usepackage{lipsum}
   \usepackage{graphicx}

\titleformat{\chapter}[hang]
{\normalfont\Large\raggedright}
{%
\llap{ \resizebox{!}{1.2cm}{\thechapter} \smash{\rule{.4pt}{10cm}} } }
{10pt}{\Huge}

\begin{document}
\chapter{A Chapter}

\end{document}

I tried adapting the code below, which works fine:

\titleformat{\chapter}[display]
 {\normalfont\Large\raggedleft}
 {\MakeUppercase{\chaptertitlename}%
 \rlap{ \resizebox{!}{1.2cm}{\thechapter} \smash{\rule{.4pt}{10cm}} } }
 {10pt}{\Huge}

But then I cannot get rid of \MakeUppercase{\chaptertitlename} without messing things up.

What am I doing wrong here?

The result I expect is like:

enter image description here

  • 1
    Your first code doesn't produce any errors on my system (TeX Live2013) after loading titlesec in the preamble: \usepackage{titlesec}- What kind of errors do you get? – Gonzalo Medina Aug 3 '13 at 2:29
  • Both codes work fine, but what I want to do is mirror the first one (make it flush right). But when I try to do that with the [hang] option and as I said, taking out \MakeUppercase{\chaptertitlename} (of the second code), it doesn't work. – Joseph Aug 3 '13 at 10:31
  • Ah, now I see. Please see my answer below. – Gonzalo Medina Aug 3 '13 at 16:48
4

Here's a possibility (adjust the lengths according to your needs):

\documentclass[a4paper,DIV=classic]{scrbook}
\usepackage{scrpage2}
\usepackage{graphicx}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\titleformat{\chapter}[hang]
  {\normalfont\raggedleft}{}
  {10pt}
  {\Huge#1\rlap{%
    \hspace{1em}\smash{\rule[-2ex]{.4pt}{10cm}}~%
    \resizebox{!}{1.2cm}{\thechapter}}%
  }
\titleformat{name=\chapter,numberless}[hang]
  {\normalfont\raggedleft}{}
  {10pt}
  {\Huge#1\rlap{%
    \hspace{1em}\smash{\rule[-2ex]{.4pt}{10cm}}}%
  }

\begin{document}

\chapter{A numbered chapter}
\lipsum[4]
\chapter*{An unnumbered chapter}
\lipsum[4]

\end{document}

An image of a numbered chapter:

enter image description here

An image of an unnumbered chapter:

enter image description here

  • Nice, that's exactly what I had in mind. – Joseph Aug 3 '13 at 23:44
2

Less code duplication than in Gonzalo's answer:

\documentclass[a4paper,DIV=classic]{scrbook}
\usepackage{scrpage2}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{lipsum}

\newif\ifnumberedchapter

\titleformat{\chapter}[display]
  {\filleft}
  {\global\numberedchaptertrue}% this is executed only for numbered chapters
  {10pt}
  {\Huge\dochaptertitle}

\newcommand{\dochaptertitle}[1]{%
  #1% The title
  \makebox[0pt][l]{%
    \hspace{1em}% one quad of space
    \smash{% this doesn't take vertical space
      \vrule height 10cm depth 2ex % the rule
      \ifnumberedchapter % the following will appear only for numbered chapters
        \enspace % some space
        \resizebox{!}{1.2cm}{\thechapter}%
      \fi
    }%
  }%
  \global\numberedchapterfalse
}

\begin{document}

\chapter{A numbered chapter}
\lipsum[4]
\chapter*{An unnumbered chapter}
\lipsum[4]

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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