Titlesec wird im Inhaltsverzeichnis angezeigt

Titlesec wird im Inhaltsverzeichnis angezeigt

Ich titleseczeige den Autor und Übersetzer jedes Kapitels meines Buches wie folgt an:

\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage{titlesec}
\newcommand{\chapterauthor}{}
\newcommand{\chaptertranslator}{}

\titleformat{\chapter}% command to format the chapter titles
[hang]% shape/type of title
{\LARGE\bfseries}% formatting commands applied to both label and title
{\makebox[0.5in][l]{\thechapter}}% chapter number; here set inside an invisible box with a constant width
{0em}% separation between number and chapter title; we've already covered this with the box
{}% additional formatting command for title itself not applied to number
[% everything inside [...] below comes after the title
\hfill% 
\normalsize\normalfont% reset font formatting
\vspace{0.5\baselineskip}% add a half-space of vertical space before author
\hspace*{0.5in}% indent author name width of chapter number box 
\begin{tabular}{rl} %
    Author: & \kern-0.5em\chapterauthor \\
    Translator: & \kern-0.5em\chaptertranslator\\
\end{tabular}%
]% end of what comes after title
\titlespacing*{\chapter}% spacing commands for chapter titles; the star unindents first line afterwards
{0em}% spacing to left of chapter title
{0ex}% vertical space before title 
{3\baselineskip}% vertical spacing after title; here set to 3 lines 
\begin{document}
\tableofcontents
\renewcommand{\chapterauthor}{Alphonse Lamartine}
\renewcommand{\chaptertranslator}{Ine}

\chapter{New chapter}
Here it is. 
\renewcommand{\chapterauthor}{Heinrich Böll}
\renewcommand{\chaptertranslator}{Llöb Chirnieh}
\chapter{Another chapter}
Here again.


\end{document}

In jedem Kapitel definiere ich Autor und Übersetzer neu und zwar folgendermaßen:

\renewcommand{\chapterauthor}{Heinrich Böll}
\renewcommand{\chaptertranslator}{Llöb Chirnieh}

Das Problem besteht darin, dass das Inhaltsverzeichnis hierdurch als Kapitel behandelt wird. Da im Inhaltsverzeichnis weder Autoren noch Übersetzer vorhanden sind, werden direkt über dem Inhaltsverzeichnis leere Felder für Autor und Übersetzer angezeigt, und zwar wie folgt:

    Author:
Translator:

Wie kann ich das verhindern?

===Bearbeiten: um das zu zeigen, reicht der Kommentar von nicht aus \boolfalse{withauthor}==Bernard

\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{etoolbox}
\newbool{withauthor}

\newcommand{\chapterauthor}{}
\newcommand{\chaptertranslator}{}

\titleformat{\chapter}% command to format the chapter titles
[hang]% shape/type of title
{\LARGE\bfseries}% formatting commands applied to both label and title
{\makebox[0.5in][l]{\thechapter}}% chapter number; here set inside an invisible box with a constant width
{0em}% separation between number and chapter title; we've already covered this with the box
{}% additional formatting command for title itself not applied to number
[% everything inside [...] below comes after the title
\ifbool{withauthor}{\hfill% 
\normalsize\normalfont% reset font formatting
\vspace{0.5\baselineskip}% add a half-space of vertical space before author
\hspace*{0.5in}% indent author name width of chapter number box 
\begin{tabular}{rl} %
    Author: & \kern-0.5em\chapterauthor \\
    Translator: & \kern-0.5em\chaptertranslator\\
\end{tabular}}{}%
\boolfalse{withauthor}
]% end of what comes after title
\titlespacing*{\chapter}% spacing commands for chapter titles; the star unindents first line afterwards
{0em}% spacing to left of chapter title
{0ex}% vertical space before title 
{3\baselineskip}% vertical spacing after title; here set to 3 lines 
\begin{document}
\tableofcontents
\renewcommand{\chapterauthor}{Alphonse Lamartine}
\renewcommand{\chaptertranslator}{Ine}
\booltrue{withauthor}
\chapter{New chapter}
Here it is.
%\renewcommand{\chapterauthor}{Heinrich Böll}
%\renewcommand{\chaptertranslator}{Llöb Chirnieh}
%\boolfalse{withauthor}
\chapter{Another chapter}
Here again.


\end{document}

Antwort1

Ich nehme an, dass alle nicht nummerierten Kapitel weder einen Autor noch einen Übersetzer haben, alle nummerierten Kapitel jedoch schon.

\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage[showframe, nomarginpar]{geometry}
\usepackage{lipsum}
\usepackage{array}
\usepackage{titlesec}
\usepackage{etoolbox}
\newbool{withauthor}

\newcommand{\chapterauthor}{}
\newcommand{\chaptertranslator}{}

\titleformat{\chapter}% command to format the chapter titles
[hang]% shape/type of title
{\LARGE\bfseries}% formatting commands applied to both label and title
{\makebox[0.5in][l]{\thechapter}}% chapter number; here set inside an invisible box with a constant width
{0em}% separation between number and chapter title; we've already covered this with the box
{}% additional formatting command for title itself not applied to number
[% everything inside [...] below comes after the title
\ifbool{withauthor}{\hfill%
\normalsize\normalfont% reset font formatting
\vspace{0.5\baselineskip}% add a half-space of vertical space before author
\hspace*{0.5in}% indent author name width of chapter number box
\begin{tabular}{ll} %
    Author: & \kern-0.5em\chapterauthor \\
    Translator: & \kern-0.5em\chaptertranslator\\
\end{tabular}}{}%
\global\boolfalse{withauthor}
]% end of what comes after title
\titlespacing*{\chapter}% spacing commands for chapter titles; the star unindents first line afterwards
{0em}% spacing to left of chapter title
{0ex}% vertical space before title
{3\baselineskip}% vertical spacing after title; here set to 3 lines
\begin{document}
\tableofcontents
\renewcommand{\chapterauthor}{Alphonse de Lamartine}
\renewcommand{\chaptertranslator}{Ine}
\booltrue{withauthor}
\chapter{New chapter}
Here it is.
%\renewcommand{\chapterauthor}{Heinrich Böll}
%\renewcommand{\chaptertranslator}{Llöb Chirnieh}
%\boolfalse{withauthor}
\chapter{Another chapter}
Here again.


\end{document} 

Bildbeschreibung hier eingeben Bildbeschreibung hier eingeben

verwandte Informationen