Miktex/XeLaTeX - wrong aligned images to the top of text using wrapfigure












2














I'm trying to display image wrapped by text, but I'm not able to align them exactly. Image is always rendered one line below the begin of text block. Additionally, it's displayed line below even when I want to align it with the subsection.



I've tried to shift the image by vspace{-33pt}, but it works only when wrapfigure has specified width. This setting is completely ignored in my case when I need to detect wrapfigure width using 0pt width settings.
(Please don't be confused by specified image (=rule) width in my example - real document contains hundreds of images of variable width, so width can't be specified as a parameter and wrapfigure width must be really detected.)



How shall be correctly aligned top of the image to



1) subsection header



2) first line of text



with additional requirement for wrapfigure width detection?



Full non-working code and screenshots describing observed and expected behaviour are below.



documentclass[a4paper]{book}

usepackage{fontspec}

usepackage{polyglossia}
setmainlanguage{czech}

usepackage{ulem}
usepackage{spverbatim}
usepackage[unicode]{hyperref}
usepackage{graphicx}
usepackage{grffile}
usepackage{color}

usepackage{wrapfig}
usepackage{hologo}

usepackage{pdfpages}

usepackage{needspace}

begin{document}

chapter{Chapter 1}
section{Section 1}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
%vspace{-33pt} % Doesn't work for width detection (0pt above)
centering
rule{3cm}{4cm}
%includegraphics[height=4cm,width=3cm]{img.jpg}
end{wrapfigure}
subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

chapter{Chapter 2}
section{Section 2}
subsection{Subsection 2}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
centering
rule{3cm}{4cm}
%includegraphics[height=4cm,width=3cm]{img.jpg}
end{wrapfigure}
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

end{document}


Screenshot 1Screenshot 2










share|improve this question









New contributor




Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • off-topic: your problem is not related to miktex , the very same problem you will meet at any latex distribution... wrapfigure work correctly (only) at standard paragraph.
    – Zarko
    3 hours ago
















2














I'm trying to display image wrapped by text, but I'm not able to align them exactly. Image is always rendered one line below the begin of text block. Additionally, it's displayed line below even when I want to align it with the subsection.



I've tried to shift the image by vspace{-33pt}, but it works only when wrapfigure has specified width. This setting is completely ignored in my case when I need to detect wrapfigure width using 0pt width settings.
(Please don't be confused by specified image (=rule) width in my example - real document contains hundreds of images of variable width, so width can't be specified as a parameter and wrapfigure width must be really detected.)



How shall be correctly aligned top of the image to



1) subsection header



2) first line of text



with additional requirement for wrapfigure width detection?



Full non-working code and screenshots describing observed and expected behaviour are below.



documentclass[a4paper]{book}

usepackage{fontspec}

usepackage{polyglossia}
setmainlanguage{czech}

usepackage{ulem}
usepackage{spverbatim}
usepackage[unicode]{hyperref}
usepackage{graphicx}
usepackage{grffile}
usepackage{color}

usepackage{wrapfig}
usepackage{hologo}

usepackage{pdfpages}

usepackage{needspace}

begin{document}

chapter{Chapter 1}
section{Section 1}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
%vspace{-33pt} % Doesn't work for width detection (0pt above)
centering
rule{3cm}{4cm}
%includegraphics[height=4cm,width=3cm]{img.jpg}
end{wrapfigure}
subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

chapter{Chapter 2}
section{Section 2}
subsection{Subsection 2}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
centering
rule{3cm}{4cm}
%includegraphics[height=4cm,width=3cm]{img.jpg}
end{wrapfigure}
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

end{document}


Screenshot 1Screenshot 2










share|improve this question









New contributor




Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • off-topic: your problem is not related to miktex , the very same problem you will meet at any latex distribution... wrapfigure work correctly (only) at standard paragraph.
    – Zarko
    3 hours ago














2












2








2







I'm trying to display image wrapped by text, but I'm not able to align them exactly. Image is always rendered one line below the begin of text block. Additionally, it's displayed line below even when I want to align it with the subsection.



