
私が本質的にやりたいことは、目次を除くすべての場所(主にヘッダーと本文)でセクションの番号を削除して、目次ではセクションに番号が付けられますが、左のヘッダーにはセクションの名前のみが表示され、番号は表示されないようにすることです。どうすればいいでしょうか?
これが私のコードです:
\documentclass[a4paper,english,oneside]{article}
\usepackage{fancyhdr}
\usepackage[top=1in,left=1in,right=1in,bottom=1in]{geometry}
\pagestyle{fancy}
\begin{document}
\tableofcontents
\newpage
\section{Section}
\end{document}
私の質問の仕方に関して何か問題点や提案がありましたら、教えていただけると幸いです。
答え1
プリアンブルで次のコードを使用すると、ヘッダーとメイン ドキュメントからセクション列挙の表示を削除できます。
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\AtBeginDocument{\renewcommand{\sectionmark}[1]{\markright{\MakeUppercase{#1}}}}
\makeatother
最初の変更は、ドキュメント内のセクション見出しの書式設定方法を更新します。各sec
セクション ユニットには、 によって指定された番号 (または ) と、それに続くタイトル テキストとの間隔がありc
ます。nt
これは、 を発行するセクション ユニットのすべてのデフォルトの書式設定に当てはまります。format
\@seccntformat
\@startsection
2 番目は、\sectionmark
セクション タイトルのみを設定し、\thesection
(セクション カウンター表現) への参照を完全に回避するように更新します。\AtBeginDocument
の選択によって再定義される可能性があるため、この再定義は まで延期されます。他のセクション レベル ( 、... など)\pagestyle
でも同様の操作を行う必要があります。\subsection
\documentclass{article}
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\AtBeginDocument{\renewcommand{\sectionmark}[1]{\markright{\MakeUppercase{#1}}}}
\makeatother
\pagestyle{headings}
\usepackage{lipsum}% Just for this example
\sloppy% Just for this example
\begin{document}
\tableofcontents
\section{A section}
\lipsum[1-20]
\section{Another section}
\lipsum[1-20]
\section{Yet another section}
\lipsum[1-20]
\section{A final section}
\lipsum[1-20]
\end{document}
上記は、デフォルトのドキュメント設定で機能します。セクション構成に影響を与える可能性のある他のパッケージでは、さらに調整が必要になる場合があります。