6

I'm writing my thesis and have defined my own appendix command (I am really doing this in a hurry, so there may be ways to do this better). What bothers me right now, is that I must include a list of appendices twice in the document, once before the real thesis start where the ToC and LoF and LoT are and then additionally at the end before the appendices.

But it doesn't work. Where am I missing something?

NOTE: I've redefined the section command to get the formatting requested, that is also the reason to use the section command in \priloga macro, so as to get same formatting. Additionally, I had to renew the sectioning counter to be alphabetic.

MWE:

\documentclass[a4paper,onecolumn,11pt,twoside]{article}
\usepackage{lipsum}

\usepackage{tocloft}
\newcommand{\listprilogename}{\normalsize SEZNAM PRILOG}
\newlistof{priloge}{pr}{\listprilogename}

\newcommand{\prilogalist}[1]{\refstepcounter{priloge}\addcontentsline{pr}{priloge}
{\protect\numberline{Priloga\;\Alph{priloge}}\hspace{1.6cm}#1}\par}

\newcommand{\priloga}[1]{\prilogalist{#1}\section{#1}}

\usepackage{titlesec}
\titleformat{\section}{\normalfont\normalsize\bfseries}{\thesection}{1em}{}
\titlespacing*{\section}{0pt}{*0.2}{*0.05}

\begin{document}

\clearpage
\section*{List of Appendices}
\listofpriloge 

\section{Introduction}
\lipsum

\clearpage
\section*{Appendices}
\listofpriloge %this command doesn't print anything :S

\setcounter{section}{0}
\renewcommand\thesection{\Alph{section}}

\clearpage
\priloga{Additional content}
\lipsum[1-5]

\end{document}
5

The problem is that \@starttoc (used internally to read all the list of... files inputs the existing file to show the list but the opens it for writing to start collecting the new list for this run, That erases the file so you can not use it twice.

This just locally redefines the command just to input and not to open the file for writing. This is safe as long as the command is issued again before your appendices so that the file is open at that point.

\documentclass[a4paper,onecolumn,11pt,twoside]{article}
\usepackage{lipsum}

\usepackage{tocloft}
\newcommand{\listprilogename}{\normalsize SEZNAM PRILOG}
\newlistof{priloge}{pr}{\listprilogename}

\newcommand{\prilogalist}[1]{\refstepcounter{priloge}\addcontentsline{pr}{priloge}
{\protect\numberline{Priloga\ \Alph{priloge}}\hspace{1.6cm}#1}\par}

\newcommand{\priloga}[1]{\prilogalist{#1}\section{#1}}

\usepackage{titlesec}
\titleformat{\section}{\normalfont\normalsize\bfseries}{\thesection}{1em}{}
\titlespacing*{\section}{0pt}{*0.2}{*0.05}

\begin{document}

\clearpage
\section*{List of Appendices}

{\expandafter\def\csname @starttoc\endcsname#1{\InputIfFileExists{\jobname.#1}{}{}}%
\listofpriloge 
}



\section{Introduction}
\lipsum

\clearpage
\section*{Appendices}
\listofpriloge %this command doesn't print anything :S

\setcounter{section}{0}
\renewcommand\thesection{\Alph{section}}

\clearpage
\priloga{Additional content}
\lipsum[1-5]

\end{document}
1
  • Thank you for the explanation. It is the case, yes, the command is issued again before the appendices start. It works :) – Pjanc Matuzl Apr 13 '13 at 0:52
2

David has already explained why your initial approach didn't work. Here's another possible solution, defining another command \listofprilogei (with external associated file with .pri extension). I also corrected the problem with the \hspace commands in your original code that were causing overfull hboxes. The new command \listofprilogei can be safely used at any point in the document:

\documentclass[a4paper,onecolumn,11pt,twoside]{article}
\usepackage{lipsum}
\usepackage{tocloft}
\usepackage{titlesec}

\titleformat{\section}
  {\normalfont\normalsize\bfseries}{\thesection}{1em}{}
\titlespacing*{\section}
  {0pt}{*0.2}{*0.05}
\newcommand{\listprilogename}{\normalsize SEZNAM PRILOG}
\newlistof{priloge}{pr}{\listprilogename}

\newlistentry{prilogi}{pr}{1}
\newlistentry{prilogii}{pri}{1}
\makeatletter
\renewcommand*\l@priloge{\@dottedtocline{1}{0em}{5.3em}}
\renewcommand*\l@prilogii{\@dottedtocline{1}{0em}{5.3em}}
\makeatother

\newcommand{\prilogalist}[1]{%
  \refstepcounter{priloge}%
  \addcontentsline{pr}{priloge}{\protect\numberline{Priloga\ \Alph{priloge}}#1}\par
\addcontentsline{pri}{priloge}
{\protect\numberline{Priloga\ \Alph{priloge}}#1}\par}

\newcommand{\priloga}[1]{\prilogalist{#1}\section{#1}}

\makeatletter
\renewcommand\contentsname{\listprilogename}
\newcommand\listofprilogei{%
    \section*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \vskip10pt\@starttoc{pri}%
    }
\makeatother

\begin{document}

\clearpage
\section*{List of Appendices}
\listofpriloge 

\section{Introduction}
\lipsum

\clearpage
\section*{Appendices}
\listofprilogei

\setcounter{section}{0}
\renewcommand\thesection{\Alph{section}}

\clearpage
\priloga{Additional content}
\lipsum[1-5]
\clearpage
\priloga{Some additional content}
\lipsum[1-5]

\end{document}

By the way, this line of your code

\newcommand{\prilogalist}[1]{\refstepcounter{priloge}\addcontentsline{pr}{priloge}
{\protect\numberline{Priloga\;\Alph{priloge}}\hspace{1.6cm}#1}\par}

produces errors since you are using the math-mode spacing command \;. In my code I used normal interword space instead.

3
  • Thank you for the spacing improvement (\ ). I have additional question, regarding your solution - can I use only \renewcommand*\l@priloge{\@dottedtocline{1}{0em}{5.3em}} for the spacing, or must I include any other line (of course, the \make are included)? – Pjanc Matuzl Apr 13 '13 at 1:01
  • @PjancMatuzl you are using David's approach which I haven't tested; I think you should ask him. – Gonzalo Medina Apr 13 '13 at 1:04
  • I'm sorry, I though this could work independetly, so as the \renewcommand is not really in connection :S Thank you anyway, I'd also accepted your answer if it was possible :) – Pjanc Matuzl Apr 13 '13 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.