附录页面显示所有附录的图片

附录页面显示所有附录的图片

我想制作一个附录页面,以简单的最小图片显示文档中所有附录。我想要的是,每次在命令\chapter{}后使用\appendix时,都应显示附录的图片。例如,如果附录页面上有 5 个附录 A、B、C、D 和 E,则应显示以下内容:如果可能的话,可能带有附录的标题。我使用报告作为\documentclass

在此处输入图片描述

答案1

这不是完全自动化的解决方案...需要编写一些脚本,但这是一个开始。基本思路是编译文档,将结果保存pdf为单独的文件,然后使用tikz创建包含附录第一页的节点。

最好通过一个例子来证明(按照上述方法,结果pdf被保存为file.pdf;参见\pdfforappximgs):

\documentclass{report}
\usepackage[left=1in,top=1in,bottom=1in,right=1in]{geometry}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{etoolbox}

%File path for pdf used to provide the images for the appendices. Must be a separate document from \jobname for access.
\def\pdfforappximgs{file}
%The rotation angle of the last appendix (drawn first)
\def\appxcardsinitialangle{40}
%The angle by which each successive appendix is rotated clockwise from the previous one
\def\appxcardsanglestep{15}
%Multiplier to get the x coordinate from the index
\def\appxcardxfactor{0.25}
%Multiplier to get the y coordinate from the index
\def\appxcardyfactor{0.25}
%The scale factor for the page
\def\appxcardscale{0.125}
%Numer of cards in a single row
\def\appxcardperrow{7}

\makeatletter
    % Array for appendices  
    \newcounter{appxpagecount}%
    \newcommand\setappxpage[2]{\csgdef{appxpage#1}{#2}}%
    \newcommand\addappxpage[1]{\stepcounter{appxpagecount}\setappxpage{\theappxpagecount}{#1}}%
    \newcommand\getappxpage[1]{\csuse{appxpage#1}}%

    %command to draw the appendix cards. Intened to be after \appendix.
    \def\appxcoverpage{%
        \chapter*{Appendices}%Add the heading to the cover page
        %Redefine \chapter and \chapter* to reference the page
        \let\old@chapter\@chapter%previous definition for the unstarred chapter
        \let\old@schapter\@schapter%\previous definition for the starred chapter
        \def\appendtochptexec{\protect\immediate\write\@auxout{\string\addappxpage{\thepage}}}%write to aux file the reference for the page 
        \gdef\@chapter[##1]##2{\old@chapter[##1]{##2}\appendtochptexec}
        \gdef\@schapter##1{\old@schapter{##1}\appendtochptexec}
        %Draw the cards
        \expandafter\ifx\expandafter\relax\pdfforappximgs\relax\else
            \IfFileExists{\pdfforappximgs.pdf}{}{\gdef\pdfforappximgs{\relax}}%Check that the file exists
        \fi
        \expandafter\ifx\expandafter\relax\pdfforappximgs\relax\wlog{No pdf file provided for appendix card display}\else%verify that the file is given and exists
            \pdfximage{\pdfforappximgs.pdf}%Get the number of pages in said pdf
            \edef\availpgs{\pdflastximagepages}
            \ifnum\theappxpagecount=0\wlog{No appendices for appendix card display}\else%do nothing if there are no appendices
                \expandafter\ifnum\getappxpage{\theappxpagecount}>\pdflastximagepages\wlog{Update the appendix pdf file...insufficient pages}\else%do nothing if there are not enough pages
                    %initialize the ranges      
                    \newcounter{cmini}
                    \newcounter{cmaxi}
                    \setcounter{cmini}{1}
                    \setcounter{cmaxi}{\appxcardperrow}
                    \ifnum\thecmaxi>\theappxpagecount\relax\setcounter{cmaxi}{\theappxpagecount}\else\fi
                    %upper limit for the loop must be 1 greater than the count to ensure all are included
                    \newcounter{cexclup}
                    \setcounter{cexclup}{\theappxpagecount}
                    \addtocounter{cexclup}{1}
                    \loop\ifnum\thecmini<\thecexclup
                        \begin{center}
                            \begin{tikzpicture}
                                \foreach \x in {\thecmaxi,...,\thecmini}{
                                    \pgfmathsetmacro\revx{\thecmaxi-\x+1};
                                    \node[fill=white,draw,anchor=south west,rotate=\appxcardsinitialangle-\appxcardsanglestep*(\revx-1)] at (\appxcardxfactor*\revx,\appxcardyfactor*\revx) {\includegraphics[page=\getappxpage{\x},scale=\appxcardscale]{\pdfforappximgs.pdf}};}
                            \end{tikzpicture}
                        \end{center}
                        %advance the counters to the next row
                        \setcounter{cmini}{\thecmaxi}
                        \addtocounter{cmini}{1}
                        \setcounter{cmaxi}{\appxcardperrow}
                        \addtocounter{cmaxi}{-1}
                        \addtocounter{cmaxi}{\thecmini}
                        \ifnum\thecmaxi>\theappxpagecount\relax\setcounter{cmaxi}{\theappxpagecount}\else\fi
                    \repeat
                \fi
            \fi
        \fi
    }
\makeatother
\begin{document}
\chapter{Introduction}
Some text.
\chapter{Literature Review}
Some more text.
\chapter{Results and Discussion}
Even more text. 

\appendix
\appxcoverpage
\chapter*{Supplementary Material 1}
Some text.
\chapter[shorter title]{Supplementary Material 2}
Some text.
\chapter{Supplementary Material 3}
Some text.
\chapter{Supplementary Material 4}
Some text.
\chapter{Supplementary Material 5}
Some text.
\chapter{Supplementary Material 6}
Some text.
\chapter{Supplementary Material 7}
Some text.
\chapter{Supplementary Material 8}
Some text.
\chapter{Supplementary Material 9}
Some text.
\chapter{Supplementary Material 10}
Some text.
\chapter{Supplementary Material 11}
Some text.
\chapter{Supplementary Material 12}
Some text.
\chapter{Supplementary Material 13}
Some text.
\end{document}

包含一些粗略的错误检查,\appxcoverpage以确保提供了文件名(应默认为)\relax,有附录可供绘制,并且引用的pdf够长了

上述示例在附录封面上产生以下内容:

appx 卡阵列

\appxcardperrow命令设置组中显示的附录卡片的最大数量。随着组中附录数量的增加,可以实现替代效果:

appx 卡太多

相关内容