Titlesec と Titletoc: 危険な関係

Titlesec と Titletoc: 危険な関係

次のコードを検討してください。

\documentclass[a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}

\usepackage{titlesec}
\renewcommand{\thechapter}{\scshape\roman{chapter}}
\titleformat{\chapter}[display]
  {\normalfont\fontsize{11pt}{12pt}\selectfont}{\thechapter}{0pt}{}
%%{\normalfont\fontsize{11pt}{12pt}\selectfont}{\chaptertitlename\space \thechapter}{11pt}{}
\renewcommand\thesection{\arabic{section}}
\titleformat{\section}
  {\normalfont\fontsize{11pt}{12pt}\selectfont}{\thesection}{1em}{}
\titleformat{\subsection}
  {\normalfont\fontsize{11pt}{12pt}\selectfont\itshape}{}{1em}{}
\titlespacing{\chapter}{0pt}{0pt}{3cm}

\usepackage{titletoc}
\titlecontents{chapter}
[1.5em] % ie, 1.5em (chapter) + 2.3em
{}
{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{}
%{\titlerule*[1pc]{.}\contentspage}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% codice Pignalberi
\contentsmargin{0pt}
\titlecontents{chapter}[4pc]
{\contentsmargin{0pt}\makebox[0pt][r]{\thecontentspage\quad\makebox[30pt][l]%
{\textsc{\romannumeral\thecontentslabel\ quad}}}}
{}
{}
{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\tableofcontents

\chapter{Chapter 1 title}
Some text some text some text some text some text

\section{Section a title}
Some text some text some text some text some text

\section{Section b title}
Some text some text some text some text some text

\chapter{Chapter 2 title}
Some text some text some text some text some text

\section{Section c title}
Some text some text some text some text some text

\section{Section d title}
Some text some text some text some text some text

\chapter{Chapter 3 title}
Some text some text some text some text some text

\section{Section e title}
Some text some text some text some text some text

\section{Section f title}
Some text some text some text some text some text
\end{document}

必要に応じて変更してみましたが、索引の形式は問題ありません。次のステップとして、左側の目次にページ番号を入れたいと思います。しかし、私が見つけたコード (私の MWE「codice Pignalberi」内) は、前のコードと干渉します。titlesec/titletoc マニュアルに従っても、このコードの両側をどこでどのように調整すればよいのか理解できないので、ご協力をお願いします。

===================================================

アップデート

Gonzalo のコードのおかげで、すべてがうまく動作するようになりました。2 つの側面を改善しました (章のタイトルの前にスペースを追加し、章番号を削除してセクション番号のみを残すことで、読者にとってより便利になりました)。コードは次のとおりです。

<pre>\usepackage{titlesec}
\usepackage[rightlabels,dotinlabels]{titletoc}

\renewcommand{\thechapter}{\roman{chapter}}
\renewcommand\thesection{\arabic{section}}

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11}{12}\selectfont}
  {\scshape\thechapter}
  {0pt}
  {}
\titleformat{\section}
  {\normalfont\fontsize{11}{12}\selectfont}
  {\thesection}
  {1em}
  {}
\titleformat{\subsection}
  {\normalfont\fontsize{11}{12}\selectfont\itshape}
  {}
  {1em}
  {}

\titlespacing{\chapter}
  {0pt}{0pt}{3cm}

\titlecontents{chapter}[-3pc]
  {\addvspace{0.8pc}}
  {\makebox[3pc][r]{\hfill}%
    \textsc{\thecontentslabel}\quad%
  }
  {}
  {}
  {}
\titlecontents{section}[-3pc]
  {\makebox[4pc][r]{\thecontentspage\hfill}%
    \textsc{\thecontentslabel}\quad%
  }
  {}
  {}
  {}</pre>

最後に、すべての数字 (ページとセクション) を左揃えではなく右揃えにしたいのですが、実際はプロポーショナル フォントを使用するとセクションのタイトルがうまく揃いません。オプションがtitletoc機能rightlabels,dotinlabelsしていないように思われます。どうもありがとうございます。問題は次の場所で確認できます。 位置合わせ不良

==========================================================

アップデート2

etoc を使用してコードを .tex ファイルにコピーしようとしましたが、結果は非常に奇妙です。 etoc 奇妙な効果

==========================================================

アップデート3

