TeX - LaTeX Asked by N3buchadnezzar on February 13, 2021
I have some code that looks like
section*{Problem 1}
begin{enumerate}
item Hello
item label{problem-2b} Yes
item cref{problem-2b} Welp
end{enumerate}
I want the reference to appear as
problem 1a)
as a refference. How can I include the name of the previous section into the reference? I already have the exercise number as a counter.
For a “MWE” of my actual problem see below
documentclass{article}
usepackage{xparse}
usepackage{etoolbox} %Neccecary for ifthenelse
usepackage{enumitem}
newcounter{tittel}
setcounter{tittel}{0}
newcounter{prob}[tittel]
setcounter{prob}{0}
newcounter{alternative}[prob]
setcounter{alternative}{0}
newcounter{alfa}[prob]
newififfirstalt
NewDocumentCommand{Oppgave}{s o}{ %
IfBooleanTF{#1}%
{refstepcounter{alternative}iffirstaltelserefstepcounter{prob}firstalttruefi}%
{setcounter{alternative}{0}refstepcounter{prob}firstaltfalse}%
section*{Oppgave~arabic{prob}~%
label{arabic{tittel}.arabic{prob}}
{normalfontIfBooleanTF{#1}{Alternativ Roman{alternative}~}{}}%
IfNoValueTF{#2}{}{normalfontnormalsize (#2~poeng)}}%
addcontentsline{toc}{section}{Oppgave~arabic{prob}} refstepcounter{alfa}
}
makeatletter
letorg@item@item
defmyspecial@item[#1]{%
org@item[#1]%
ifdef@listctr
{%
expandafterifdefequal@listctr@enumctr
{addcontentsline{toc}{subsection}{hspace{0.8em}textbf{alph{alfa})}}
label{arabic{tittel}.arabic{prob}.alph{alfa}}
refstepcounter{alfa}}%
{}%
}{}%
}
newenvironment{oppgaver}{%
begin{enumerate}[ref={alph{alfa}},topsep =1.2em,label=textbf{alph{alfa})},labelsep=1.5em,itemsep=0.7cm]
let@itemmyspecial@item
}{%
end{enumerate}
}
makeatother
usepackage{hyperref}
hypersetup{
linktoc=all, % Link all the things in the toc
colorlinks=true, % false: boxed links; true: colored links
linkcolor=black, % color of internal links (change box color with linkbordercolor)
}
usepackage[norsk, nameinlink, noabbrev]{cleveref}
crefname{alfa}{oppgave}{oppgave}
Crefname{alfa}{Oppgave}{Oppgave}
begin{document}
tableofcontents
stepcounter{tittel}
Oppgave[4] % Oppgave 1
begin{oppgaver}
item Prob 1
item label{prob1b} Prob 2
item cref{prob1b} Prob 3
end{oppgaver}
end{document}
You can do that by redefining p@enumi
.
documentclass{article}
makeatletter
renewcommand*p@enumi{thesection.}
makeatother
begin{document}
section{Some Section}
begin{enumerate}
item Hello
item label{some-item} Yes
item Bye
end{enumerate}
Look at item~ref{some-item}
end{document}
Answered by schtandard on February 13, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP