Put section number in reference to subsection, but not in title












4















The below code produces



enter image description here



I'm wondering if it's possible to have the subsections show up as i, ii, etc, on the subsection title (because it's clear which section they're in when they show up), but as 1.i, 1.ii, etc. when I refer to them. (So that the reader can distinguish between 1.i and 2.i, for instance.)



Possibilities:




  1. Just enter the section number manually when I refer to it. This is
    worst, since it isn't robust to renumbering the sections.

  2. Find a way to store the section number of Fruit Section, and use
    that when I make the reference. This is OK, but not robust to
    changing which section Apples is a part of.

  3. Inside Apples, get the current section somehow, store it, and then
    refer to it. This would be robust, but would have to be done every time I want to make such a reference.

  4. Better once-and-for-all solution to this problem.


.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}









share|improve this question


















  • 1





    I general I think users are going to be confused when they are browsing through the document that there are more than one section that are named i. It is probably doable using some hackery,but I would not recommend it.

    – daleif
    Jun 21 '18 at 14:45











  • @daleif I for one bin such documents...if the author cannot be bothered to use proper structure in the document, why should I be bothered reading it?

    – naphaneal
    Jun 21 '18 at 16:26











  • @naphaneal there apparently is a kind of "cult" around this way of numbering, I have a colleague who adhere to it. But as mentioned, I pity the reader.

    – daleif
    Jun 21 '18 at 16:28
















4















The below code produces



enter image description here



I'm wondering if it's possible to have the subsections show up as i, ii, etc, on the subsection title (because it's clear which section they're in when they show up), but as 1.i, 1.ii, etc. when I refer to them. (So that the reader can distinguish between 1.i and 2.i, for instance.)



Possibilities:




  1. Just enter the section number manually when I refer to it. This is
    worst, since it isn't robust to renumbering the sections.

  2. Find a way to store the section number of Fruit Section, and use
    that when I make the reference. This is OK, but not robust to
    changing which section Apples is a part of.

  3. Inside Apples, get the current section somehow, store it, and then
    refer to it. This would be robust, but would have to be done every time I want to make such a reference.

  4. Better once-and-for-all solution to this problem.


.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}









share|improve this question


















  • 1





    I general I think users are going to be confused when they are browsing through the document that there are more than one section that are named i. It is probably doable using some hackery,but I would not recommend it.

    – daleif
    Jun 21 '18 at 14:45











  • @daleif I for one bin such documents...if the author cannot be bothered to use proper structure in the document, why should I be bothered reading it?

    – naphaneal
    Jun 21 '18 at 16:26











  • @naphaneal there apparently is a kind of "cult" around this way of numbering, I have a colleague who adhere to it. But as mentioned, I pity the reader.

    – daleif
    Jun 21 '18 at 16:28














4












4








4








The below code produces



enter image description here



I'm wondering if it's possible to have the subsections show up as i, ii, etc, on the subsection title (because it's clear which section they're in when they show up), but as 1.i, 1.ii, etc. when I refer to them. (So that the reader can distinguish between 1.i and 2.i, for instance.)



Possibilities:




  1. Just enter the section number manually when I refer to it. This is
    worst, since it isn't robust to renumbering the sections.

  2. Find a way to store the section number of Fruit Section, and use
    that when I make the reference. This is OK, but not robust to
    changing which section Apples is a part of.

  3. Inside Apples, get the current section somehow, store it, and then
    refer to it. This would be robust, but would have to be done every time I want to make such a reference.

  4. Better once-and-for-all solution to this problem.


.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}









share|improve this question














The below code produces



enter image description here



I'm wondering if it's possible to have the subsections show up as i, ii, etc, on the subsection title (because it's clear which section they're in when they show up), but as 1.i, 1.ii, etc. when I refer to them. (So that the reader can distinguish between 1.i and 2.i, for instance.)



Possibilities:




  1. Just enter the section number manually when I refer to it. This is
    worst, since it isn't robust to renumbering the sections.

  2. Find a way to store the section number of Fruit Section, and use
    that when I make the reference. This is OK, but not robust to
    changing which section Apples is a part of.

  3. Inside Apples, get the current section somehow, store it, and then
    refer to it. This would be robust, but would have to be done every time I want to make such a reference.

  4. Better once-and-for-all solution to this problem.


.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}






hyperref cross-referencing numbering






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 21 '18 at 14:40









Eric AuldEric Auld

3731515