上記の問題はパッケージが原因ですbidi。そのファイルではヘブライ語とフェニキア語も使用しています。「通常の」ファイルではetocコードは正常に動作します。最後の質問は 1 つだけです。ドキュメントを非常によく読まなければなりませんがetoc、かなり大きいです。しかし、ページ番号を正しく揃えるにはどうしたらよいのでしょうか? ありがとうございます。

答え1

これは、ゴンサロ・メディナの回答使用するetocと相互作用してどのように動作するかはわかりませんbidi

etoc例が揃えば物事は簡単になります。

ここでは、レイアウト、特に垂直方向の配置を理解するために、いくつかのグラフィック補助を追加しました。セクションのページ番号は左余白にあります。章とセクションの番号は右揃えで、1em 実際の見出しとは水平方向に離れています。章の名前は1cm左余白から から始まり、セクションの名前は から始まります。長い名前は、右のテキスト余白から2cmの距離で折り返されます。1cm

アップデート(最後に追加) は、番号なしの章の扱いと、選択されたいくつかの章にもページ番号を表示することに関するコメントへの回答です。(両方とも、番号なしの追加の章 1 つに示されています)。

etoc TOC

\documentclass[a4paper]{report}
\usepackage[margin=2cm,paperwidth=14cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\usepackage{etoc}
\usepackage{color}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand\thesection{\arabic{section}}

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11}{12}\selectfont}
  {\scshape\thechapter}
  {0pt}
  {}
\titleformat{\section}
  {\normalfont\fontsize{11}{12}\selectfont}
  {\thesection}
  {1em}
  {}
\titleformat{\subsection}
  {\normalfont\fontsize{11}{12}\selectfont\itshape}
  {}
  {1em}
  {}

\titlespacing{\chapter}
  {0pt}{0pt}{3cm}

\etocsetstyle{chapter}
% FOR VISUALIZING LAYOUT:
  % {\fboxsep-\fboxrule\noindent\normalsize
  %        \fbox{\makebox[1cm][r]{\strut
  %                          \smash{\color{blue}\vrule depth12cm}\hspace{1em}%
  %                          \smash{\color{green}\vrule depth12cm}}}%
  %        \fbox{\makebox[1cm][r]{\color{blue}\strut
  %                          \smash{\color{blue}\vrule depth12cm}\hspace{1em}%
  %                          \smash{\color{green}\vrule depth12cm}}}%
  %        \fbox{\makebox[1cm]{\strut}}(debugging layout)\hfill
  %        \fbox{\makebox[1cm][l]{\strut\smash{\color{red}\vrule
  %              depth12cm}}}%
  %   \hrule}  
  {}% <- uncomment the above and suppress this line if debugging layout
  {\pagebreak[3]\vskip25pt\leftskip 1cm\relax
                          \rightskip 1cm\relax
                          \parindent 0pt\relax
   }
  {\Large\leavevmode
   \llap{\makebox[1cm][r]{\normalsize\etocnumber.\hspace{1em}}}%
   \etocname\par\nopagebreak\medskip }
  {\bigskip}


\etocsetstyle{section}
  {}  
  {\leftskip 2cm\relax}
  {\normalsize\leavevmode
   \llap{\makebox[1cm][r]{\mdseries\etocpage}%
                    \hspace{1cm}%
                    \makebox[1cm][r]{\etocnumber.\hspace{1em}}}%
   \etocname\par\pagebreak[1]\smallskip }
  {}

\begin{document}
\tableofcontents

\chapter{Vita e Opere}
\setcounter{page}{98}% just for the example
Some text some text some text some text some text

\section{Infanzia, studi a Lipsia e soggiorno a Parigi}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text

\section{La concezione delle idee}
Some text some text some text some text some text

\chapter{Seggni (``caratteri'') e idee}
Some text some text some text some text some text

\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text

\section{La concezione delle idee}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\clearpage

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\end{document}

etoc TOC 2

\documentclass[a4paper]{report}
\usepackage[margin=2cm,paperwidth=14cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\usepackage{etoc}
\usepackage{color}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand\thesection{\arabic{section}}

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11}{12}\selectfont}
  {\scshape\thechapter}
  {0pt}
  {}
\titleformat{\section}
  {\normalfont\fontsize{11}{12}\selectfont}
  {\thesection}
  {1em}
  {}
\titleformat{\subsection}
  {\normalfont\fontsize{11}{12}\selectfont\itshape}
  {}
  {1em}
  {}

