附录编号的智能解决方案

附录编号的智能解决方案

好吧,我总结一下。我得到了一些练习(6)和每个练习的几个答案。所有练习和答案都包含在 graphicx 中。所以我可以在讨论中自动引用它们。我希望附录的结构是:按练习 1 命名——练习 1 的答案——练习 2——答案.....我希望它们被命名为 E1——A E1——E2——A E2,所以当 \autoref{tim}(查看代码)时,它会显示为:图片 A E1:Tim

\documentclass[a4paper,11pt]{article}
\usepackage[ngerman]{babel}

\usepackage[utf8]{inputenc}
%Formalia der schriftlichen Arbeit
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage{pdfpages}
\usepackage{graphicx}
\usepackage{hyperref}     
\usepackage{url}
\usepackage{caption}
\usepackage{lscape}
\usepackage{longtable} 
\usepackage{chngcntr}
\counterwithin{figure}{section}

\usepackage[numbers]{natbib}    
\usepackage{parskip}
%\setlength{\parindent}{10pt}

%Abstand nach Section

\begin{document}

\tableofcontents
\newpage
\section{hi}
d
\newpage
\appendix
\section{Exercise 1}
\renewcommand{\thesection}{E\arabic{section}}
\begin{figure}[ht]
    \centering
  \includegraphics[width=.99\textwidth,angle = 270 ]{Eercises/E1.pdf}
    \caption{Exercise 1}
    \label{A1a}
\end{figure}
%this A E1 stands for Answer of Exc 1.
\section{A E1}\renewcommand{\thesection}{A E\arabic{section}}
\begin{figure}[ht]
    \centering
  \includegraphics[width=0.7\textwidth]{pictures/AE1/Tim.JPG}
    \caption{Tim}
    \label{tim}
\end{figure}


\end{document}

引用

答案1

如果我正确理解了这个问题,那么尝试一下解决方案。

我稍微改变了输出并添加了一个结合和的\thefigure宏,用于打印标题。\autorefname\autoref\nameref

但带星号的版本\autonameref*不会使用超链接。

\documentclass[a4paper,11pt]{article}
\usepackage[ngerman]{babel}

\usepackage[utf8]{inputenc}
%Formalia der schriftlichen Arbeit
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage{pdfpages}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{longtable} 
\usepackage{chngcntr}
\counterwithin{figure}{section}

\usepackage[numbers]{natbib}    
\usepackage{parskip}

\usepackage{hyperref}     
\usepackage{url}
\usepackage{caption}

%\setlength{\parindent}{10pt}

%Abstand nach Section

\usepackage{xparse}
\usepackage{cleveref}
\usepackage{crossreftools}

\newcommand{\figureprefix}{E}

\makeatletter
\NewDocumentCommand{\autonameref}{sm}{%
  % Check for label existence first:
  \@ifundefined{r@#2}{%
    % Do nothing...
  }{%
    \IfBooleanTF{#1}{%
      % No hyperlink, just the reference 'text'
      \csname \crtcrefcounter{#2}autorefname\endcsname\ \crtrefnumber{#2}: \crtrefname{#2}%
    }{%
      % Construct the hyperlink and link text as \...autorefname refnumber: caption (etc.) content
      \hyperlink{\crtrefanchor{#2}}{\csname \crtcrefcounter{#2}autorefname\endcsname\ \crtrefnumber{#2}: \crtrefname{#2}}%
    }%
  }%
}
\makeatother

\begin{document}

\tableofcontents
\clearpage

\section{Foo section}

See \autonameref{Ente} or \autonameref*{A1a}

\autonameref{foo}
\clearpage
\appendix
\section{Exercise 1} \label{foo}
\renewcommand{\thesection}{\figureprefix\arabic{section}}
\begin{figure}[ht]
  \let\thefigure\thesection
  \centering
  \includegraphics{ente}
%  \includegraphics[width=.99\textwidth,angle = 270 ]{Eercises/E1.pdf}
  \caption{Exercise 1}\label{A1a}
\end{figure}
% this A E1 stands for Answer of Exc 1.
\section{A E1}\renewcommand{\thesection}{A E\arabic{section}}
\begin{figure}[ht]
\renewcommand{\thefigure}{\thesection}
  \centering
  \includegraphics[width=0.7\textwidth]{ente}
  % \includegraphics[width=0.7\textwidth]{pictures/AE1/Tim.JPG}
  \caption{Ente}\label{Ente}
\end{figure}


\end{document}

在此处输入图片描述

相关内容