How to make 'appendix' appear in toc in Latex? - latex

How to make word 'appendix' appear in the table of contents? Right now toc looks like this:
1 ......
2 ......
.
.
A .....
B .....
I would like it to be:
1 ......
2 ......
.
.
Appendix A .....
Appendix B .....
My latex source file structure is like this:
\begin{document}
\tableofcontents
\include{...}
\include{...}
\appendix
\include{...}
\include{...}
\end{document}

There's a couple of ways to solve this problem; unfortunately, I've only got a hack for you at this stage. One problem is that if we redefine the section number "A" to include the word "Appendix", it messes up the formatting of the table of contents. So instead, I've just defined a new sectioning command that prints the section without a number and inserts "Appendix X" manually.
Kind of ugly, but at least it works without having to change any markup :)
\documentclass{article}
\makeatletter
\newcommand\appendix#section[1]{%
\refstepcounter{section}%
\orig#section*{Appendix \#Alph\c#section: #1}%
\addcontentsline{toc}{section}{Appendix \#Alph\c#section: #1}%
}
\let\orig#section\section
\g#addto#macro\appendix{\let\section\appendix#section}
\makeatother
\begin{document}
\tableofcontents
\section{goo}
\label{a}
This is sec~\ref{a}
\section{har}
\label{b}
This is sec~\ref{b}
\appendix
\section{ji}
\label{c}
This is app~\ref{c}
\subsection{me}
does this look right?
\end{document}

For my thesis, I did the following:
\appendix
\addcontentsline{toc}{section}{Appendix~\ref{app:scripts}: Training Scripts}
\section*{Sample Training Scripts}
\label{app:scripts}
Blah blah appendix content blah blah blah.
Explanation: I manually added a line to the TOC so I would have "Appendix X:..." show up in my TOC. Then I excluded the actual section command from the TOC by using an asterisk.

This is probably most easily achieved by using the appendix
package, or the memoir class.
If you don't want to use a prepackaged solution, you'll have to
hack the sectioning commands. When I needed to do this for my
dissertation, I cloned the report class, and edited until I made
the margins lady happy. What you're looking for is the
definition of the \addcontentsline macro.

