Is there a way to make cleveref distinguish two environments with the same counter?
I believe that usually you explicitly tell cleveref what to call your label using crefname{type}{singular}{plural}
, this doen't work however as here "type" has to be the name of the counter (I believe). I've also tried using label[type]{label}
to no avail.
Is there any way to accomplish two environments sharing a counter, but have cleveref be able to distinguish between them? (Or is there maybe some way to use two counters, but for them always to be equal/dependent as to accomplish the same effect?)
Below is an example:
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline
}
crefname{theo}{Theorem}{Theorems}
%new lemma environment
newenvironment{lem}{%
refstepcounter{theo}
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label[Lemma]{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
At the bottom of the example I use cref three times. In a comment I display the desired output.
Here I used crefname{theo}{Theorem}{Theorems}
to give the "theo"-environment the correct name, as you can see then the "lem"-environment gets the same name, when referred to. The second time I use the "lem"-environment, I label it using label[Lemma]{lm2}
, which turns out not to have the desired effect.
(Note: The code that uses tikz is not relevant, I added it as a small justification for not using the newtheorem command instead.)
cleveref
New contributor
add a comment |
I believe that usually you explicitly tell cleveref what to call your label using crefname{type}{singular}{plural}
, this doen't work however as here "type" has to be the name of the counter (I believe). I've also tried using label[type]{label}
to no avail.
Is there any way to accomplish two environments sharing a counter, but have cleveref be able to distinguish between them? (Or is there maybe some way to use two counters, but for them always to be equal/dependent as to accomplish the same effect?)
Below is an example:
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline
}
crefname{theo}{Theorem}{Theorems}
%new lemma environment
newenvironment{lem}{%
refstepcounter{theo}
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label[Lemma]{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
At the bottom of the example I use cref three times. In a comment I display the desired output.
Here I used crefname{theo}{Theorem}{Theorems}
to give the "theo"-environment the correct name, as you can see then the "lem"-environment gets the same name, when referred to. The second time I use the "lem"-environment, I label it using label[Lemma]{lm2}
, which turns out not to have the desired effect.
(Note: The code that uses tikz is not relevant, I added it as a small justification for not using the newtheorem command instead.)
cleveref
New contributor
You could add a boolean to the environment, which would be set to true for only one of the environments and use a test in the commandcrefname{...}{...}
to determine what to print.
– Bernard
7 hours ago
1
never end a paragraph withnewline
– David Carlisle
7 hours ago
add a comment |
I believe that usually you explicitly tell cleveref what to call your label using crefname{type}{singular}{plural}
, this doen't work however as here "type" has to be the name of the counter (I believe). I've also tried using label[type]{label}
to no avail.
Is there any way to accomplish two environments sharing a counter, but have cleveref be able to distinguish between them? (Or is there maybe some way to use two counters, but for them always to be equal/dependent as to accomplish the same effect?)
Below is an example:
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline
}
crefname{theo}{Theorem}{Theorems}
%new lemma environment
newenvironment{lem}{%
refstepcounter{theo}
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label[Lemma]{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
At the bottom of the example I use cref three times. In a comment I display the desired output.
Here I used crefname{theo}{Theorem}{Theorems}
to give the "theo"-environment the correct name, as you can see then the "lem"-environment gets the same name, when referred to. The second time I use the "lem"-environment, I label it using label[Lemma]{lm2}
, which turns out not to have the desired effect.
(Note: The code that uses tikz is not relevant, I added it as a small justification for not using the newtheorem command instead.)
cleveref
New contributor
I believe that usually you explicitly tell cleveref what to call your label using crefname{type}{singular}{plural}
, this doen't work however as here "type" has to be the name of the counter (I believe). I've also tried using label[type]{label}
to no avail.
Is there any way to accomplish two environments sharing a counter, but have cleveref be able to distinguish between them? (Or is there maybe some way to use two counters, but for them always to be equal/dependent as to accomplish the same effect?)
Below is an example:
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline
}
crefname{theo}{Theorem}{Theorems}
%new lemma environment
newenvironment{lem}{%
refstepcounter{theo}
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label[Lemma]{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
At the bottom of the example I use cref three times. In a comment I display the desired output.
Here I used crefname{theo}{Theorem}{Theorems}
to give the "theo"-environment the correct name, as you can see then the "lem"-environment gets the same name, when referred to. The second time I use the "lem"-environment, I label it using label[Lemma]{lm2}
, which turns out not to have the desired effect.
(Note: The code that uses tikz is not relevant, I added it as a small justification for not using the newtheorem command instead.)
cleveref
cleveref
New contributor
New contributor
New contributor
asked 8 hours ago
lamcarlamcar
454
454
New contributor
New contributor
You could add a boolean to the environment, which would be set to true for only one of the environments and use a test in the commandcrefname{...}{...}
to determine what to print.
– Bernard
7 hours ago
1
never end a paragraph withnewline
– David Carlisle
7 hours ago
add a comment |
You could add a boolean to the environment, which would be set to true for only one of the environments and use a test in the commandcrefname{...}{...}
to determine what to print.
– Bernard
7 hours ago
1
never end a paragraph withnewline
– David Carlisle
7 hours ago
You could add a boolean to the environment, which would be set to true for only one of the environments and use a test in the command
crefname{...}{...}
to determine what to print.– Bernard
7 hours ago
You could add a boolean to the environment, which would be set to true for only one of the environments and use a test in the command
crefname{...}{...}
to determine what to print.– Bernard
7 hours ago
1
1
never end a paragraph with
newline
– David Carlisle
7 hours ago
never end a paragraph with
newline
– David Carlisle
7 hours ago
add a comment |
2 Answers
2
active
oldest
votes
You can allocate lem and theo to the same count register (with care:-)
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline%BADNESS 10000!!!!!
}
makeatletter
letc@lemc@theo
%now def not let so it picks up current value
defp@lem{p@theo}
defthelem{thetheo}
makeatother
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
%new lemma environment
newenvironment{lem}{%
refstepcounter{lem}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline%BADNESS 10000!!!!!
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
You may want to point out to the OP that no special effort is needed, so to say, as long as he/she employs either theamsthm
or thentheorem
package.
– Mico
6 hours ago
@Mico I did wonder, but I just answered the question as asked:-) OP should accept your answer though....
– David Carlisle
5 hours ago
add a comment |
No need for any programming contortions -- just load either the amsthm
or the ntheorem
package before both hyperref
and cleveref
, and then define the theorem-like environments the usual way. In particular, it's perfectly ok for several theorem-like environments to share the same counter (theo
in the following code):
documentclass{article}
usepackage{amsthm} %or: usepackage{ntheorem}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
% two new theorem-like environments
newtheorem{theo}{Theorem}[section] % subordinate 'theo' cntr to 'section' cntr
newtheorem{lem}[theo]{Lemma} % make 'lem' and 'theo' share same cntr
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
begin{document}
setcounter{section}{2} % just for this example
begin{theo}label{thrm}Just some text.end{theo}
begin{lem}label{lm1}Just some more text.end{lem}
begin{lem}label{lm2}Still more text.end{lem}
cref{thrm} dots
cref{lm1,lm2} dots
end{document}
add a comment |
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
});
}
});
lamcar is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f478642%2fis-there-a-way-to-make-cleveref-distinguish-two-environments-with-the-same-count%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can allocate lem and theo to the same count register (with care:-)
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline%BADNESS 10000!!!!!
}
makeatletter
letc@lemc@theo
%now def not let so it picks up current value
defp@lem{p@theo}
defthelem{thetheo}
makeatother
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
%new lemma environment
newenvironment{lem}{%
refstepcounter{lem}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline%BADNESS 10000!!!!!
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
You may want to point out to the OP that no special effort is needed, so to say, as long as he/she employs either theamsthm
or thentheorem
package.
– Mico
6 hours ago
@Mico I did wonder, but I just answered the question as asked:-) OP should accept your answer though....
– David Carlisle
5 hours ago
add a comment |
You can allocate lem and theo to the same count register (with care:-)
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline%BADNESS 10000!!!!!
}
makeatletter
letc@lemc@theo
%now def not let so it picks up current value
defp@lem{p@theo}
defthelem{thetheo}
makeatother
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
%new lemma environment
newenvironment{lem}{%
refstepcounter{lem}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline%BADNESS 10000!!!!!
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
You may want to point out to the OP that no special effort is needed, so to say, as long as he/she employs either theamsthm
or thentheorem
package.
– Mico
6 hours ago
@Mico I did wonder, but I just answered the question as asked:-) OP should accept your answer though....
– David Carlisle
5 hours ago
add a comment |
You can allocate lem and theo to the same count register (with care:-)
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline%BADNESS 10000!!!!!
}
makeatletter
letc@lemc@theo
%now def not let so it picks up current value
defp@lem{p@theo}
defthelem{thetheo}
makeatother
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
%new lemma environment
newenvironment{lem}{%
refstepcounter{lem}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline%BADNESS 10000!!!!!
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
You can allocate lem and theo to the same count register (with care:-)
documentclass{article}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
usepackage{tikz}
%new theorem environment
newcounter{theo}[section]setcounter{theo}{0}
renewcommand{thetheo}{arabic{section}.arabic{theo}}
newenvironment{theo}{%
refstepcounter{theo}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=green!20]
{strut textbf{Theorem~thetheo.}};
newline%BADNESS 10000!!!!!
}
makeatletter
letc@lemc@theo
%now def not let so it picks up current value
defp@lem{p@theo}
defthelem{thetheo}
makeatother
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
%new lemma environment
newenvironment{lem}{%
refstepcounter{lem}%
tikz[baseline=(current bounding box.east),outer sep=0pt]
node[anchor=east,rectangle,fill=blue!20]
{strut textbf{Lemma~thetheo.}};
newline%BADNESS 10000!!!!!
}
begin{document}
begin{theo}label{thrm}
Just some text.
end{theo}
begin{lem}label{lm1}
Just some more text.
end{lem}
begin{lem}label{lm2}
Just some more text.
end{lem}
noindent
cref{thrm}\ %give Theorem 0.1
cref{lm1}\ %give Lemma 0.2
cref{lm2}\ %give Lemma 0.3
end{document}
answered 7 hours ago
David CarlisleDavid Carlisle
494k4111371885
494k4111371885
You may want to point out to the OP that no special effort is needed, so to say, as long as he/she employs either theamsthm
or thentheorem
package.
– Mico
6 hours ago
@Mico I did wonder, but I just answered the question as asked:-) OP should accept your answer though....
– David Carlisle
5 hours ago
add a comment |
You may want to point out to the OP that no special effort is needed, so to say, as long as he/she employs either theamsthm
or thentheorem
package.
– Mico
6 hours ago
@Mico I did wonder, but I just answered the question as asked:-) OP should accept your answer though....
– David Carlisle
5 hours ago
You may want to point out to the OP that no special effort is needed, so to say, as long as he/she employs either the
amsthm
or the ntheorem
package.– Mico
6 hours ago
You may want to point out to the OP that no special effort is needed, so to say, as long as he/she employs either the
amsthm
or the ntheorem
package.– Mico
6 hours ago
@Mico I did wonder, but I just answered the question as asked:-) OP should accept your answer though....
– David Carlisle
5 hours ago
@Mico I did wonder, but I just answered the question as asked:-) OP should accept your answer though....
– David Carlisle
5 hours ago
add a comment |
No need for any programming contortions -- just load either the amsthm
or the ntheorem
package before both hyperref
and cleveref
, and then define the theorem-like environments the usual way. In particular, it's perfectly ok for several theorem-like environments to share the same counter (theo
in the following code):
documentclass{article}
usepackage{amsthm} %or: usepackage{ntheorem}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
% two new theorem-like environments
newtheorem{theo}{Theorem}[section] % subordinate 'theo' cntr to 'section' cntr
newtheorem{lem}[theo]{Lemma} % make 'lem' and 'theo' share same cntr
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
begin{document}
setcounter{section}{2} % just for this example
begin{theo}label{thrm}Just some text.end{theo}
begin{lem}label{lm1}Just some more text.end{lem}
begin{lem}label{lm2}Still more text.end{lem}
cref{thrm} dots
cref{lm1,lm2} dots
end{document}
add a comment |
No need for any programming contortions -- just load either the amsthm
or the ntheorem
package before both hyperref
and cleveref
, and then define the theorem-like environments the usual way. In particular, it's perfectly ok for several theorem-like environments to share the same counter (theo
in the following code):
documentclass{article}
usepackage{amsthm} %or: usepackage{ntheorem}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
% two new theorem-like environments
newtheorem{theo}{Theorem}[section] % subordinate 'theo' cntr to 'section' cntr
newtheorem{lem}[theo]{Lemma} % make 'lem' and 'theo' share same cntr
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
begin{document}
setcounter{section}{2} % just for this example
begin{theo}label{thrm}Just some text.end{theo}
begin{lem}label{lm1}Just some more text.end{lem}
begin{lem}label{lm2}Still more text.end{lem}
cref{thrm} dots
cref{lm1,lm2} dots
end{document}
add a comment |
No need for any programming contortions -- just load either the amsthm
or the ntheorem
package before both hyperref
and cleveref
, and then define the theorem-like environments the usual way. In particular, it's perfectly ok for several theorem-like environments to share the same counter (theo
in the following code):
documentclass{article}
usepackage{amsthm} %or: usepackage{ntheorem}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
% two new theorem-like environments
newtheorem{theo}{Theorem}[section] % subordinate 'theo' cntr to 'section' cntr
newtheorem{lem}[theo]{Lemma} % make 'lem' and 'theo' share same cntr
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
begin{document}
setcounter{section}{2} % just for this example
begin{theo}label{thrm}Just some text.end{theo}
begin{lem}label{lm1}Just some more text.end{lem}
begin{lem}label{lm2}Still more text.end{lem}
cref{thrm} dots
cref{lm1,lm2} dots
end{document}
No need for any programming contortions -- just load either the amsthm
or the ntheorem
package before both hyperref
and cleveref
, and then define the theorem-like environments the usual way. In particular, it's perfectly ok for several theorem-like environments to share the same counter (theo
in the following code):
documentclass{article}
usepackage{amsthm} %or: usepackage{ntheorem}
usepackage[colorlinks, linkcolor=blue]{hyperref}
usepackage[noabbrev, capitalise]{cleveref}
% two new theorem-like environments
newtheorem{theo}{Theorem}[section] % subordinate 'theo' cntr to 'section' cntr
newtheorem{lem}[theo]{Lemma} % make 'lem' and 'theo' share same cntr
crefname{theo}{Theorem}{Theorems}
crefname{lem}{Lemma}{Lemmas}
begin{document}
setcounter{section}{2} % just for this example
begin{theo}label{thrm}Just some text.end{theo}
begin{lem}label{lm1}Just some more text.end{lem}
begin{lem}label{lm2}Still more text.end{lem}
cref{thrm} dots
cref{lm1,lm2} dots
end{document}
edited 6 hours ago
answered 6 hours ago
MicoMico
282k31385774
282k31385774
add a comment |
add a comment |
lamcar is a new contributor. Be nice, and check out our Code of Conduct.
lamcar is a new contributor. Be nice, and check out our Code of Conduct.
lamcar is a new contributor. Be nice, and check out our Code of Conduct.
lamcar is a new contributor. Be nice, and check out our Code of Conduct.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f478642%2fis-there-a-way-to-make-cleveref-distinguish-two-environments-with-the-same-count%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You could add a boolean to the environment, which would be set to true for only one of the environments and use a test in the command
crefname{...}{...}
to determine what to print.– Bernard
7 hours ago
1
never end a paragraph with
newline
– David Carlisle
7 hours ago