Effect of `label` on caption position in new environment












3














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



























    3














    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

























      3












      3








      3







      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 26 mins ago









      user1362373

      8711027




      8711027






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I would 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:



          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
            34 secs ago













          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









          0














          I would 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:



          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
            34 secs ago


















          0














          I would 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:



          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
            34 secs ago
















          0












          0








          0






          I would 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:



          begin{mynewenv}{Caption}
          lipsum[2]
          end{mynewenv}


          enter image description here






          share|improve this answer












          I would 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:



          begin{mynewenv}{Caption}
          lipsum[2]
          end{mynewenv}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 11 mins ago









          Sigur

          23.9k355137




          23.9k355137












          • 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
            34 secs ago




















          • 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
            34 secs ago


















          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
          34 secs ago






          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
          34 secs ago




















          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

          Accessing regular linux commands in Huawei's Dopra Linux

          Can't connect RFCOMM socket: Host is down

          Kernel panic - not syncing: Fatal Exception in Interrupt