\ref コマンドにドットを追加せずに、見出しと目次の \section 番号の後にドットを追加する方法

\ref コマンドにドットを追加せずに、見出しと目次の \section 番号の後にドットを追加する方法

\section番号付け後にドット付きで印刷される( \subsection\subsubsection... ) タイトルが必要です。

例:

  1. 私のタイトル

この目的のために私は以下を使用します:

\renewcommand\thesection{\normalfont \arabic{section}.}

\renewcommand\thesubsection{\thesection\arabic{subsection}.}

\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.}

\renewcommand\theparagraph{\thesubsubsection\arabic{paragraph}.}

しかし、この方法では\ref{}コマンドに余分なドットも追加されます。したがって、コード「セクション . を参照\ref{section:label}」は文字列「セクション 3 を参照..」を生成します。

見出しと目次にのみドットを追加し、参照には追加しない方法はありますか?

答え1

の使い方は次のとおりです。ラベルの後のドットはではなく でtitlesec/titletoc追加されます。目次のドットについては、titletoc ではオプションになっています。また、相互参照をより簡単に記述するために を使用します。\titleformat\thesectioncleveref

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{heuristica}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage[dotinlabels]{titletoc}
\titleformat{\section}[hang]{\bfseries\large}{Section \thesection.}{0.4em}{}
\titlespacing*{\section}{0pt}{2\baselineskip}{2\baselineskip}
\dottedcontents{section}[3.8em]{}{2.3em}{1pc}
\usepackage{cleveref}

\begin{document}

\tableofcontents

\section{Preliminaries}\label{sec:prelim}
\lipsum[1]

\section{Another section}
See \Cref{sec:prelim}.

\end{document} 

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

答え2

\usepackage{titlesec}
\titlelabel{\thetitle.\quad}

詳細はパッケージtitlesecのドキュメント3ページ目。

関連情報