2

My document structure looks like this:

I. Example-heading
  1. Example-subheading
  2. Example-subheading 2
    a) Example-subsubheading
    b) Example-subsubheading 2
       (aa) Example-subsubsubheading
       (bb) Example-subsubheading 2
          ...
             ...
               ...
II. Example-heading 2
  1. Example2-subheading

When I now use

\subthreesection{Example-subsubsubheading}\label{my-label}

and later on somewhere in the text

\ref{my-label} \nameref{my-label}

The output is like

(aa) Example-subsubsubheading

But I would like to have

I.2.a).(aa) Example-subsubsubheading

And not only for third-level but for seven-level or deeper.

I'm using the document class hausarbeit-jura (a document class for jura student papers).

How can I achieve this?

7
  • Which document class do you employ? Also, do tell us how you've changed the numbering style of \section, \subsection, and \subsubsection-level headers.
    – Mico
    Mar 26, 2017 at 17:24
  • I added the name of the document class - hausarbeit-jura. But I don't know how it changes the numbering style.
    – Yeti
    Mar 26, 2017 at 17:48
  • @Yeti: Unfortunately this document class changes the numbering really and there is no easy way to track b) back to the first chapter and another b) back to another chapter etc.
    – user31729
    Mar 26, 2017 at 17:55
  • Thanks for indicating which document class you use. I've taken the liberty of editing the title and body of your posting to streamline the exposition.
    – Mico
    Mar 26, 2017 at 18:16
  • Thanks for updating the title! But to be exact it is not only referncing third-level but also seven- or n-level sections.
    – Yeti
    Mar 26, 2017 at 20:34

3 Answers 3

3

Since you use the hausarbeit-jura document class, I suggest you modify the "prefix macros" \p@subsection, \p@subsubsection, and \p@subthreesection. Specifically, you should insert the following instructions in the preamble:

\makeatletter
\renewcommand\p@subsection{\thesection}
\renewcommand\p@subsubsection{\p@subsection\thesubsection}
\renewcommand\p@subthreesection{\p@subsubsection\thesubsubsection.}
\renewcommand\p@subfoursection{\p@subthreesection\thesubthreesection.}
\renewcommand\p@subfivesection{\p@subfoursection\thesubfoursection.}
\renewcommand\p@subsixsection{\p@subfivesection\thesubfivesection.}
\makeatother

Remark: I've added three additional levels of cross-referencing prefix macros beyond those you requested in your initial posting. I trust you have enough information to carry on to levels seven and eight as well as to paragraph and subparagraphs...

A full MWE:

enter image description here

\documentclass{hausarbeit-jura}
\usepackage[colorlinks]{hyperref} % for \nameref macro

\makeatletter  % use a recursive approach to define the prefix macros:
\renewcommand\p@subsection{\thesection}
\renewcommand\p@subsubsection{\p@subsection\thesubsection}
\renewcommand\p@subthreesection{\p@subsubsection\thesubsubsection.}
\renewcommand\p@subfoursection{\p@subthreesection\thesubthreesection.}
\renewcommand\p@subfivesection{\p@subfoursection\thesubfoursection.}
\makeatother

\begin{document}
level-1 sub: \ref{my-label1} \nameref{my-label1}

level-2 sub: \ref{my-label2} \nameref{my-label2}

level-3 sub: \ref{my-label3} \nameref{my-label3}

level-4 sub: \ref{my-label4} \nameref{my-label4}

level-5 sub: \ref{my-label5} \nameref{my-label5}

etc.

\section{Section heading}
\subsection{Subsection heading} \label{my-label1}
\subsubsection{Subsubsection heading} \label{my-label2}
\subthreesection{Subthree-heading} \label{my-label3}
\subfoursection{Subfour-heading} \label{my-label4}
\subfivesection{Subfive-heading} \label{my-label5}
\end{document}
2
  • Nice. I considered this also ...(+1)
    – user31729
    Mar 26, 2017 at 18:21
  • 1
    Thanks for your answer! As I sad above I was not that exact in the original question as i thought. It is not about referencing only third-level sections but also like seven- or n-level section ...
    – Yeti
    Mar 26, 2017 at 20:35
2

