带有可延伸垂直标尺的章节标题

带有可延伸垂直标尺的章节标题

我尝试在右边距重现下面的示例,但是遇到了严重的错误。

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

我尝试修改下面的代码,效果很好:

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

\MakeUppercase{\chaptertitlename}但如果不把事情弄乱的话我就无法摆脱它。

我在这里做错了什么?

我期望的结果是这样的:

在此处输入图片描述

答案1

这是一种可能性(根据您的需要调整长度):

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

编号章节的图像:

在此处输入图片描述

未编号章节的图片:

在此处输入图片描述

答案2

代码重复比 Gonzalo 的答案要少:

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

相关内容