使用 tikz 水平线制作章节标题

使用 tikz 水平线制作章节标题

我正在尝试通过更改

\thickhrulefill to \myrule[line width = 2mm]{fast cap reversed}{fast cap reversed}

尽管放置

\myrule[line width = 2mm]{fast cap reversed}{fast cap reversed}

没有像以前那样出现\thickhrulefill(我希望它位于中间的章节周围有两条规则,就像未修改的章节一样)由于缺乏该领域的信息和经验,我作为初学者寻求您的帮助。这是未修改的章节标题的代码:

\documentclass[a4paper,french,12pt,openany,twoside]{report}

%%%%%Language

\usepackage[utf8]{inputenc}
\usepackage[french]{babel} 
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
\usepackage{geometry}
\geometry{margin=57pt}

%%%%%Police

\usepackage{lmodern}% police de caractère
\usepackage{textcomp}% caractères additionnels
\usepackage[normalem]{ulem}
\usepackage{soul}

%%%%%Graphic

\usepackage{graphicx}
\usepackage{xcolor}% gestion des couleurs
\usepackage{footnote}


%%%%%Titling

\usepackage{titling}% pour le titre
\usepackage{titlesec}% pour les sections
\usepackage{titletoc}% pour la table des matières
\usepackage{fancyhdr}% pour les en-têtes
\usepackage{enumitem}

%%%%%Math

\usepackage{array}
\usepackage{amsthm,latexsym,amssymb,amsmath, amsfonts}
\usepackage{mathtools}
\usepackage{pstricks}%pour psshadowbox
\usepackage{mathrsfs}
\usepackage{verbatim}
\usepackage{shapepar}
\usepackage{calc}% syntaxe naurelle pour les calculs

\usepackage{hyperref} 

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

\usepackage{tikz}
\usetikzlibrary{arrows}

\newcommand{\myrule} [3] []{
    \begin{center}
        \begin{tikzpicture}
            \draw[#2-#3, ultra thick, #1] (0,0) to (0.5\linewidth,0);
        \end{tikzpicture}
    \end{center}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Chapter Header

\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
     \vspace*{50\p@}%
     %\vspace*{10\p@}%
     {\parindent \z@ \centering \reset@font
          \thickhrulefill\quad
           \normalfont\sffamily\scshape \@chapapp{} \thechapter
           \quad  \thickhrulefill
           \par\nobreak
           \vspace*{7mm}%
           \interlinepenalty\@M
           \hrule
           \vspace*{6mm}%
           \Huge \bfseries #1\par\nobreak
           \par
           \vspace*{7mm}%
           \hrule
       \vskip 40\p@
       \vskip 100\p@
     }}
    \def\@makeschapterhead#1{%
     \vspace*{50\p@}%
     %\vspace*{10\p@}%
     {\parindent \z@ \centering \reset@font
           \thickhrulefill
           \par\nobreak
           \vspace*{10\p@}%
           \interlinepenalty\@M
           \hrule
           \vspace*{10\p@}%
           \Huge \bfseries #1\par\nobreak
           \par
           \vspace*{10\p@}%
           \hrule
       \vskip 40\p@
       %\vskip 100\p@
     }}

\begin{document}
\chapter{Introduction}
\end{document}

下面是我修改的代码:

\documentclass[a4paper,french,12pt,openany,twoside]{report}

%%%%%Language

\usepackage[utf8]{inputenc}
\usepackage[french]{babel} 
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
\usepackage{geometry}
\geometry{margin=57pt}

%%%%%Police
\usepackage{lmodern}% police de caractère
\usepackage{textcomp}% caractères additionnels
\usepackage[normalem]{ulem}
\usepackage{soul}

%%%%%Graphic

\usepackage{graphicx}
\usepackage{xcolor}% gestion des couleurs
\usepackage{footnote}


%%%%%Titling

\usepackage{titling}% pour le titre
\usepackage{titlesec}% pour les sections
\usepackage{titletoc}% pour la table des matières
\usepackage{fancyhdr}% pour les en-têtes
\usepackage{enumitem}

%%%%%Math

\usepackage{array}
\usepackage{amsthm,latexsym,amssymb,amsmath, amsfonts}
\usepackage{mathtools}
\usepackage{pstricks}%pour psshadowbox
\usepackage{mathrsfs}
\usepackage{verbatim}
\usepackage{shapepar}
\usepackage{calc}% syntaxe naurelle pour les calculs

\usepackage{hyperref} 

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