\titlespacing{\chapter}
  {0pt}{0pt}{3cm}


%% ETOC SPECIFICATIONS

% conditional to display chapter page number
% a priori set to false
\newif\ifDisplayInTocChapterPageNumber

\etocsetstyle{chapter}
  {}
  {\pagebreak[3]\vskip25pt\leftskip 1cm\relax
                          \rightskip 1cm\relax
                          \parindent 0pt\relax
   }
  {\Large\leavevmode
   \llap{\ifDisplayInTocChapterPageNumber
             \makebox[1cm][r]{\mdseries\normalsize\etocpage}%
         \fi
         \makebox[1cm][r]{\normalsize\etocifnumbered{\etocnumber.}{}%
                          \hspace{1em}}}%
   \etocname\par\nopagebreak\medskip }
  {\bigskip}


\etocsetstyle{section}
  {}  
  {\leftskip 2cm\relax}
  {\normalsize\leavevmode
   \llap{\makebox[1cm][r]{\mdseries\etocpage}%
                    \hspace{1cm}%
                    \makebox[1cm][r]{\etocnumber.\hspace{1em}}}%
   \etocname\par\pagebreak[1]%\smallskip 
  }
  {}

\begin{document}
\tableofcontents

\chapter{Vita e Opere}
\setcounter{page}{98}% just for the example
Some text some text some text some text some text

\section{Infanzia, studi a Lipsia e soggiorno a Parigi}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text

\section{La concezione delle idee}
Some text some text some text some text some text

\chapter{Seggni (``caratteri'') e idee}
Some text some text some text some text some text

\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text

\section{La concezione delle idee}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\clearpage

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\addtocontents{toc}{\protect\DisplayInTocChapterPageNumbertrue}

\chapter*{Un capitolo non numerato e col numero di pagina nel margine dell'indice}
\addcontentsline{toc}{chapter}{Un capitolo non numerato e col numero di
  pagina nel margine dell'indice}
\setcounter{section}{0}

\section{Ultimi anni}
Some text some text some text some text some text


\end{document}

答え2

以下に 2 つのオプションを示します。最初のオプションは を使用しetoc、2 番目のオプションは を使用titletocします。最終的な望ましい書式設定がまだ完全にはわかりません。質問では、章のページ番号を左側に配置するように求められていますが、コメントには、章のエントリに左側にページ番号がない画像が提供されています。とにかく、以下のサンプル コードを使用すると、必要な形式を簡単にカスタマイズできます。

強力なetocパッケージ:

\documentclass[a4paper]{report}
\usepackage[margin=2cm,paperwidth=14cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\usepackage{etoc}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand\thesection{\arabic{section}}

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11}{12}\selectfont}
  {\scshape\thechapter}
  {0pt}
  {}
\titleformat{\section}
  {\normalfont\fontsize{11}{12}\selectfont}
  {\thesection}
  {1em}
  {}
\titleformat{\subsection}
  {\normalfont\fontsize{11}{12}\selectfont\itshape}
  {}
  {1em}
  {}

\titlespacing{\chapter}
  {0pt}{0pt}{3cm}

\etocsetstyle{chapter}
  {}  
  {\vskip25pt\leavevmode\leftskip 0cm\relax}
  {\parbox[t]{.5cm}{\etocnumber.\hfill}%
  \parbox[t]{\dimexpr\linewidth-1cm-15pt\relax}{\Large\etocname}\hfill\par\medskip
  }
  {}
\etocsetstyle{section}
  {}  
  {\leavevmode\leftskip 0cm\relax}
  {\llap{\parbox[t]{1.5cm}{\mdseries\hfill\etocpage}\hspace{.5cm}}%
    \normalsize\parbox[t]{1cm}{\quad\etocnumber.\hfill}%
  \parbox[t]{\dimexpr\linewidth-1cm-15pt\relax}{\etocname\par}\hfill\par
  }
  {}

\begin{document}
\tableofcontents

\chapter{Vita e Opere}
\setcounter{page}{98}% just for the example
Some text some text some text some text some text

\section{Infanzia, studi a Lipsia e soggiorno a Parigi}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text

\section{La concezione delle idee}
Some text some text some text some text some text

\chapter{Seggni (``caratteri'') e idee}
Some text some text some text some text some text

\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text

\section{La concezione delle idee}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\clearpage

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text

\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text

\end{document}

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

次を使用した別の可能性を示しますtitletoc:

\documentclass[a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\usepackage{titletoc}

\renewcommand{\thechapter}{\roman{chapter}}
\renewcommand\thesection{\arabic{section}}

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11}{12}\selectfont}
  {\scshape\thechapter}
  {0pt}
  {}
