1

I used the command getcurrentref from this question/answer to achieve a custom numbering when \paragraph is used.

I wrapped it into the macro:

\newcommand\mybook[1]{\paragraph{B \getcurrentref{subsection}-\getcurrentref{paragraph}: #1}\hfill\par\vspace{0.2\baselineskip}}%

And it allows my to get a structure like this:

enter image description here

It doesn't seem the best solution, but it works.

Basically I'm facing the problem, that the numbering of subsubsections should be ignored and the numbering of the paragraph should only contain the current subsection and the subsequent paragraph numbers.

However I'd like to reference my custom paragraph with the custom numbering, which does not work, as you see in B 1-2.

How can I make \ref or even better \cref to adapt my custom numbering?

I thought it should work with customizing the paragraph command directly like here, but I can't get it work.

Any ideas?

I'd need a solution for KOMA-script classes. I need to keep the subsubsections as I need them in other parts of my document.


MWE

\documentclass{scrreprt}
\usepackage{etoolbox}

% get currentref command
\newcommand\getcurrentref[1]{%
 \ifnumequal{\value{#1}}{0}
  {??}
  {\the\value{#1}}%
} 

% remove label from paragraph, even if numbered
\renewcommand*{\paragraphformat}{}

% custom paragraph heading 
\newcommand\mybook[1]{\paragraph{B \getcurrentref{subsection}-\getcurrentref{paragraph}: #1}\hfill\par\vspace{0.2\baselineskip}}%

\setcounter{secnumdepth}{4} % how many sectioning levels to assign numbers to
\setcounter{tocdepth}{2}    % how many sectioning levels to show in ToC  

\begin{document}

\chapter{Books (chapter)}
\section{Fiction (section)}
\subsection{Dystopy (subsection)}

\subsubsection*{George Orwell (subsubsection 1.1.1.1)}

\mybook{Animal Farm (paragraph)}\label{AnimalFarm}

Animal Farm is an allegorical and dystopian novella by George Orwell, first [...]

\mybook{1984 (paragraph)}

Nineteen Eighty-Four, often published as 1984, is a dystopian novel [...]
I'd like to reference Animal Farm (\ref{AnimalFarm}) as B 1-1 [...]

\subsubsection*{Aldous Huxley (subsubsection  1.1.1.2)}

\mybook{Brave New World (paragraph)}

Brave New World is a novel written in 1931 by [...]

\subsection{Historic Novel (subsection)}

\subsubsection*{Ken Follet}

\mybook{The Pillars of the Earth (paragraph)}

\section{Non-Fiction}
\subsection{Cooking}
\subsubsection*{Baking}
\mybook{Baking without flour}
\subsubsection*{Cooking}
\mybook{Cooking without water}

\end{document}
5
  • At the moment I don't understand what you really want to achieve. What should be the output of your references? Is the 0 in 1.1.1.0.1 the issue? This is totally clear, since the subsubsection` counter is zero at the moment of using it – user31729 May 30 '16 at 16:12
  • You want the books to be numbered, dont you? The book-book counters shall be reset for each increase of book-counter? You then need some kind of personal label, to refer to the custom booky stuff? – MaestroGlanz May 30 '16 at 16:15
  • @ChristianHupfer I dont want 1.1.1.0.1 to be displayed, I want B 1-1 to be displayed. – thewaywewalk May 30 '16 at 16:21
  • @MaestroGlanz For the current paragraph I just want to consider the current section and the current paragraph to be considered. The subsection number should be skipped. And with every new section the paragraph numbering should be reset. – thewaywewalk May 30 '16 at 16:22
  • Please try the suggestions first and tell us what should be changed. In my suggestions, booknumber is independent from section numbering. But this can be changed. – MaestroGlanz May 30 '16 at 16:30
1

Why not redefining the \theparagraph, this will set the reference the easiest way:

\documentclass{scrreprt}
\usepackage{etoolbox}

% get currentref command
\newcommand\getcurrentref[1]{%
 \ifnumequal{\value{#1}}{0}
  {??}
  {\the\value{#1}}%
} 

% remove label from paragraph, even if numbered
\renewcommand*{\paragraphformat}{}

% custom paragraph heading 
\newcommand\mybook[1]{\paragraph{B \getcurrentref{subsection}-\getcurrentref{paragraph}: #1}\hfill\par\vspace{0.2\baselineskip}}%

\renewcommand{\theparagraph}{B \arabic{subsection}-\arabic{paragraph}}


\usepackage{cleveref}

\crefname{paragraph}{paragraph}{paragraphs}
\Crefname{paragraph}{Paragraph}{Paragraphs}


\setcounter{secnumdepth}{4} % how many sectioning levels to assign numbers to
\setcounter{tocdepth}{2}    % how many sectioning levels to show in ToC  




\begin{document}


\chapter{Books}
\section{Fiction}
\subsection{Dystopy}

\subsubsection*{George Orwell}

\mybook{Animal Farm}\label{AnimalFarm}

Animal Farm is an allegorical and dystopian novella by George Orwell, first [...]

\mybook{1984}

Nineteen Eighty-Four, often published as 1984, is a dystopian novel [...]

\subsubsection*{Aldous Huxley}

\mybook{Brave New World}

Brave New World is a novel written in 1931 by [...]

\section{Interpretation}

I'd like to Reference Animal Farm (\ref{AnimalFarm}) as B 1-1 [...]

In \cref{AnimalFarm} we saw that Orwell...

\end{document}

enter image description here

In principle, this would also avoid \getcurrentref command.

3
  • Yes, by setting \setcounter{secnumdepth}{5} and removing \renewcommand*{\paragraphformat}{} I could just use \paragraph instead of mybook. Great! – thewaywewalk May 30 '16 at 16:35
  • @thewaywewalk: I already wondered about this strange stuff ... – user31729 May 30 '16 at 16:36
  • Well that was required for the macro to work as intended ;) – thewaywewalk May 30 '16 at 16:37
0

Sonmething like this?

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


\newcounter{book}
\newcounter{subbook}[book]

\def\bookagraph#1{\stepcounter{book}\stepcounter{subbook} \paragraph{B \arabic{book} -\arabic{subbook} #1}\expandafter\label{bookagraph_\arabic{book}\arabic{subbook}}}

\begin{document}

\arabic{book}

\bookagraph{Heute}

As seen in \nameref{bookagraph_11}

\end{document}

For further wishes, please ask.

2
  • I can't get work for my example, the counter is not reset for example. – thewaywewalk May 30 '16 at 16:36
  • @thewaywewalk You see \newcounter{subbook}[book]? The second argument [ ] defines, when the counter subbook is reset (if book changes). Maybe you try ChristianHupfers code. He does better code than me. – MaestroGlanz May 30 '16 at 16:39

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.