I've tried to shift the image by vspace{-33pt}, but it works only when wrapfigure has specified width. This setting is completely ignored in my case when I need to detect wrapfigure width using 0pt width settings.
(Please don't be confused by specified image (=rule) width in my example - real document contains hundreds of images of variable width, so width can't be specified as a parameter and wrapfigure width must be really detected.)



How shall be correctly aligned top of the image to



1) subsection header



2) first line of text



with additional requirement for wrapfigure width detection?



Full non-working code and screenshots describing observed and expected behaviour are below.



documentclass[a4paper]{book}

usepackage{fontspec}

usepackage{polyglossia}
setmainlanguage{czech}

usepackage{ulem}
usepackage{spverbatim}
usepackage[unicode]{hyperref}
usepackage{graphicx}
usepackage{grffile}
usepackage{color}

usepackage{wrapfig}
usepackage{hologo}

usepackage{pdfpages}

usepackage{needspace}

begin{document}

chapter{Chapter 1}
section{Section 1}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
%vspace{-33pt} % Doesn't work for width detection (0pt above)
centering
rule{3cm}{4cm}
%includegraphics[height=4cm,width=3cm]{img.jpg}
end{wrapfigure}
subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

chapter{Chapter 2}
section{Section 2}
subsection{Subsection 2}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
centering
rule{3cm}{4cm}
%includegraphics[height=4cm,width=3cm]{img.jpg}
end{wrapfigure}
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

end{document}


Screenshot 1Screenshot 2










share|improve this question









New contributor




Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm trying to display image wrapped by text, but I'm not able to align them exactly. Image is always rendered one line below the begin of text block. Additionally, it's displayed line below even when I want to align it with the subsection.



I've tried to shift the image by vspace{-33pt}, but it works only when wrapfigure has specified width. This setting is completely ignored in my case when I need to detect wrapfigure width using 0pt width settings.
(Please don't be confused by specified image (=rule) width in my example - real document contains hundreds of images of variable width, so width can't be specified as a parameter and wrapfigure width must be really detected.)



How shall be correctly aligned top of the image to



1) subsection header



2) first line of text



with additional requirement for wrapfigure width detection?



Full non-working code and screenshots describing observed and expected behaviour are below.



documentclass[a4paper]{book}

usepackage{fontspec}

usepackage{polyglossia}
setmainlanguage{czech}

usepackage{ulem}
usepackage{spverbatim}
usepackage[unicode]{hyperref}
usepackage{graphicx}
usepackage{grffile}
usepackage{color}

usepackage{wrapfig}
usepackage{hologo}

usepackage{pdfpages}

usepackage{needspace}

begin{document}

chapter{Chapter 1}
section{Section 1}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
%vspace{-33pt} % Doesn't work for width detection (0pt above)
centering
rule{3cm}{4cm}
%includegraphics[height=4cm,width=3cm]{img.jpg}
end{wrapfigure}
subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

chapter{Chapter 2}
section{Section 2}
subsection{Subsection 2}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
centering
rule{3cm}{4cm}
%includegraphics[height=4cm,width=3cm]{img.jpg}
end{wrapfigure}
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

end{document}


Screenshot 1Screenshot 2







xetex wrapfigure alignment






share|improve this question









New contributor




Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 3 hours ago









David Carlisle

481k3811121848




481k3811121848






New contributor




Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









Joseph

454




454




New contributor




Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • off-topic: your problem is not related to miktex , the very same problem you will meet at any latex distribution... wrapfigure work correctly (only) at standard paragraph.
    – Zarko
    3 hours ago


















  • off-topic: your problem is not related to miktex , the very same problem you will meet at any latex distribution... wrapfigure work correctly (only) at standard paragraph.
    – Zarko
    3 hours ago
















off-topic: your problem is not related to miktex , the very same problem you will meet at any latex distribution... wrapfigure work correctly (only) at standard paragraph.
– Zarko
3 hours ago




off-topic: your problem is not related to miktex , the very same problem you will meet at any latex distribution... wrapfigure work correctly (only) at standard paragraph.
– Zarko
3 hours ago










2 Answers
2






active

oldest

votes


















2