Apart from the numbering style (which must be setup differently and that's a different question) the 'contraction' of the reference style can be achieved easily with zref when links are required, just replace \label with zlabel and setup a \fullref command that extracts the anchor, default value and title of the link.

\documentclass{book}
\usepackage{hyperref}

\usepackage[user,hyperref,titleref]{zref}


\makeatletter
\newcommand{\fullref}[1]{%
  % Check for existence and provide a hyperlink
  \zref@ifrefundefined{#1}{%
  }{%
    \hyperlink{\zref@extract{#1}{anchor}}{\zref@extract{#1}{default} \zref@extract{#1}{title}}%
  }%    
}
\makeatother


\begin{document}

See \fullref{my-label}

\chapter{Example-heading}
\section{Example-subheading}
\section{Example-subheading 2}
\subsection{Example subsubheading} 

\subsubsection{Example subsubheading} 
\subsubsection{Example subsubheading 2}  \zlabel{my-label}

\chapter{Example-heading 2}
\section{Example-subheading again}

\end{document}

enter image description here

Update for the hausarbeit-jura.cls

\documentclass{hausarbeit-jura}

\usepackage{expl3}
\usepackage{hyperref}
\usepackage[counter,user,hyperref,titleref]{zref}


\makeatletter
\zref@newprop{chapterprop}{\thechapter}
\zref@newprop{sectionprop}{\thesection}
\zref@newprop{subsectionprop}{\thesubsection}
\zref@newprop{subsubsectionprop}{\thesubsubsection}
\zref@addprops{main}{chapterprop,sectionprop,subsectionprop,subsubsectionprop}

\ExplSyntaxOn

\cs_new:Npn \extractstructure #1{
  \str_case_x:nn {\zref@extract{#1}{counter} }
  {
    {chapter} {\zref@extract{#1}{chapterprop} }
    {section} {\zref@extract{#1}{chapterprop}~\zref@extract{#1}{sectionprop} }
    {subsection} {\zref@extract{#1}{chapterprop}~\zref@extract{#1}{sectionprop}~\zref@extract{#1}{subsectionprop} }
    {subsubsection} {\zref@extract{#1}{chapterprop}~\zref@extract{#1}{sectionprop}~\zref@extract{#1}{subsectionprop}~\zref@extract{#1}{subsubsectionprop} }
  } 
}
\ExplSyntaxOff

\newcommand{\fullref}[1]{%
  % Check for existence and provide a hyperlink
  \zref@ifrefundefined{#1}{%
  }{%
    \hyperlink{\zref@extract{#1}{anchor}}{\extractstructure{#1} \zref@extract{#1}{title}}
  }%    
}
\makeatother


\begin{document}

See \fullref{my-label} or \fullref{somechapter}

\chapter{Example-heading}
\section{Example-subheading}
\section{Example-subheading 2}
\subsection{Example subsubheading} 

\subsubsection{Example subsubheading} 
\subsubsection{Example subsubheading 2}  \zlabel{my-label}

\chapter{Example-heading 2} \zlabel{somechapter}
\section{Example-subheading again}

\end{document}

enter image description here

5
  • I think the OP is working without \chapter but with \subthreesection. [Aside: The OP's document class also provides \subfoursection, ... , \subeightsection macros. Downright scary, if you ask me.]
    – Mico
    Mar 26, 2017 at 18:19
  • @Mico: I will change later on... and yes, what has jurisdiction ever done for us, apart from strange numbering/structuring schemes ;-)
    – user31729
    Mar 26, 2017 at 18:20
  • I suppose each profession has managed to develop its own set of barriers to entry to keep all but the most dedicated wannabes out. In some fields the barrier is an ability to do math comfortably and competently -- this includes my field (economics -- Volkswirtschaftslehre. In other fields it's an expectation to read lots and lots of books and pamphlets, many of which are of dubious to low intrinsic interest and value (literature...). In law, it's quite evidently an ability to build and keep track of rather elaborate numbering systems...
    – Mico
    Mar 26, 2017 at 18:26
  • 1
    @Mico You're right about the chapters. I only use section down to subsevensection (and could(!) use than up to subparagraph). And you are right about the barriers. :)
    – Yeti
    Mar 26, 2017 at 20:39
  • I've upvoted your answer. :-)
    – Mico
    Mar 26, 2017 at 21:17
1

I had the same question with a standard document class: Abbreviated references: just the necessary references, no more

In a nutshell: If I'm on the "II." branch, the reference from e.g. II.3.b) doesn't need to be to II.1.a), but simply 1.a). But if I'm refering from somewhere under III., the reference in the text has to bee II.1.a), of course.

It took me a whole day and much help to find this solution:

https://tex.stackexchange.com/a/325871/4736

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .