質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
LaTeX

LaTeXは、レスリー・ランポートが開発したテキストベースの文書整形システムです。 電子製版ソフトウェアである「TeX」にマクロパッケージを組み込む形で構成されており、 通常のTeXより扱いやすくなっているのが特徴です。

TeX

フリーの組版システムで、字や図版などの要素を紙面に配置するという作業をコンピュータで行います

Q&A

解決済

2回答

5807閲覧

LaTeXで目次の1ページ目に\thispagestyle{fancy}が適用されない

Julius_Novachro

総合スコア7

LaTeX

LaTeXは、レスリー・ランポートが開発したテキストベースの文書整形システムです。 電子製版ソフトウェアである「TeX」にマクロパッケージを組み込む形で構成されており、 通常のTeXより扱いやすくなっているのが特徴です。

TeX

フリーの組版システムで、字や図版などの要素を紙面に配置するという作業をコンピュータで行います

1グッド

0クリップ

投稿2019/12/18 04:57

編集2019/12/18 05:04

LaTeXでページ番号をヘッダに書きたいのですが、pagestyle{fancy}やthispagestyle{fancy}を使っても目次の1ページ目に適用されません。
(2ページ目では適用されます。目次だけページ番号をromanにしています。)
ちなみにchapter{}のページはthispagestyle{fancy}で適用されました。
どうしたらいいでしょうか?

\documentclass[11pt,a4paper,titlepage,a4j]{jreport}
\usepackage{fancyhdr}

%いったん設定
\pagestyle{fancy}
\lhead{\rightmark}
\rhead{\thepage}
\cfoot{}
\renewcommand{\headrulewidth}{1pt}

\title{略}

\begin{document}
\pagenumbering{roman}
\maketitle
\tableofcontents

%目次用に再設定
\thispagestyle{fancy}
\lhead{目次}
\rhead{\thepage}
\cfoot{}
\renewcommand{\headrulewidth}{1pt}
%↑↑↑が目次1ページ目に適用されない

\chapter{チャプター}
%設定戻す
\thispagestyle{fancy}
\lhead{\rightmark}
\rhead{\thepage}
\cfoot{}
\renewcommand{\headrulewidth}{1pt}

\pagenumbering{arabic}
%以降のページは正しく表示される。

\end{document}

toyjack👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

overleaf環境と手元環境で実験してみましたが、目次ページもちゃんとpagestyleが適用されます。
もっとも\tableofcontents時点ではpageには値が入っていないので添付画像のように"i"で表示されてしまいますが。

イメージ説明

"i"を出したくないのであれば、\thead{目次}の前に\pagenumbering{empty}をいれればいいでしょう。

(追記)
現象を確認しました。\thispagestle{fancy}をprotectすればいいかと。
\begin{document}の前に\AtBeginDocument{\addtocontents{toc}{\protect\thispagestyle{fancy}}} を追加。

投稿2019/12/20 04:39

編集2019/12/20 05:57
rogueref

総合スコア727

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Julius_Novachro

2019/12/20 05:46 編集

回答ありがとうございます。 改めて試してみたところ、目次が1ページだけの時は大丈夫なのですが、 複数ページになると1ページ目のみpagestyleが適用されないようです。 また、lhead{目次}は目次の最後のページにしか適用されないようです。 以下、雑ですが修正サンプルを貼っておきます。 (ついでに質問・コメント欄にコードを貼る方法も教えてもらえると助かります、、、) \documentclass[11pt,a4paper,titlepage,a4j]{jreport} \usepackage{fancyhdr} %いったん設定 \pagestyle{fancy} \lhead{\rightmark} \rhead{\thepage} \cfoot{} \renewcommand{\headrulewidth}{1pt} \title{略} \begin{document} \pagenumbering{roman} \maketitle \tableofcontents %目次用に再設定 \thispagestyle{fancy} \lhead{目次} \rhead{\thepage} \cfoot{} \renewcommand{\headrulewidth}{1pt} %↑↑↑が目次1ページ目に適用されない \chapter{チャプター} %設定戻す \thispagestyle{fancy} \lhead{\rightmark} \rhead{\thepage} \cfoot{} \renewcommand{\headrulewidth}{1pt} \pagenumbering{arabic} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} \section{セクション} %以降のページは正しく表示される。 \end{document}
rogueref

2019/12/20 06:11

回答編集しときました。 "i"は目次のページ番号でしたね。失礼しました。
Julius_Novachro

2019/12/20 06:13

\AtBeginDocument{\addtocontents{toc}{\protect\thispagestyle{fancy}}} でうまくいきました。 ありがとうございます。
guest

0

回答編集しときました。
"i"は目次のページ番号でしたね。失礼しました。

投稿2019/12/20 06:11

rogueref

総合スコア727

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問