3731515








  • 1





    I general I think users are going to be confused when they are browsing through the document that there are more than one section that are named i. It is probably doable using some hackery,but I would not recommend it.

    – daleif
    Jun 21 '18 at 14:45











  • @daleif I for one bin such documents...if the author cannot be bothered to use proper structure in the document, why should I be bothered reading it?

    – naphaneal
    Jun 21 '18 at 16:26











  • @naphaneal there apparently is a kind of "cult" around this way of numbering, I have a colleague who adhere to it. But as mentioned, I pity the reader.

    – daleif
    Jun 21 '18 at 16:28














  • 1





    I general I think users are going to be confused when they are browsing through the document that there are more than one section that are named i. It is probably doable using some hackery,but I would not recommend it.

    – daleif
    Jun 21 '18 at 14:45











  • @daleif I for one bin such documents...if the author cannot be bothered to use proper structure in the document, why should I be bothered reading it?

    – naphaneal
    Jun 21 '18 at 16:26











  • @naphaneal there apparently is a kind of "cult" around this way of numbering, I have a colleague who adhere to it. But as mentioned, I pity the reader.

    – daleif
    Jun 21 '18 at 16:28








1




1





I general I think users are going to be confused when they are browsing through the document that there are more than one section that are named i. It is probably doable using some hackery,but I would not recommend it.

– daleif
Jun 21 '18 at 14:45





I general I think users are going to be confused when they are browsing through the document that there are more than one section that are named i. It is probably doable using some hackery,but I would not recommend it.

– daleif
Jun 21 '18 at 14:45













@daleif I for one bin such documents...if the author cannot be bothered to use proper structure in the document, why should I be bothered reading it?

– naphaneal
Jun 21 '18 at 16:26





@daleif I for one bin such documents...if the author cannot be bothered to use proper structure in the document, why should I be bothered reading it?

– naphaneal
Jun 21 '18 at 16:26













@naphaneal there apparently is a kind of "cult" around this way of numbering, I have a colleague who adhere to it. But as mentioned, I pity the reader.

– daleif
Jun 21 '18 at 16:28





@naphaneal there apparently is a kind of "cult" around this way of numbering, I have a colleague who adhere to it. But as mentioned, I pity the reader.

– daleif
Jun 21 '18 at 16:28










1 Answer
1






active

oldest

votes


















4














You can use p@<counter> to add something before the actual counter value in references. To quote source2e (§22.1)




p@foo Macro that expands to a printed ‘reference prefix’ of counter foo. Any ref to a value created by counter foo will produce the expansion of p@foothefoo when the label command is executed.




So



makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother


would add the section and a dot whenever you reference a subsection.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}


enter image description here



Having seen the result I would probably not do this, especially if the subsections can be longer, and would include the section number for subsections also in the headings.






share|improve this answer


























  • Is there a way to show the section number for only one reference in the document, but not in general? I tried putting makeatletter renewcommand... inside a group along with the reference I'm making, but it didn't work. (I'm guessing makeatletter renewcommand... wants to be in the preamble.)

    – Eric Auld
    Jun 21 '18 at 16:24











  • @EricAuld What exactly are you thinking of? As far as I am aware the p@foo setting active at the time of defining the label governs all of its later uses in ref no matter what their environment setting w.r.t p@foo is. So if you want something more complicated a different solution is probably needed. Please ask a new question about that.

    – moewe
    Jun 21 '18 at 16:29











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f437402%2fput-section-number-in-reference-to-subsection-but-not-in-title%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














You can use p@<counter> to add something before the actual counter value in references. To quote source2e (§22.1)




p@foo Macro that expands to a printed ‘reference prefix’ of counter foo. Any ref to a value created by counter foo will produce the expansion of p@foothefoo when the label command is executed.




So



makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother


would add the section and a dot whenever you reference a subsection.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}


enter image description here



Having seen the result I would probably not do this, especially if the subsections can be longer, and would include the section number for subsections also in the headings.






share|improve this answer


























  • Is there a way to show the section number for only one reference in the document, but not in general? I tried putting makeatletter renewcommand... inside a group along with the reference I'm making, but it didn't work. (I'm guessing makeatletter renewcommand... wants to be in the preamble.)

    – Eric Auld
    Jun 21 '18 at 16:24











  • @EricAuld What exactly are you thinking of? As far as I am aware the p@foo setting active at the time of defining the label governs all of its later uses in ref no matter what their environment setting w.r.t p@foo is. So if you want something more complicated a different solution is probably needed. Please ask a new question about that.

    – moewe
    Jun 21 '18 at 16:29
















4














You can use p@<counter> to add something before the actual counter value in references. To quote source2e (§22.1)




p@foo Macro that expands to a printed ‘reference prefix’ of counter foo. Any ref to a value created by counter foo will produce the expansion of p@foothefoo when the label command is executed.




So



makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother


would add the section and a dot whenever you reference a subsection.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}


enter image description here



Having seen the result I would probably not do this, especially if the subsections can be longer, and would include the section number for subsections also in the headings.






