Graphics, Figures & Tables ⇒ How To Breakup List Of Figures For Bookmarks In PDF File
-
- Posts: 51
- Joined: Wed Aug 06, 2014 6:59 pm
How To Breakup List Of Figures For Bookmarks In PDF File
In general \listoffigures gives a listing of all the figures in the document. The "pdflatex" command produces a PDF file with a list of bookmarks on the left side of the document. The bookmarks come from the table of contents.
The section, subsection, and subsubsections appear in the bookmarks, but they're displayed in a tree. I.E.: You won't see these subsections unless you open the tree via clicking on the "+" sign next to the chapter name.
In the bookmarks, what I would like to be able to have is (instead of just creating a single link to a list of all the figures in the document) divide the output from the \listoffigures command in a tree-like layout just like sections, subsections are displayable via a tree.
FYI: I add the list of figures to the table of contents using the following code:
...
\phantomsection\label{listoffig}
\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
...
So, I get one link in the bookmarks of the PDF file.
Thanks,
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
-
- Posts: 51
- Joined: Wed Aug 06, 2014 6:59 pm
Re: How To Breakup List Of Figures For Bookmarks In PDF File
\usepackage{tocloft}
...
\newcommand{\listlemmaname}{List of Lemmas}
\newlistof{lemma}{lem}{\listlemmaname}
\newcommand{\lemma}[1]{%
\refstepcounter{lemma}
\par\noindent\textbf{Lemma \thelemma. #1}
\addcontentsline{lem}{lemma}
{\protect\numberline{\thechapter.\thelemma}#1}\par
}
...
\listoflemma
...
\lemma{My first lemma}
\label{lem:lemma1}
Reference:
http://texblog.org/2011/09/09/10-ways-t ... tocloflot/
-
- Posts: 51
- Joined: Wed Aug 06, 2014 6:59 pm
Re: How To Breakup List Of Figures For Bookmarks In PDF File
Thanks,
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
How To Breakup List Of Figures For Bookmarks In PDF File
Please provide a minimal working example this time. Follow the link and read how to do it.
-
- Posts: 51
- Joined: Wed Aug 06, 2014 6:59 pm
How To Breakup List Of Figures For Bookmarks In PDF File
- Add sections to the list of figures.
- Add line to the list of figures.
And, this gives an error when I add lines to the list of figures in my actual (real) document. It tells me, "! Argument of \contentsline has an extra }."
Reference:
http://texblog.org/2013/07/16/how-to-ad ... nd-tables/
Code: Select all
\documentclass[11pt]{article}
\usepackage{blindtext}
\usepackage{caption}
\usepackage{etoolbox}
\begin{document}
\tableofcontents
\preto\figure{%
\ifnum\value{figure}=0\addtocontents{lof}{{\bfseries Section\thesection\vskip10pt}}\fi
}
\listoffigures
\addtocontents{lof}{\contentsline{section}{\protect\rule{\linewidth}{.5pt}}{}}
\section{First section}
\begin{minipage}{\linewidth}
\begin{center}
\rule{5cm}{4cm}
\captionof{figure}{this is my 1st caption}
\end{center}
\end{minipage}
\begin{minipage}{\linewidth}
\begin{center}
\rule{5cm}{4cm}
\captionof{figure}{this is my 2nd caption}
\end{center}
\end{minipage}
\blindtext
\addtocontents{lof}{\contentsline{section}{\protect\rule{\linewidth}{.5pt}}{}}
\section{Second section}
\begin{minipage}{\linewidth}
\begin{center}
\rule{5cm}{4cm}
\captionof{figure}{this is my 3rd caption}
\end{center}
\end{minipage}
\begin{minipage}{\linewidth}
\begin{center}
\rule{5cm}{4cm}
\captionof{figure}{this is my 4th caption}
\end{center}
\end{minipage}
\blindtext
\end{document}
How To Breakup List Of Figures For Bookmarks In PDF File
I added the bookmark feature for figure (and table) captions to the code.
It needs three runs of (pdflatex) to complete the correct ToC/LoT/LoF files.
Code: Select all
\documentclass[paper=a4,12pt]{scrartcl}%
\usepackage[demo]{graphicx}%
\usepackage{etoolbox}%
\usepackage{xpatch}%
\usepackage{blindtext}%
\usepackage{caption}%
\usepackage{placeins}%
\usepackage{morewrites}%
\usepackage{assoccnt}%
\usepackage{letltxmacro}%
\usepackage[bookmarksopen=true,bookmarksopenlevel=4]{hyperref}%
\makeatletter
% Get some file handles first
\newwrite\figurecountsout%
\newwrite\tablecountsout%
\newread\figurecountsin%
\newread\tablecountsin%
%%% `Unique` bookmarks
\newcounter{totalsections}
\DeclareAssociatedCounters{section}{totalsections}
%%% Redefine \caption
\LetLtxMacro\LaTeXStandardCaption\caption%
\newcommand{\caption@@noopt}[1]{%
\caption@@opt[#1]{#1}%
}%
\apptocmd{\refstepcounter}{\gdef\LastRefSteppedCounter{#1}}{}{}%
\apptocmd{\stepcounter}{\gdef\LastSteppedCounter{#1}}{}{}%
\newcommand{\caption@@opt}[2][]{%
\phantomsection%
\def\currentcountertype{}
\LaTeXStandardCaption[#1]{#2}%
\belowpdfbookmark{#1}{bookmark::\LastSteppedCounter::\number\value{totalsections}::\number\value{\LastSteppedCounter}}%
}%
\renewcommand{\caption}{%
\@ifnextchar[{%
\caption@@opt%
}{%
\caption@@noopt%
}%
}%
% The number of runs...
\newcounter{numberofruns}%
\newcommand{\secfig@@voidstage}{0}%
\newcommand{\secfig@@writecounterstage}{1}%
\newcommand{\secfig@@readcounterstage}{2}%
\newcommand{\secfig@@writecontentstage}{2}%
\newcommand{\secfig@@resetstage}{3}%
% numberofruns = 1 --> write figcount file --> no adding to lof
% numberofruns = 2 --> Read fig counters file and decide if a section entry is to be done
% numberofruns = 3 --> Last update run to the toc, do neither read nor write! Set the counter of runs to 0 then.
\@addtoreset{figure}{section}%
\@addtoreset{table}{section}%
\let\LaTeXStandardSection\section%
\newcommand{\unstarredsection@@noopt}[1]{%
% Call the command without option - long title will become 'short' title
\unstarredsection@@opt[#1]{#1}%
}%
\newcommand{\unstarredsection@@opt}[2][]{%
\FloatBarrier%
\gdef\lastsectionfigures{0}%
\gdef\lastsectiontables{0}%
\ifnumequal{\number\value{numberofruns}}{\secfig@@writecounterstage}{% Only write, if counter has value 1
\edef\lastsectionfigures{\number\value{figure}}%
\edef\lastsectionfigures{\number\value{table}}%
\ifnumequal{\number\value{section}}{0}{%
}{%
\immediate\write\figurecountsout{%
\number\value{figure}%
}%
\immediate\write\tablecountsout{%
\number\value{table}%
}%
}%
}{%
\ifnumequal{\number\value{numberofruns}}{\secfig@@readcounterstage}{% Only read, if value is \secfig@@readcounterstage%
\read\figurecountsin to \lastsectionfigures
\read\tablecountsin to \lastsectiontables%
}{}
}%
%\phantomsection Use here if hyperref is needed
\LaTeXStandardSection[#1]{#2}%
\ifnumequal{\number\value{numberofruns}}{\secfig@@writecontentstage}{% Only make an entry in stages >= 2
\ifnumgreater{\lastsectionfigures}{0}{%
\typeout{Writing a section entry for \thesection{}to the LOF}%
\addtocontents{lof}{\smallskip\textbf{\large\thesection~#1}\medskip}%
}{%
\typeout{No figures in \thesection!}
}%
\ifnumgreater{\lastsectiontables}{0}{%
\typeout{Writing a section entry for \thesection{}to the LOT}%
\addtocontents{lot}{\smallskip\textbf{\large\thesection~#1}\medskip}%
}{%
\typeout{No tables in \thesection!}
}%
}{}%
}%
\newcommand{\unstarredsection}{%
\@ifnextchar[{%
\unstarredsection@@opt%
}{%
\unstarredsection@@noopt%
}%
}%
\newcommand{\starredsection}[1]{%
\LaTeXStandardSection*{#1}%
}%
\renewcommand{\section}{%
\@ifstar{%
\starredsection%
}{%
\unstarredsection%
}%
}%
\AtBeginDocument{%
\typeout{Previous Stage \number\value{numberofruns}}%
\stepcounter{numberofruns}%
\typeout{Current Stage is now \number\value{numberofruns}}%
\ifnumequal{\number\value{numberofruns}}{\secfig@@writecounterstage}{%
\immediate\openout\figurecountsout=\jobname.figcount
\immediate\openout\tablecountsout=\jobname.tabcount
}{%
\openin\figurecountsin=\jobname.figcount%
\openin\tablecountsin=\jobname.tabcount%
}%
}%
\AtEndDocument{%
\ifnumequal{\number\value{numberofruns}}{\secfig@@resetstage}{%
\setcounter{numberofruns}{\secfig@@voidstage} % Reset counters afterwards.
}{}%
\immediate\write\@auxout{%
\string\setcounter{numberofruns}{\number\value{numberofruns}}
}
% Write the last figure counter value to the file!
\ifnumequal{\number\value{numberofruns}}{\secfig@@writecounterstage}{%
\immediate\write\figurecountsout{%
\number\value{figure}%
}%
\immediate\write\tablecountsout{%
\number\value{table}%
}%
\immediate\closeout\figurecountsout%
\immediate\closeout\tablecountsout%
}%
\immediate\closein\figurecountsin% Close input file
\immediate\closein\tablecountsin% Close input file
}%
\makeatother
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}%
\renewcommand{\thetable}{\arabic{section}.\arabic{table}}%
\begin{document}
\tableofcontents%
\listoffigures
\listoftables
\clearpage
\section{First}
\blindtext
\begin{figure}[!ht]
\begin{center}
\includegraphics[scale=1]{somefig}%
\caption{First}
\end{center}
\end{figure}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{somefig}%
\caption{Second}
\end{center}
\end{figure}
\begin{table}
\begin{tabular}{ccc}
a & small table \tabularnewline
\end{tabular}
\caption[Small Table]{First small table}
\end{table}
\section{Second}
\begin{figure}
\caption{Third}
\end{figure}
\begin{figure}
\caption{Fourth}
\end{figure}
\begin{figure}
\caption{Fifth}
\end{figure}
\begin{figure}
\caption{Sixth}%
\end{figure}
\section{Without figures}
\section[One with another title]{A very long, long, long section title}
\begin{figure}
\caption{Eight}
\end{figure}
\begin{figure}
\caption[short]{Ninth}
\end{figure}
\section{Another section without figures}%
\blindtext
\section[Yippie]{Last one}%
\begin{table}
\caption{dummy table}%
\end{table}
\end{document}