\usepackage{tikz}
\usetikzlibrary{arrows}

\newcommand{\myrule} [3] []{
    \begin{center}
        \begin{tikzpicture}
            \draw[#2-#3, ultra thick, #1] (0,0) to (0.5\linewidth,0);
        \end{tikzpicture}
    \end{center}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Chapter Header

\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
     \vspace*{50\p@}%

     %\vspace*{10\p@}%

 {\parindent \z@ \centering \reset@font
     \myrule[line width = 2mm]{fast cap reversed}{fast cap reversed}\quad
       \normalfont\sffamily\scshape \@chapapp{} \thechapter
       \quad  \myrule[line width = 2mm]{fast cap reversed}{fast cap reversed} 
       \par\nobreak
       \vspace*{7mm}%
       \interlinepenalty\@M
       \hrule
       \vspace*{6mm}%
       \Huge \bfseries #1\par\nobreak
       \par
       \vspace*{7mm}%
       \hrule
   \vskip 40\p@
   \vskip 100\p@
 }}
\def\@makeschapterhead#1{%
     \vspace*{50\p@}%
     %\vspace*{10\p@}%
     {\parindent \z@ \centering \reset@font
           \thickhrulefill
           \par\nobreak
           \vspace*{10\p@}%
           \interlinepenalty\@M
           \hrule
           \vspace*{10\p@}%
           \Huge \bfseries #1\par\nobreak
           \par
           \vspace*{10\p@}%
           \hrule
       \vskip 40\p@
       %\vskip 100\p@
     }}
\begin{document}
\chapter{Introduction}
\end{document}
\begin{document}
\chapter{Introduction}
\end{document}

答案1

几个问题:

  • 标题定义中的空行充当换行符 -> 删除

  • centertikzpicture 周围的环境将强制将其放在单独的行上 -> 删除

  • 行尾缺少的 % 将被解释为空格 -> 添加

  • .5\linewidth太长 -> 需要留出空间\quad chapter 1\quad-> 缩短

  • 如果有超过 9 个章节,最好将数字放在固定宽度的框中


\documentclass[a4paper,french,12pt,openany,twoside]{report}

%%%%%Language

\usepackage[utf8]{inputenc}
\usepackage[french]{babel} 
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
\usepackage{geometry}
\geometry{margin=57pt}

%%%%%Police
\usepackage{lmodern}% police de caractère
\usepackage{textcomp}% caractères additionnels
\usepackage[normalem]{ulem}
\usepackage{soul}

%%%%%Graphic

\usepackage{graphicx}
\usepackage{xcolor}% gestion des couleurs
\usepackage{footnote}


%%%%%Titling

\usepackage{titling}% pour le titre
\usepackage{titlesec}% pour les sections
\usepackage{titletoc}% pour la table des matières
\usepackage{fancyhdr}% pour les en-têtes
\usepackage{enumitem}

%%%%%Math

\usepackage{array}
\usepackage{amsthm,latexsym,amssymb,amsmath, amsfonts}
\usepackage{mathtools}
\usepackage{pstricks}%pour psshadowbox
\usepackage{mathrsfs}
\usepackage{verbatim}
\usepackage{shapepar}
\usepackage{calc}% syntaxe naurelle pour les calculs

\usepackage{hyperref} 

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

\usepackage{tikz}
\usetikzlibrary{arrows}

\newcommand{\myrule}[3][]{%
%    \begin{center}
        \begin{tikzpicture}%
            \draw[#2-#3, ultra thick, #1] (0,0) to (0.39\linewidth,0);
        \end{tikzpicture}%
%    \end{center}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Chapter Header

\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
     \vspace*{50\p@}%
     %\vspace*{10\p@}%
 {\parindent \z@ \centering \reset@font
     \myrule[line width = 2mm]{fast cap reversed}{fast cap reversed}\quad
       \normalfont\sffamily\scshape \@chapapp{} \thechapter
       \quad  \myrule[line width = 2mm]{fast cap reversed}{fast cap reversed} 
       \par\nobreak
       \vspace*{7mm}%
       \interlinepenalty\@M
       \hrule
       \vspace*{6mm}%
       \Huge \bfseries #1\par\nobreak
       \par
       \vspace*{7mm}%
       \hrule
   \vskip 40\p@
   \vskip 100\p@
 }}

\begin{document}
\chapter{Introduction}
\end{document}
\begin{document}
\chapter{Introduction}
\end{document}

在此处输入图片描述

相关内容