share|improve this answer


























  • Is there a way to show the section number for only one reference in the document, but not in general? I tried putting makeatletter renewcommand... inside a group along with the reference I'm making, but it didn't work. (I'm guessing makeatletter renewcommand... wants to be in the preamble.)

    – Eric Auld
    Jun 21 '18 at 16:24











  • @EricAuld What exactly are you thinking of? As far as I am aware the p@foo setting active at the time of defining the label governs all of its later uses in ref no matter what their environment setting w.r.t p@foo is. So if you want something more complicated a different solution is probably needed. Please ask a new question about that.

    – moewe
    Jun 21 '18 at 16:29














4












4








4







You can use p@<counter> to add something before the actual counter value in references. To quote source2e (§22.1)




p@foo Macro that expands to a printed ‘reference prefix’ of counter foo. Any ref to a value created by counter foo will produce the expansion of p@foothefoo when the label command is executed.




So



makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother


would add the section and a dot whenever you reference a subsection.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}


enter image description here



Having seen the result I would probably not do this, especially if the subsections can be longer, and would include the section number for subsections also in the headings.






share|improve this answer















You can use p@<counter> to add something before the actual counter value in references. To quote source2e (§22.1)




p@foo Macro that expands to a printed ‘reference prefix’ of counter foo. Any ref to a value created by counter foo will produce the expansion of p@foothefoo when the label command is executed.




So



makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother


would add the section and a dot whenever you reference a subsection.



documentclass{article}
usepackage{hyperref}
renewcommandthesubsection{roman{subsection}}
makeatletter
renewcommand*{p@subsection}{thesection.}
makeatother
begin{document}
section{Fruit Section}
subsection{Apples} label{Apples-subsec}
subsection{Bananas} label{Bananas-subsec}
section{Vegetable Section}
subsection{Kale}
section{Conclusion}
As we recall from sections ref{Apples-subsec} and ref{Bananas-subsec}, apples and bananas are healthy to eat.
end{document}


enter image description here



Having seen the result I would probably not do this, especially if the subsections can be longer, and would include the section number for subsections also in the headings.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 21 '18 at 15:34

























answered Jun 21 '18 at 14:49









moewemoewe

91.4k10114346




91.4k10114346













  • Is there a way to show the section number for only one reference in the document, but not in general? I tried putting makeatletter renewcommand... inside a group along with the reference I'm making, but it didn't work. (I'm guessing makeatletter renewcommand... wants to be in the preamble.)

    – Eric Auld
    Jun 21 '18 at 16:24











  • @EricAuld What exactly are you thinking of? As far as I am aware the p@foo setting active at the time of defining the label governs all of its later uses in ref no matter what their environment setting w.r.t p@foo is. So if you want something more complicated a different solution is probably needed. Please ask a new question about that.

    – moewe
    Jun 21 '18 at 16:29



















  • Is there a way to show the section number for only one reference in the document, but not in general? I tried putting makeatletter renewcommand... inside a group along with the reference I'm making, but it didn't work. (I'm guessing makeatletter renewcommand... wants to be in the preamble.)

    – Eric Auld
    Jun 21 '18 at 16:24











  • @EricAuld What exactly are you thinking of? As far as I am aware the p@foo setting active at the time of defining the label governs all of its later uses in ref no matter what their environment setting w.r.t p@foo is. So if you want something more complicated a different solution is probably needed. Please ask a new question about that.

    – moewe
    Jun 21 '18 at 16:29

















Is there a way to show the section number for only one reference in the document, but not in general? I tried putting makeatletter renewcommand... inside a group along with the reference I'm making, but it didn't work. (I'm guessing makeatletter renewcommand... wants to be in the preamble.)

– Eric Auld
Jun 21 '18 at 16:24





Is there a way to show the section number for only one reference in the document, but not in general? I tried putting makeatletter renewcommand... inside a group along with the reference I'm making, but it didn't work. (I'm guessing makeatletter renewcommand... wants to be in the preamble.)

– Eric Auld
Jun 21 '18 at 16:24













@EricAuld What exactly are you thinking of? As far as I am aware the p@foo setting active at the time of defining the label governs all of its later uses in ref no matter what their environment setting w.r.t p@foo is. So if you want something more complicated a different solution is probably needed. Please ask a new question about that.

– moewe
Jun 21 '18 at 16:29





@EricAuld What exactly are you thinking of? As far as I am aware the p@foo setting active at the time of defining the label governs all of its later uses in ref no matter what their environment setting w.r.t p@foo is. So if you want something more complicated a different solution is probably needed. Please ask a new question about that.

– moewe
Jun 21 '18 at 16:29


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f437402%2fput-section-number-in-reference-to-subsection-but-not-in-title%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?