You can set intextsep to 0 to align with the first line of the paragraph. To move it more up in e.g. a heading use raisebox and hide the real height with the option argument. Be aware that a long heading will be overwritten by such an image.



documentclass[a4paper]{book}
usepackage{wrapfig}
usepackage{needspace}
intextsep=0pt
begin{document}

chapter{Chapter 1}
section{Section 1}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
centering
raisebox{baselineskip}[dimexprheight-baselineskip][0pt]{rule{3cm}{4cm}}
end{wrapfigure}
subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

chapter{Chapter 2}
section{Section 2}
subsection{Subsection 2}
needspace{6cm}
begin{wrapfigure}{R}{0pt}
centering
rule{3cm}{4cm}
end{wrapfigure}
Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

end{document}





share|improve this answer





























    2














    You can play with raisebox, fooling LaTeX with the real height of the image via the 1st optional argument of the command:



    documentclass[a4paper]{book}

    usepackage{fontspec}

    usepackage{polyglossia}
    setmainlanguage{czech}

    usepackage{ulem}
    usepackage{spverbatim}
    usepackage[unicode]{hyperref}
    usepackage[demo]{graphicx}
    usepackage{grffile}
    usepackage{color}

    usepackage{wrapfig}
    usepackage{hologo}

    usepackage{pdfpages}

    usepackage{needspace}
    usepackage{lipsum}

    begin{document}

    chapter{Chapter 1}
    section{Section 1}
    needspace{6cm}
    begin{wrapfigure}{R}{0pt}
    %vspace{-33pt} % Doesn't work for width detection (0pt above)
    centering
    rule{3cm}{4cm}
    %includegraphics[height=4cm,width=3cm]{img.jpg}
    end{wrapfigure}
    subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
    Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

    chapter{Chapter 2}
    section{Section 2}
    subsection{Subsection 2}
    needspace{6cm}
    begin{wrapfigure}[8]{R}{0pt}
    centering
    raisebox{4ex}[0.8height]{ includegraphics[height=4cm,width=3cm]{img.jpg}}
    end{wrapfigure}
    leavevmode lipsum[1]

    end{document}


    enter image description here






    share|improve this answer





















      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
      });


      }
      });






      Joseph is a new contributor. Be nice, and check out our Code of Conduct.










      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467036%2fmiktex-xelatex-wrong-aligned-images-to-the-top-of-text-using-wrapfigure%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









      2














      You can set intextsep to 0 to align with the first line of the paragraph. To move it more up in e.g. a heading use raisebox and hide the real height with the option argument. Be aware that a long heading will be overwritten by such an image.



      documentclass[a4paper]{book}
      usepackage{wrapfig}
      usepackage{needspace}
      intextsep=0pt
      begin{document}

      chapter{Chapter 1}
      section{Section 1}
      needspace{6cm}
      begin{wrapfigure}{R}{0pt}
      centering
      raisebox{baselineskip}[dimexprheight-baselineskip][0pt]{rule{3cm}{4cm}}
      end{wrapfigure}
      subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
      Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

      chapter{Chapter 2}
      section{Section 2}
      subsection{Subsection 2}
      needspace{6cm}
      begin{wrapfigure}{R}{0pt}
      centering
      rule{3cm}{4cm}
      end{wrapfigure}
      Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

      end{document}





      share|improve this answer


























        2














        You can set intextsep to 0 to align with the first line of the paragraph. To move it more up in e.g. a heading use raisebox and hide the real height with the option argument. Be aware that a long heading will be overwritten by such an image.



        documentclass[a4paper]{book}
        usepackage{wrapfig}
        usepackage{needspace}
        intextsep=0pt
        begin{document}

        chapter{Chapter 1}
        section{Section 1}
        needspace{6cm}
        begin{wrapfigure}{R}{0pt}
        centering
        raisebox{baselineskip}[dimexprheight-baselineskip][0pt]{rule{3cm}{4cm}}
        end{wrapfigure}
        subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
        Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

        chapter{Chapter 2}
        section{Section 2}
        subsection{Subsection 2}
        needspace{6cm}
        begin{wrapfigure}{R}{0pt}
        centering
        rule{3cm}{4cm}
        end{wrapfigure}
        Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

        end{document}





        share|improve this answer
























          2












          2








          2






          You can set intextsep to 0 to align with the first line of the paragraph. To move it more up in e.g. a heading use raisebox and hide the real height with the option argument. Be aware that a long heading will be overwritten by such an image.



          documentclass[a4paper]{book}
          usepackage{wrapfig}
          usepackage{needspace}
          intextsep=0pt
          begin{document}

          chapter{Chapter 1}
          section{Section 1}
          needspace{6cm}
          begin{wrapfigure}{R}{0pt}
          centering
          raisebox{baselineskip}[dimexprheight-baselineskip][0pt]{rule{3cm}{4cm}}
          end{wrapfigure}
          subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
          Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

          chapter{Chapter 2}
          section{Section 2}
          subsection{Subsection 2}
          needspace{6cm}
          begin{wrapfigure}{R}{0pt}
          centering
          rule{3cm}{4cm}
          end{wrapfigure}
          Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

          end{document}





          share|improve this answer












          You can set intextsep to 0 to align with the first line of the paragraph. To move it more up in e.g. a heading use raisebox and hide the real height with the option argument. Be aware that a long heading will be overwritten by such an image.



          documentclass[a4paper]{book}
          usepackage{wrapfig}
          usepackage{needspace}
          intextsep=0pt
          begin{document}

          chapter{Chapter 1}
          section{Section 1}
          needspace{6cm}
          begin{wrapfigure}{R}{0pt}
          centering
          raisebox{baselineskip}[dimexprheight-baselineskip][0pt]{rule{3cm}{4cm}}
          end{wrapfigure}
          subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
          Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

          chapter{Chapter 2}
          section{Section 2}
          subsection{Subsection 2}
          needspace{6cm}
          begin{wrapfigure}{R}{0pt}
          centering
          rule{3cm}{4cm}
          end{wrapfigure}
          Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

          end{document}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Ulrike Fischer

          185k7289666




          185k7289666























              2














              You can play with raisebox, fooling LaTeX with the real height of the image via the 1st optional argument of the command:



              documentclass[a4paper]{book}

              usepackage{fontspec}

              usepackage{polyglossia}
              setmainlanguage{czech}

              usepackage{ulem}
              usepackage{spverbatim}
              usepackage[unicode]{hyperref}
              usepackage[demo]{graphicx}
              usepackage{grffile}
              usepackage{color}

              usepackage{wrapfig}
              usepackage{hologo}

              usepackage{pdfpages}

              usepackage{needspace}
              usepackage{lipsum}

              begin{document}

              chapter{Chapter 1}
              section{Section 1}
              needspace{6cm}
              begin{wrapfigure}{R}{0pt}
              %vspace{-33pt} % Doesn't work for width detection (0pt above)
              centering
              rule{3cm}{4cm}
              %includegraphics[height=4cm,width=3cm]{img.jpg}
              end{wrapfigure}
              subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
              Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

              chapter{Chapter 2}
              section{Section 2}
              subsection{Subsection 2}
              needspace{6cm}
              begin{wrapfigure}[8]{R}{0pt}
              centering
              raisebox{4ex}[0.8height]{ includegraphics[height=4cm,width=3cm]{img.jpg}}
              end{wrapfigure}
              leavevmode lipsum[1]

              end{document}


              enter image description here






              share|improve this answer


























                2














                You can play with raisebox, fooling LaTeX with the real height of the image via the 1st optional argument of the command:



                documentclass[a4paper]{book}

                usepackage{fontspec}

                usepackage{polyglossia}
                setmainlanguage{czech}

                usepackage{ulem}
                usepackage{spverbatim}
                usepackage[unicode]{hyperref}
                usepackage[demo]{graphicx}
                usepackage{grffile}
                usepackage{color}

                usepackage{wrapfig}
                usepackage{hologo}

                usepackage{pdfpages}

                usepackage{needspace}
                usepackage{lipsum}

                begin{document}

                chapter{Chapter 1}
                section{Section 1}
                needspace{6cm}
                begin{wrapfigure}{R}{0pt}
                %vspace{-33pt} % Doesn't work for width detection (0pt above)
                centering
                rule{3cm}{4cm}
                %includegraphics[height=4cm,width=3cm]{img.jpg}
                end{wrapfigure}
                subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
                Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

                chapter{Chapter 2}
                section{Section 2}
                subsection{Subsection 2}
                needspace{6cm}
                begin{wrapfigure}[8]{R}{0pt}
                centering
                raisebox{4ex}[0.8height]{ includegraphics[height=4cm,width=3cm]{img.jpg}}
                end{wrapfigure}
                leavevmode lipsum[1]

                end{document}


                enter image description here






                share|improve this answer
























                  2












                  2








                  2






                  You can play with raisebox, fooling LaTeX with the real height of the image via the 1st optional argument of the command:



                  documentclass[a4paper]{book}

                  usepackage{fontspec}

                  usepackage{polyglossia}
                  setmainlanguage{czech}

                  usepackage{ulem}
                  usepackage{spverbatim}
                  usepackage[unicode]{hyperref}
                  usepackage[demo]{graphicx}
                  usepackage{grffile}
                  usepackage{color}

                  usepackage{wrapfig}
                  usepackage{hologo}

                  usepackage{pdfpages}

                  usepackage{needspace}
                  usepackage{lipsum}

                  begin{document}

                  chapter{Chapter 1}
                  section{Section 1}
                  needspace{6cm}
                  begin{wrapfigure}{R}{0pt}
                  %vspace{-33pt} % Doesn't work for width detection (0pt above)
                  centering
                  rule{3cm}{4cm}
                  %includegraphics[height=4cm,width=3cm]{img.jpg}
                  end{wrapfigure}
                  subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
                  Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

                  chapter{Chapter 2}
                  section{Section 2}
                  subsection{Subsection 2}
                  needspace{6cm}
                  begin{wrapfigure}[8]{R}{0pt}
                  centering
                  raisebox{4ex}[0.8height]{ includegraphics[height=4cm,width=3cm]{img.jpg}}
                  end{wrapfigure}
                  leavevmode lipsum[1]

                  end{document}


                  enter image description here






                  share|improve this answer












                  You can play with raisebox, fooling LaTeX with the real height of the image via the 1st optional argument of the command:



                  documentclass[a4paper]{book}

                  usepackage{fontspec}

                  usepackage{polyglossia}
                  setmainlanguage{czech}

                  usepackage{ulem}
                  usepackage{spverbatim}
                  usepackage[unicode]{hyperref}
                  usepackage[demo]{graphicx}
                  usepackage{grffile}
                  usepackage{color}

                  usepackage{wrapfig}
                  usepackage{hologo}

                  usepackage{pdfpages}

                  usepackage{needspace}
                  usepackage{lipsum}

                  begin{document}

                  chapter{Chapter 1}
                  section{Section 1}
                  needspace{6cm}
                  begin{wrapfigure}{R}{0pt}
                  %vspace{-33pt} % Doesn't work for width detection (0pt above)
                  centering
                  rule{3cm}{4cm}
                  %includegraphics[height=4cm,width=3cm]{img.jpg}
                  end{wrapfigure}
                  subsection{Subsection 1} % <----- Image shall be here, but is one line below Some text
                  Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below. Some text below.

                  chapter{Chapter 2}
                  section{Section 2}
                  subsection{Subsection 2}
                  needspace{6cm}
                  begin{wrapfigure}[8]{R}{0pt}
                  centering
                  raisebox{4ex}[0.8height]{ includegraphics[height=4cm,width=3cm]{img.jpg}}
                  end{wrapfigure}
                  leavevmode lipsum[1]

                  end{document}


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  Bernard

                  165k769193




                  165k769193






















                      Joseph is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      Joseph is a new contributor. Be nice, and check out our Code of Conduct.













                      Joseph is a new contributor. Be nice, and check out our Code of Conduct.












                      Joseph 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.





                      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%2f467036%2fmiktex-xelatex-wrong-aligned-images-to-the-top-of-text-using-wrapfigure%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

                      Morgemoulin

                      Scott Moir

                      Souastre