セクション、サブセクション、サブサブセクションの番号付けの周囲にフレーム ボックスを追加する方法

セクション、サブセクション、サブサブセクションの番号付けの周囲にフレーム ボックスを追加する方法

以下のように、各セクション、サブセクション、サブサブセクションの番号にフレームボックスを追加したいと思います。 ここに画像の説明を入力してください

しかし、次のコードは 'subsubsection' では機能しないようです。

\documentclass[12pt,a4paper]{report}
\usepackage[french]{babel} 
\usepackage[a4paper,margin=0.5in]{geometry}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[Glenn]{fncychap}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\thesection{\fbox{\Roman{section}}}
\renewcommand\thesubsection{\fbox{\arabic{subsection}}}
\renewcommand\thesubsubsection{\fbox{\begin{english}\textit{\alph{subsubsection}}\end{english}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
    \chapter{}
    \section{Section}
    \subsection{Subsection 1}
    \subsection{Subsection 2}
    \subsubsection{\fbox{a} subSubsection}
    \subsubsection{\fbox{b} subSubsection}
    \section{section}
    \subsection{subsection}
    \subsubsection{\fbox{a} subsubsection}
\end{document}

答え1

順不同でいくつかのコメントを述べます。

  • ドキュメントreportクラスは を実行します\setcounter{secnumdepth}{2}。つまり、サブセクションレベルのヘッダーに自動的に番号を付けません。

    \setcounter{secnumdepth}{3} 
    

    LaTeX にサブサブセクション レベルのヘッダーにも番号を付ける様に指示します。

  • 、、および\fboxの (再) 定義に命令を組み込むのは、本当に悪い考えです。なぜでしょうか? フレームボックスが、セクション、サブセクション、サブサブセクションへのすべての相互参照に表示されるため、これはほぼ確実に望ましくない結果になります。\thesection\thesubsection\thesubsubsection

  • 代わりに、低レベルの\@seccntformatマクロ (アプリケーションについては以下のコードを参照) を使用して、ヘッダー内にのみフレームボックスを描画するように LaTeX に指示します。

  • サブセクション レベルのヘッダーにアルファベット文字を使用しているため、文字にアセンダもディセンダもない場合 (例: および )、アセンダのみがある場合 (例: a) z、ディセンダのみがあるb場合 (「y」または「j」)、またはその両方がある場合 (italic-shape ) に関係なく、まったく同じフレームボックスが使用されるように注意する必要があります。の定義にディレクティブfを挿入すると、サイズの不規則性が修正される可能性があります。\vphantom{f}\subsubsection@cntformat

ここに画像の説明を入力してください

\documentclass[12pt,a4paper]{report}
\usepackage[french]{babel} 
\usepackage[margin=0.5in]{geometry}

\usepackage[Glenn]{fncychap}
\setcounter{secnumdepth}{3} % <-- new

\renewcommand\thesection{\Roman{section}}
\renewcommand\thesubsection{\arabic{subsection}}
\renewcommand\thesubsubsection{\alph{subsubsection}}

% Use method proposed in "The LaTeX Companion", 2nd ed., to determine
% how the section-like counters are displayed in sectioning headers
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
    {\csname the#1\endcsname\space}%    default
    {\csname #1@cntformat\endcsname}}%  enable individual control
\newcommand\section@cntformat{%       section
   \fbox{\thesection}\quad}       
\newcommand\subsection@cntformat{%    subsection
   \fbox{\thesubsection}\quad} 
\newcommand\subsubsection@cntformat{% subsubsection
    \fbox{\itshape\thesubsubsection\vphantom{f}}\quad}
\makeatother

\begin{document}
\arabic{secnumdepth}
    \chapter{}
    \section{Section}
    \subsection{Subsection 1}
    \subsection{Subsection 2}
    \subsubsection{subSubsection}
    \subsubsection{subSubsection}
    \section{Section}
    \subsection{Subsection}
    \subsubsection{subSubsection} 
\end{document}

関連情報