章节样式来自 zoonek.free.fr/LaTeX/LaTeX_samples_chapter/0.html

章节样式来自 zoonek.free.fr/LaTeX/LaTeX_samples_chapter/0.html

我尝试获取页面 zoonek.free.fr/LaTeX/LaTeX_samples_chapter/0.html 上 n.39 中的章节样式。

它应该是这样的

在此处输入图片描述

这是代码:

\documentclass{sample}
\usepackage{psboxit,pstcol}
\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 setrgbcolor 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 setrgbcolor 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}
\chapter{Introduction}
\end{document}

不幸的是,当我尝试使用它时,没有出现带有章节号的黑框。数字是白色的,背景是白色的。

有什么帮助吗?

谢谢

答案1

您制造负载彩色\colorbox{black}{<text>}并使用\color{white},最终\textcolor{white}{<text>}

在此处输入图片描述

\documentclass{book}
\usepackage{xcolor}
\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{} \\
        \colorbox{black}{%                 % Change to colorbox from xcolor
          \vrule depth 8em width 0pt%
          \vrule height 0pt depth 0pt width 10pt%
          {\color{white}  \LARGE \bfseries  % % Change to color{white}
            \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{}} \\
        \colorbox{black}{%            % Change to colorbox from xcolor
          \vrule depth 8em width 0pt%
          \vrule height 0pt depth 0pt width 10pt%
          {\color{white} \LARGE \bfseries  % Change to color{white}
            \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}
\chapter{Introduction}
\end{document}

答案2

我会用titlesec

\documentclass{book}
\usepackage{titlesec,xcolor,array}

\titleformat{name=\chapter}[block]
 {}
 {}
 {0pt}
 {\zoonekchapterhead{\chaptername}{\thechapter}}
\titleformat{name=\chapter,numberless}[block]
 {}
 {}
 {0pt}
 {\zoonekchapterhead{}{}}

\newcommand{\zoonekchapterhead}[3]{%
  \noindent
  \begin{tabular}[t]{@{}wc{1cm}@{}}
  \makebox[0pt]{\normalfont\scshape#1}\\
  \setlength{\fboxsep}{0pt}%
  \colorbox{black}{%
    \parbox[t][4cm]{1cm}{\LARGE\bfseries\centering\textcolor{white}{\strut#2}}%
  }
  \end{tabular}%
  \hspace*{1pc}%
  \begin{minipage}[t]{\dimexpr\textwidth-1pc-1cm}
  \vspace*{1cm}
  \hrule
  \vspace{6pt}
  \raggedright\Huge\bfseries\leftskip=1em #3
  \end{minipage}%
}

\begin{document}

\chapter*{Unnumbered}

\chapter{Introduction}

\chapter{Long title that needs to be split across lines}

\end{document}

在此处输入图片描述

相关内容