理解章节样式代码

理解章节样式代码

我想为我的报告找一种奇特的风格,我在网上找到了一个这里

我将其用于另一份报告,但代码并不完全相同。我想尝试一下,更改一些东西,然后开始意识到我上次(太久以前了)对它做了太多改动,以至于我不能再使用它了。

现在,在新电脑上,在新项目上,我想开始一种新的风格,并且想尝试一下这种风格的元素。

唯一的问题是,首先,我可以像示例 (n°39) 那样让它工作:我不明白黑匣子。其次,我不太理解代码。

这就是为什么我寻求您的智慧,翻译这段代码,以便我可以使用它。

这是我的代码:

\documentclass[12pt]{report}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[top=2cm, bottom=2cm, left=1.5cm, right=1.5cm]{geometry}
\usepackage{fancyhdr} % En-têtes et pieds de page
\usepackage{psboxit,pstricks}

\makeatletter
\renewcommand\part{%
  \thispagestyle{fancy}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
  \null\vfil
  \secdef\@part\@spart}

\renewcommand\chapter{
  \thispagestyle{fancy}%
  \global\@topnum\z@
  \@afterindentfalse
  \secdef\@chapter\@schapter}
\makeatother 

%%%%%%%%%%%%%%%%%%%%%%%%%%%% THE PART I DON'T UNDERSTAND

\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
  \reset@font
  \parindent \z@ 
  \vspace*{10\p@}%
  \hbox{%
    \vbox{%
      \hsize=2cm%
      \begin{tabular}{c}
        \scshape \strut \@chapapp{} \\
        \psboxit{box 0 0 0 black fill}{%
          \vrule depth 8em width 0pt%
          \vrule height 0pt depth 0pt width 10pt%
          {\white \LARGE \bfseries 
            \strut \vrule height 1em depth 0pt width 0pt
            \thechapter}%
          \vrule height 0pt depth 0pt width 10pt%
          }
      \end{tabular}%
      }%
    \vbox{%
      \advance\hsize by -2cm
      \hrule height 0.4pt depth 0pt width \hsize
      \par
      \vskip 6pt%
      \hspace{20pt}%
      \parbox{260pt}{%
        \Huge \bfseries #1}%
      }%
    }%
  \vskip 100\p@
}
\def\@makeschapterhead#1{%
  \reset@font
  \parindent \z@ 
  \vspace*{10\p@}%
  \hbox{%
    \vbox{%
      \hsize=2cm%
      \begin{tabular}{c}
        \scshape \strut \phantom{\@chapapp{}} \\
        \psboxit{box 0 0 0 black fill}{%
          \vrule depth 8em width 0pt%
          \vrule height 0pt depth 0pt width 10pt%
          {\white \LARGE \bfseries 
            \strut \vrule height 1em depth 0pt width 0pt
            \vphantom{\thechapter}}%
          \vrule height 0pt depth 0pt width 10pt%
          }
      \end{tabular}%
      }%
    \vbox{%
      \advance\hsize by -2cm
      \hrule height 0.4pt depth 0pt width \hsize
      \par
      \vskip 6pt%
      \hspace{20pt}%
      \parbox{260pt}{%
        \Huge \bfseries #1}%
      }%
    }%
  \vskip 100\p@
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    

\begin{document}
\pagenumbering{gobble}
\chapter*{Test}
\newpage
\chapter{Nice Chapter}
\newpage
\pagenumbering{arabic}
\pagestyle{fancy}
\lhead{Nice header}
\rfoot{Page\ \thepage}
\cfoot{}
\chapter{Test2}
\newpage
\chapter*{Nice Chapter2}

\end{document}

初始输出:

在此处输入图片描述

编辑 :

正如 Christian Hupfer 所说,我的代码无法正常工作,可能是因为 psboxit 和 psboxtricks 软件包太旧了

这是我以前使用过的代码,但我在没有真正理解它的情况下对其进行了修改:

\documentclass[12pt]{report}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[top=2cm, bottom=2cm, left=1.5cm, right=1.5cm]{geometry}
\usepackage{fancyhdr} % En-têtes et pieds de page
\usepackage[usenames,dvipsnames]{xcolor}

\makeatletter
\renewcommand\part{%
  \thispagestyle{fancy}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
  \null\vfil
  \secdef\@part\@spart}

\renewcommand\chapter{
  \thispagestyle{fancy}%
  \global\@topnum\z@
  \@afterindentfalse
  \secdef\@chapter\@schapter}
\makeatother 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter
    \def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
    \def\@makechapterhead#1{%
      \reset@font
      \vspace*{-40\p@}%
      \hbox{%
        \vbox{%
          \hsize=1cm%
          \begin{tabular}{c}
           \hspace*{-100mm} \scshape \strut \phantom{\@chapapp{}} \\
           \hspace*{-9mm} \colorbox{Black}{\vbox{\hbox{\vbox to 1mm{}}\hbox{\color{white} \LARGE \bfseries \hspace{1mm}\thechapter\hspace{1mm}}\hbox{\vbox to 1cm{}}}}%
          \end{tabular}%
          }%
        \vbox{%
          \advance\hsize by -1cm
          \hrule height 0.4pt depth 0pt width \hsize
          \par
          \vskip 6pt%
          \hspace{1pt}%
          \parbox{400pt}{%
            \Huge \bfseries #1}%
          }%
        }%
      \vskip 15\p@
    }
    \def\@makeschapterhead#1{%
      \reset@font
      \vspace*{-40\p@}
      \hbox{%
        \vbox{%
          \hsize=1cm%
          \begin{tabular}{c}
            \hspace*{-100mm} \scshape \strut \phantom{\@chapapp{}} \\
            \hspace*{-9mm} \colorbox{Black}{\vbox{\hbox{\vbox to 1mm{}}\hbox{\color{white} \LARGE \bfseries \hspace{1mm}\phantom{\thechapter}\hspace{1mm}}\hbox{\vbox to 1cm{}}}}%
          \end{tabular}%
          }%
        \vbox{%
          \advance\hsize by -1cm
          \hrule height 0.4pt depth 0pt width \hsize
          \par
          \vskip 6pt%
          \hspace{1pt}%
          \parbox{400pt}{%
            \Huge \bfseries #1}%
          }%
        }%
      \vskip 15\p@
    }
    \makeatother


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    

\begin{document}
\pagenumbering{gobble}
\chapter*{Test}
\newpage
\chapter{Nice Chapter}
\newpage
\pagenumbering{arabic}
\pagestyle{fancy}
\lhead{Nice header}
\rfoot{Page\ \thepage}
\cfoot{}
\chapter{Test2}
\newpage
\chapter*{Nice Chapter2}

\end{document}

相关内容