The appendix package is really good and simple solution. My answer can be helpful for who wants to change chapters numbering style, for example, with using cyrillic alphabet or roman digits. The appendices numbering style is hardcoded in the \#resets#pp command (I looked in sources here http://hal.in2p3.fr/docs/00/31/90/21/TEX/appendix.sty). I solved it by simple redefining this command to my own. Just add this code into your preamble:
\makeatletter
\renewcommand{\#resets#pp}{\par
\#ppsavesec
\stepcounter{#pps}
\setcounter{section}{0}
\if#chapter#pp
\setcounter{chapter}{0}
\renewcommand\#chapapp{\appendixname}
\gdef\thechapter{\Asbuk{chapter}} % changed
\else
\setcounter{subsection}{0}
\gdef\thechapter{\Asbuk{section}} % changed
\fi
\if#pphyper
\if#chapter#pp
\renewcommand{\theHchapter}{\theH#pps.\Asbuk{chapter}} % changed
\else
\renewcommand{\theHsection}{\theH#pps.\Asbuk{section}} % changed
\fi
\def\Hy#chapapp{\appendixname}%
\fi
\restoreapp
}
\makeatother
As a result,
Appendix A
Appendix B
Appendix C
...
will change to
Appendix A
Appendix Б
Appendix В
... etc
I'm not a latex expert, and I can't guarantee this code won't break something else.

Based on #Will Robertson's answer, the code below defines the same thing but for chapter and also fixes the fact that chapter* does not add to the header when using the fancyhdr package.
With this in the preable all issues are resolved.
\makeatletter
\newcommand\appendix#chapter[1]{%
\refstepcounter{chapter}%
\def\app#ct{Appendix \#Alph\c#chapter: #1}
\orig#chapter*{\app#ct}%
\markboth{\MakeUppercase{\app#ct}}{\MakeUppercase{\app#ct}}
\addcontentsline{toc}{chapter}{\app#ct}%
}
\let\orig#chapter\chapter
\g#addto#macro\appendix{\let\chapter\appendix#chapter}
\makeatother

Related

How to reset chapter and section counter with \part*

Sorry for bad english
I have a problem with my Latex code (I'm not very good in coding). I want an output like this:
Part I
Chapter I
Chapter II
Part II
Chapter I
Chapter II
I also wanted to create a box around my title of the parts , this doesn't work like I wanted, so I used \part* and \addcontentsline{toc}{part}{PART I} (to write the line in the table of content).So the code is:
\fbox{\begin{minipage}{\linewidth}
\part*{\begin{center}
PART I
\end{center}}
\end{minipage}}
\addcontentsline{toc}{part}{PART I}
\vspace{0.7cm}
I saw this methode to reset the counter of the chapters:
\makeatletter
\#addtoreset{chapter}{part}
\makeatother
but this doesn't work, I think it's due to use of \part*.
Has anyone an idea? THNANKS!
Hope the example bellow can help:)
\documentclass[a4paper,11pt,]{report}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\newpage
\fbox{\begin{minipage}{\linewidth}
\part*{\begin{center}
INTRODUCTION
\end{center}}
\end{minipage}}
\addcontentsline{toc}{part}{INTRODUCTION}
\vspace{0.7cm}
\chapter{Hello}
\section{my}
\newpage
\fbox{\begin{minipage}{\linewidth}
\part*{\begin{center}
CONCLUSION
\end{center}}
\end{minipage}}
\addcontentsline{toc}{part}{CONCLUSION}
\vspace{0.7cm}
\chapter{name}
\section{is}
\end{document}
As you already know the solution for \part, how about simply using this and make it look like \part*? This has the advantage that you could add the boxes around the part titles automatically.
\documentclass[a4paper,11pt,]{report}
\usepackage[newparttoc]{titlesec}
\titleformat{\part}[frame]
{\normalfont}
{}
{8pt}
{\Large\bfseries\filcenter}
\usepackage{titletoc}
\titlecontents{part}[0em]
{\vspace{2em}\large\bfseries\sffamily\relax}
{\contentslabel[\relax]{0em}}{}{\hfill\contentspage}
\usepackage{hyperref}
\makeatletter
\#addtoreset{chapter}{part}
\makeatother
\begin{document}
\tableofcontents
\part{INTRODUCTION}
\chapter{Hello}
\section{my}
\part{CONCLUSION}
\chapter{name}
\section{is}
\end{document}

part lettering Latex

I am trying to get my document parts to show up as:
A. Narrative % \part{Narrative}
Intro %\section{Intro}
main text...
B. Appendix % \part{Appendix}
Derivations % \section{Derivations}
appendix text...
I have seen others use:
\renewcommand{\thepart}{\Alph{part}}
However this is not working for me for some reason. My parts are showing up as:
Part A
Narrative
Intro
main text...
Part B
Appendix
Derivations
appendix text...
Any ideas anyone?
The minimal example below updates \part to set its numbering differently. More specifically, it removes the \partname - Part - prefix and keeps the title on the same line. Fonts are also updated to set the part using \LARGE\bfseries in both \part and \part*. All of the above updates are done using etoolbox's \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>} macro that performs a <search>-and-<replace> within <cmd>.
\documentclass{article}
\usepackage{lipsum,etoolbox}
\renewcommand{\thepart}{\Alph{part}}
\makeatletter
% Change part display; also uniform size of \LARGE\bfseries
\patchcmd{\#part}% <cmd>
{\Large\bfseries \partname\nobreakspace\thepart \par\nobreak}% <search>
{\LARGE\bfseries \thepart.\quad}% <replace>
{}{}% <success><failure>
\patchcmd{\#part}{\huge}{\LARGE}{}{}
\patchcmd{\#spart}{\huge}{\LARGE}{}{}
\renewcommand{\#seccntformat}[1]{\csname the#1\endcsname.\quad}
% \#addtoreset{section}{part} % Reset section counter with every part
\makeatother
\begin{document}
\part{Narrative}
\section{Intro}
\lipsum[1]
\part{Appendix}
\section{Derivations}
\lipsum[2]
\end{document}
If you wish to have the \section numbers reset with every new \part, uncomment the line referencing that in the preamble.
Your idea is right, but you also redefine the titleformat.
From the following link:
\usepackage{titlesec}
\renewcommand{\thepart}{\Alph{part}}
\makeatletter
\titleformat{\part}[display]
{\Huge\scshape\filright}
{\thepart~\partname}
{20pt}
{\thispagestyle{plain}}
\makeatother

Temporarily changing document class in LaTeX/resetting pdfLaTeX

How can I temporarily cause pdfLaTeX to forget everything that I've told it and start with a new document class?
I've modified the example environment from the lshort document:
\newwrite\examplesx#out
\newenvironment{examplesx}{%
\begingroup% Lets Keep the Changes Local
\#bsphack
\immediate\openout \examplesx#out \jobname.exa
\let\do\#makeother\dospecials\catcode`\^^M\active
\def\verbatim#processline{%
\immediate\write\examplesx#out{\the\verbatim#line}}%
\verbatim#start
}{%
\immediate\closeout\examplesx#out\#esphack\endgroup%
\noindent\makebox[\textwidth][l]{%
\begin{minipage}[c]{0.45\textwidth}%
\small\verbatiminput{\jobname.exa}
\end{minipage}%
\hspace*{0.1\textwidth}%
\framebox{%
\begin{minipage}{0.45\textwidth}%
\small\input{\jobname.exa}%
\end{minipage}
}%
}\vspace*{\parskip}%
}
and it mostly works, but I want to be able to do something like
\begin{examplesx}
\section{Section}
\end{examplesx}
and have it show up as a section in a box. I also would like it to typeset lists using the standard article style, even if I use it in beamer
I think that the easiest way of doing this is to compile some small document and then include the resultant pdf as an image into the larger document. Much simpler even if not exactly what you want. I have done this to show, in a Beamer presentation, what LaTeX articles look like.
Of course if its a REALLY simple document (e.g., a simple block of text) that you want to have inside beamer, I could recommend that you mimic the document with a TikZ "picture" that contains some text.
Maybe another approach: instead of trying to typeset things in beamer as if they would be done in article, simply typeset them with the article document class and include the result the in the beamer document.
With tcolorbox this can be done automatically:
% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
\documentclass{beamer}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{frame}[fragile]
\begin{tcblisting}{
comment only,
pdf comment,
compilable listing,
run pdflatex,
}
\documentclass{article}
\begin{document}
\section{Section Title}
test
\end{document}
\end{tcblisting}
\end{frame}
\end{document}

Adding bibliography to appendices in latex

I am writing my thesis and I am using the chapterbib option. While it makes beautiful bibliographies for my chapters, I can't get it to do the same thing for my appendices.
The preamble:
\documentclass[pdftex, 11pt, onecolumn, openany]{report}
\usepackage{amsmath}
\usepackage[pdftex]{graphicx}
\usepackage{appendix}
\usepackage[sectionbib]{chapterbib}
\usepackage{chapterbib}
\begin{document}
...
\include{background}
\include{ATRPcomp}
\include{CCTcomp}
\appendix
\include{AppCCT}
\end{document}
In each of my chapter sections and appendix I have:
\chapter{Compartmentalization in Catalytic Chain Transfer}
...
\bibliography{references}
Does the chapterbib also work for appendices or is there another option that could help?
I assume the package to work also within the appendix. I fact, when you issue the command \appendix the sectioning commands' behavior is the same, except for the numbering (and perhaps the heading).
In the main matter, the chapter command
\chapter{CCTcomp}
gives you
7 CCtcomp
(7 is an example). The commands sequence
\appendix
\chapter{AppCCT}
gives you
A AppCCT
The bibliography shoud work properly.

No page number for divider pages in LaTeX

I have a report in LaTeX, and i have used the following commands to create my Appendix, however, my lecturer states that any divider pages should be unnumbered.
\documentclass{report}
\usepackage{appendix}
\begin{document}
\include{chap1}
\include{appendix}
\end{document}
Then in appendix.tex
\appendix
\pagestyle{empty}
\appendixpage
\noappendicestocpagenum
\addappheadtotoc
This creates the Appendices divider page, but still puts a page number on it in the footer. There is no page number in the TOC, as expected.
How can I remove it from the footer?
I looked at the appendix.sty source, and I see the problem: line 74, in the definition of \#chap#pppage, issues a \thispagestyle{plain} command, thus overriding your \pagestyle{empty} for this page. The inelegant but direct way to fix this is to redefine the command without this line - issue the following code after importing the package.
Revised, tested version
\documentclass{report}
\usepackage{appendix}
%==== The action ================
\makeatletter
\def\#chap#pppage{%
\clear#ppage
\if#twocolumn\onecolumn\#tempswatrue\else\#tempswafalse\fi
\null\vfil
\markboth{}{}%
{ \centering \interlinepenalty \#M
\normalfont \Huge \bfseries \appendixpagename\par}%
\if#dotoc#pp\addappheadtotoc\fi
\vfil\newpage
\if#twoside
\if#openright \null \thispagestyle{empty}\newpage\fi
\fi
\if#tempswa \twocolumn\fi
}
\makeatother
%==== Back to the document ========
\begin{document}
\tableofcontents
\chapter{Blah}
Rhubarb, rhubarb, rhubarb.
\appendix
\pagestyle{empty}
\appendixpage
\noappendicestocpagenum
\addappheadtotoc
\chapter{Boff}
Cabbages, cabbages, cabbages.
\end{document}
The TeX FAQ might come in handy here:
I asked for “empty”, but the page is numbered
If you use \pagestyle{empty} and you
find some pages are numbered anyway,
you are probably encountering one of
the style decisions built into the
standard LaTeX classes: that certain
special pages should always appear
with \pagestyle{plain}, with a page
number at the centre of the page foot.
The special pages in question are
those (in article class) containing a
\maketitle, or (in book and report
classes) \chapter or \part commands.
The simple solution is to reissue the
page style after the command, with
effect for a single page, as, for
example (in article):
\maketitle
\thispagestyle{empty}
So give adding \thispagestyle{empty} after your \appendix a try.
try changing \pagestyle{empty} to \thispagestyle{empty} and put it after \addappheadtotoc.
Try instead:
\pagenumbering{gobble}
\begin{appendices} \newpage
\clearpage
\pagenumbering{arabic}
\addtocounter{page}{100}
\tableofcontents
\newpage
*Special thanks to https://tex.stackexchange.com/questions/6639/removing-page-numbers-but-not-headers!

Resources