Effect of `label` on caption position in new environment












7














I use a new environment and have tried to refer to it using the label-refcommands. 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:



enter image description here



With them, however, the caption is shifted up:



enter image description here



How can I fix this?










share|improve this question



























    7














    I use a new environment and have tried to refer to it using the label-refcommands. 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:



    enter image description here



    With them, however, the caption is shifted up:



    enter image description here



    How can I fix this?










    share|improve this question

























      7












      7








      7







      I use a new environment and have tried to refer to it using the label-refcommands. 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:



      enter image description here



      With them, however, the caption is shifted up:



      enter image description here



      How can I fix this?










      share|improve this question













      I use a new environment and have tried to refer to it using the label-refcommands. 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:



      enter image description here



      With them, however, the caption is shifted up:



      enter image description here



      How can I fix this?







      formatting environments minipage






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '18 at 16:04









      user1362373

      9431028




      9431028






















          1 Answer
          1






          active

          oldest

          votes


















          4














          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}


          enter image description here






          share|improve this answer























          • 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.
            – Christian Hupfer
            Dec 28 '18 at 16:31












          • @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}}
            – Christian Hupfer
            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
            – Christian Hupfer
            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













          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%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









          4














          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}


          enter image description here






          share|improve this answer























          • 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.
            – Christian Hupfer
            Dec 28 '18 at 16:31












          • @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}}
            – Christian Hupfer
            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
            – Christian Hupfer
            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


















          4














          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}


          enter image description here






          share|improve this answer























          • 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.
            – Christian Hupfer
            Dec 28 '18 at 16:31












          • @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}}
            – Christian Hupfer
            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
            – Christian Hupfer
            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
















          4












          4








          4






          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}


          enter image description here






          share|improve this answer














          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}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 28 '18 at 17:26

























          answered Dec 28 '18 at 16:19









          Sigur

          24k355137




          24k355137












          • 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.
            – Christian Hupfer
            Dec 28 '18 at 16:31












          • @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}}
            – Christian Hupfer
            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
            – Christian Hupfer
            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.
            – Christian Hupfer
            Dec 28 '18 at 16:31












          • @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}}
            – Christian Hupfer
            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
            – Christian Hupfer
            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.
          – Christian Hupfer
          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.
          – Christian Hupfer
          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}}
          – Christian Hupfer
          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}}
          – Christian Hupfer
          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
          – Christian Hupfer
          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
          – Christian Hupfer
          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




















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f467684%2feffect-of-label-on-caption-position-in-new-environment%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

          Human spaceflight

          Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

          張江高科駅