Effect of `label` on caption position in new environment
I use a new environment and have tried to refer to it using the label
-ref
commands. I'm running into the problem that the label
command affects the vertical position of the caption.
The MWE is:
documentclass[a4paper]{memoir}
usepackage{lipsum}
%%% caption for new environment
makeatletter
newcommand{mycaption}[1]{%
strictpagecheckmarginpar{setlength{parindent}{1.0em}small
@afterindentfalse@afterheading {textbf{Caption themynewcount:}} #1}%
}
makeatother
%%% new environment
newcounter{mynewcount}[chapter]
renewcommand{themynewcount}{thechapter.arabic{mynewcount}}
newenvironment{mynewenv}[1]{%
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#1}%
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
begin{document}
chapter{Chapter}
lipsum[1]
begin{mynewenv}{Caption}
label{test} % <<< label
lipsum[2]
end{mynewenv}
ref{test} % <<< refer to label
end{document}
Without the label
and ref
commands, the caption is properly aligned with the top of the contents of the environment:
With them, however, the caption is shifted up:
How can I fix this?
formatting environments minipage
add a comment |
I use a new environment and have tried to refer to it using the label
-ref
commands. I'm running into the problem that the label
command affects the vertical position of the caption.
The MWE is:
documentclass[a4paper]{memoir}
usepackage{lipsum}
%%% caption for new environment
makeatletter
newcommand{mycaption}[1]{%
strictpagecheckmarginpar{setlength{parindent}{1.0em}small
@afterindentfalse@afterheading {textbf{Caption themynewcount:}} #1}%
}
makeatother
%%% new environment
newcounter{mynewcount}[chapter]
renewcommand{themynewcount}{thechapter.arabic{mynewcount}}
newenvironment{mynewenv}[1]{%
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#1}%
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
begin{document}
chapter{Chapter}
lipsum[1]
begin{mynewenv}{Caption}
label{test} % <<< label
lipsum[2]
end{mynewenv}
ref{test} % <<< refer to label
end{document}
Without the label
and ref
commands, the caption is properly aligned with the top of the contents of the environment:
With them, however, the caption is shifted up:
How can I fix this?
formatting environments minipage
add a comment |
I use a new environment and have tried to refer to it using the label
-ref
commands. I'm running into the problem that the label
command affects the vertical position of the caption.
The MWE is:
documentclass[a4paper]{memoir}
usepackage{lipsum}
%%% caption for new environment
makeatletter
newcommand{mycaption}[1]{%
strictpagecheckmarginpar{setlength{parindent}{1.0em}small
@afterindentfalse@afterheading {textbf{Caption themynewcount:}} #1}%
}
makeatother
%%% new environment
newcounter{mynewcount}[chapter]
renewcommand{themynewcount}{thechapter.arabic{mynewcount}}
newenvironment{mynewenv}[1]{%
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#1}%
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
begin{document}
chapter{Chapter}
lipsum[1]
begin{mynewenv}{Caption}
label{test} % <<< label
lipsum[2]
end{mynewenv}
ref{test} % <<< refer to label
end{document}
Without the label
and ref
commands, the caption is properly aligned with the top of the contents of the environment:
With them, however, the caption is shifted up:
How can I fix this?
formatting environments minipage
I use a new environment and have tried to refer to it using the label
-ref
commands. I'm running into the problem that the label
command affects the vertical position of the caption.
The MWE is:
documentclass[a4paper]{memoir}
usepackage{lipsum}
%%% caption for new environment
makeatletter
newcommand{mycaption}[1]{%
strictpagecheckmarginpar{setlength{parindent}{1.0em}small
@afterindentfalse@afterheading {textbf{Caption themynewcount:}} #1}%
}
makeatother
%%% new environment
newcounter{mynewcount}[chapter]
renewcommand{themynewcount}{thechapter.arabic{mynewcount}}
newenvironment{mynewenv}[1]{%
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#1}%
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
begin{document}
chapter{Chapter}
lipsum[1]
begin{mynewenv}{Caption}
label{test} % <<< label
lipsum[2]
end{mynewenv}
ref{test} % <<< refer to label
end{document}
Without the label
and ref
commands, the caption is properly aligned with the top of the contents of the environment:
With them, however, the caption is shifted up:
How can I fix this?
formatting environments minipage
formatting environments minipage
asked Dec 28 '18 at 16:04
user1362373user1362373
1,0081128
1,0081128
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Warning: since your code uses marginpar
it could not be well aligned with the mini page.
You could change the mynewenv
environment definition to have an optional argument to be used within label
, as shown below:
newenvironment{mynewenv}[2]{% <-- here
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#2}label{#1}% <-- here
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
Then, you simply pass the label
as option, like:
begin{mynewenv}[test]{Caption}
lipsum[2]
end{mynewenv}
As we can see in ref{test}...
Or without the option (but in this case, some warning could happens if using multiple times):
begin{mynewenv}{Caption}
lipsum[2]
end{mynewenv}
If the optional argument is not used,label{}
will occur, which is no problem, but awful, but you will getmultiply defined labels
warnings when using the environment twice or more times without setting the optional argument.
– user31729
Dec 28 '18 at 16:31
@ChristianHupfer, ow, that is true. Some use ofnextchar
could help.
– Sigur
Dec 28 '18 at 16:34
Easier: Usexparse
andNewDocumentEnvironment{mynewenv}{o+m}{... IfValueT{#1}{label{#1}} ... rest as given, for example)}{end{minipage}}
– user31729
Dec 28 '18 at 16:36
Actually, the optional argument is the better way, since the label should occur after themycaption
and not in the environment body, in my point of view
– user31729
Dec 28 '18 at 16:44
@ChristianHupfer I am having problem to align to mini page because the depth, I think.
– Sigur
Dec 28 '18 at 16:47
|
show 1 more 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
});
}
});
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%2f467684%2feffect-of-label-on-caption-position-in-new-environment%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
Warning: since your code uses marginpar
it could not be well aligned with the mini page.
You could change the mynewenv
environment definition to have an optional argument to be used within label
, as shown below:
newenvironment{mynewenv}[2]{% <-- here
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#2}label{#1}% <-- here
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
Then, you simply pass the label
as option, like:
begin{mynewenv}[test]{Caption}
lipsum[2]
end{mynewenv}
As we can see in ref{test}...
Or without the option (but in this case, some warning could happens if using multiple times):
begin{mynewenv}{Caption}
lipsum[2]
end{mynewenv}
If the optional argument is not used,label{}
will occur, which is no problem, but awful, but you will getmultiply defined labels
warnings when using the environment twice or more times without setting the optional argument.
– user31729
Dec 28 '18 at 16:31
@ChristianHupfer, ow, that is true. Some use ofnextchar
could help.
– Sigur
Dec 28 '18 at 16:34
Easier: Usexparse
andNewDocumentEnvironment{mynewenv}{o+m}{... IfValueT{#1}{label{#1}} ... rest as given, for example)}{end{minipage}}
– user31729
Dec 28 '18 at 16:36
Actually, the optional argument is the better way, since the label should occur after themycaption
and not in the environment body, in my point of view
– user31729
Dec 28 '18 at 16:44
@ChristianHupfer I am having problem to align to mini page because the depth, I think.
– Sigur
Dec 28 '18 at 16:47
|
show 1 more comment
Warning: since your code uses marginpar
it could not be well aligned with the mini page.
You could change the mynewenv
environment definition to have an optional argument to be used within label
, as shown below:
newenvironment{mynewenv}[2]{% <-- here
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#2}label{#1}% <-- here
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
Then, you simply pass the label
as option, like:
begin{mynewenv}[test]{Caption}
lipsum[2]
end{mynewenv}
As we can see in ref{test}...
Or without the option (but in this case, some warning could happens if using multiple times):
begin{mynewenv}{Caption}
lipsum[2]
end{mynewenv}
If the optional argument is not used,label{}
will occur, which is no problem, but awful, but you will getmultiply defined labels
warnings when using the environment twice or more times without setting the optional argument.
– user31729
Dec 28 '18 at 16:31
@ChristianHupfer, ow, that is true. Some use ofnextchar
could help.
– Sigur
Dec 28 '18 at 16:34
Easier: Usexparse
andNewDocumentEnvironment{mynewenv}{o+m}{... IfValueT{#1}{label{#1}} ... rest as given, for example)}{end{minipage}}
– user31729
Dec 28 '18 at 16:36
Actually, the optional argument is the better way, since the label should occur after themycaption
and not in the environment body, in my point of view
– user31729
Dec 28 '18 at 16:44
@ChristianHupfer I am having problem to align to mini page because the depth, I think.
– Sigur
Dec 28 '18 at 16:47
|
show 1 more comment
Warning: since your code uses marginpar
it could not be well aligned with the mini page.
You could change the mynewenv
environment definition to have an optional argument to be used within label
, as shown below:
newenvironment{mynewenv}[2]{% <-- here
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#2}label{#1}% <-- here
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
Then, you simply pass the label
as option, like:
begin{mynewenv}[test]{Caption}
lipsum[2]
end{mynewenv}
As we can see in ref{test}...
Or without the option (but in this case, some warning could happens if using multiple times):
begin{mynewenv}{Caption}
lipsum[2]
end{mynewenv}
Warning: since your code uses marginpar
it could not be well aligned with the mini page.
You could change the mynewenv
environment definition to have an optional argument to be used within label
, as shown below:
newenvironment{mynewenv}[2]{% <-- here
refstepcounter{mynewcount}%
vspace{2abovedisplayskip}%
mycaption{#2}label{#1}% <-- here
vspace{-abovedisplayskip}
noindentbegin{minipage}[t]{textwidth}%
}{end{minipage}vspace{belowdisplayskip}}
Then, you simply pass the label
as option, like:
begin{mynewenv}[test]{Caption}
lipsum[2]
end{mynewenv}
As we can see in ref{test}...
Or without the option (but in this case, some warning could happens if using multiple times):
begin{mynewenv}{Caption}
lipsum[2]
end{mynewenv}
edited Dec 28 '18 at 17:26
answered Dec 28 '18 at 16:19
SigurSigur
26.1k457142
26.1k457142
If the optional argument is not used,label{}
will occur, which is no problem, but awful, but you will getmultiply defined labels
warnings when using the environment twice or more times without setting the optional argument.
– user31729
Dec 28 '18 at 16:31
@ChristianHupfer, ow, that is true. Some use ofnextchar
could help.
– Sigur
Dec 28 '18 at 16:34
Easier: Usexparse
andNewDocumentEnvironment{mynewenv}{o+m}{... IfValueT{#1}{label{#1}} ... rest as given, for example)}{end{minipage}}
– user31729
Dec 28 '18 at 16:36
Actually, the optional argument is the better way, since the label should occur after themycaption
and not in the environment body, in my point of view
– user31729
Dec 28 '18 at 16:44
@ChristianHupfer I am having problem to align to mini page because the depth, I think.
– Sigur
Dec 28 '18 at 16:47
|
show 1 more comment
If the optional argument is not used,label{}
will occur, which is no problem, but awful, but you will getmultiply defined labels
warnings when using the environment twice or more times without setting the optional argument.
– user31729
Dec 28 '18 at 16:31
@ChristianHupfer, ow, that is true. Some use ofnextchar
could help.
– Sigur
Dec 28 '18 at 16:34
Easier: Usexparse
andNewDocumentEnvironment{mynewenv}{o+m}{... IfValueT{#1}{label{#1}} ... rest as given, for example)}{end{minipage}}
– user31729
Dec 28 '18 at 16:36
Actually, the optional argument is the better way, since the label should occur after themycaption
and not in the environment body, in my point of view
– user31729
Dec 28 '18 at 16:44
@ChristianHupfer I am having problem to align to mini page because the depth, I think.
– Sigur
Dec 28 '18 at 16:47
If the optional argument is not used,
label{}
will occur, which is no problem, but awful, but you will get multiply defined labels
warnings when using the environment twice or more times without setting the optional argument.– user31729
Dec 28 '18 at 16:31
If the optional argument is not used,
label{}
will occur, which is no problem, but awful, but you will get multiply defined labels
warnings when using the environment twice or more times without setting the optional argument.– user31729
Dec 28 '18 at 16:31
@ChristianHupfer, ow, that is true. Some use of
nextchar
could help.– Sigur
Dec 28 '18 at 16:34
@ChristianHupfer, ow, that is true. Some use of
nextchar
could help.– Sigur
Dec 28 '18 at 16:34
Easier: Use
xparse
and NewDocumentEnvironment{mynewenv}{o+m}{... IfValueT{#1}{label{#1}} ... rest as given, for example)}{end{minipage}}
– user31729
Dec 28 '18 at 16:36
Easier: Use
xparse
and NewDocumentEnvironment{mynewenv}{o+m}{... IfValueT{#1}{label{#1}} ... rest as given, for example)}{end{minipage}}
– user31729
Dec 28 '18 at 16:36
Actually, the optional argument is the better way, since the label should occur after the
mycaption
and not in the environment body, in my point of view– user31729
Dec 28 '18 at 16:44
Actually, the optional argument is the better way, since the label should occur after the
mycaption
and not in the environment body, in my point of view– user31729
Dec 28 '18 at 16:44
@ChristianHupfer I am having problem to align to mini page because the depth, I think.
– Sigur
Dec 28 '18 at 16:47
@ChristianHupfer I am having problem to align to mini page because the depth, I think.
– Sigur
Dec 28 '18 at 16:47
|
show 1 more comment
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%2f467684%2feffect-of-label-on-caption-position-in-new-environment%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