\titleformat{\section}
  {\normalfont\fontsize{11}{12}\selectfont}
  {\thesection}
  {1em}
  {}
\titleformat{\subsection}
  {\normalfont\fontsize{11}{12}\selectfont\itshape}
  {}
  {1em}
  {}

\titlespacing{\chapter}
  {0pt}{0pt}{3cm}

\titlecontents{chapter}[-4pc]
  {\makebox[2pc][l]{\hfill\thecontentspage}\hspace{2pc}%
    \textsc{\thecontentslabel}\quad%
  }
  {}
  {}
  {}
\titlecontents{section}[-4pc]
  {\makebox[2pc][l]{\hfill\thecontentspage}\hspace{3pc}%
    \textsc{\thecontentslabel}\quad%
  }
  {}
  {}
  {}

\begin{document}
\tableofcontents

\chapter{Chapter 1 title}
\setcounter{page}{98}% just for the example
Some text some text some text some text some text

\section{Section a title}
Some text some text some text some text some text

\section{Section b title}
Some text some text some text some text some text

\chapter{Chapter 2 title}
Some text some text some text some text some text

\section{Section c title}
Some text some text some text some text some text

\section{Section d title}
Some text some text some text some text some text

\chapter{Chapter 3 title}
Some text some text some text some text some text

\section{Section e title}
Some text some text some text some text some text

\section{Section f title}
Some text some text some text some text some text

\end{document}

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

答え3

レイアウトを正しく理解していれば、以下に基づいた基本的な解決策がありますtitletoc:

\newcommand\boxedpage{\makebox[3pc][r]{\thecontentspage}}
\newcommand\boxedtocnum{\makebox[3pc][r]{\thecontentslabel.\quad}}

\titlecontents{chapter}[0pc]
  {\addvspace{0.8pc}}
  {\contentslabel[\boxedpage\boxedtocnum]{6pc}}
  {}{}{}
\titlecontents{section}[3pc]
  {}
  {\contentslabel[\boxedpage\hspace*{3pc}\boxedtocnum]{9pc}}
  {}{}{}

ただディメンションで遊んでみてください。

編集。完全な例を以下に示しますtitletoc。 で番号付けを制御できsecnumdepth、 で目次に含まれるエントリを制御できることを覚えておいてください。で目次エントリの形式を変更できるtocdepthことも覚えておいてください。titletoc真ん中何らかの理由で必要になった場合、ドキュメントの(後続のセクションで)ディメンションを変更できます。前と同じように、ディメンションを操作してください。

\documentclass{book}

\renewcommand{\thesection}{\arabic{section}}

\usepackage{titletoc}

\newcommand\boxedpage{\makebox[3pc][r]{\thecontentspage}}
\newcommand\boxedtocnum{\makebox[3pc][r]{\thecontentslabel.\quad}}

\titlecontents{chapter}[3pc]
  {\addvspace{0.8pc}}
  {\contentslabel[\boxedpage\boxedtocnum]{6pc}}
  {\contentslabel[\boxedpage\hspace*{3pc}]{6pc}}
  {}{}
\titlecontents{section}[6pc]
  {}
  {\contentslabel[\boxedpage\hspace*{3pc}\boxedtocnum]{9pc}}
  {\contentslabel[\boxedpage\hspace*{6pc}]{9pc}}
  {}{}

\newcommand*\asection{
\section{A Honovver, text text al servizio del ducchi Johann
  Friedrich ed Ernst August.}
Some text some text some text some text some text\par}

\begin{document}
\tableofcontents

\chapter{Vita e Opere}
\setcounter{page}{98}% just for the example

\asection\asection

\chapter{Seggni (``caratteri'') e idee}

\asection\asection\asection\asection\asection
\asection\asection\asection\asection\asection

% From now on, unnumbered headers, but still in the toc
% down to section
\setcounter{secnumdepth}{-1}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}\ignorespaces}

\chapter{Seggni (``caratteri'') e idee}

\asection\asection

\end{document}

関連情報