2

I used the LaTeX code below to place three images in a document.

\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\graphicspath{ {images/} }   


\begin{document}

\begin{wrapfigure}{r}{0.5\textwidth} %this figure will be at the right
    %\centering
    \includegraphics[width=0.5\textwidth]{image1}
\end{wrapfigure}

\begin{wrapfigure}{l}{0.5\textwidth}
    \centering
    \includegraphics[width=0.25\textwidth]{image1}
\end{wrapfigure} 

\begin{wrapfigure}{l}{0.5\textwidth}
    \centering
    \includegraphics[width=0.25\textwidth]{image1}
\end{wrapfigure} 

\end{document}

I expected one large image on the right hand side and two images on the left. But this code doesn't seem to do that. I wish to know the error if possible.

This code works but only when there is text.

I understand there are other methods to do so, but I am highly interested in knowing the mistake in this code as I am new to LaTeX.

Current output:

enter image description here

Expected output:

enter image description here

Mico
  • 506,678
Denis
  • 125

1 Answers1

2

I can't fully reproduce your output since I don't have the image1 graphic. I'd like to make the following suggestions, though:

  • Insert a \noindent directive immediately before the first \begin{wrapfigure} statement.

  • Don't leave blank lines between the three wrapfigures. Remember: when TeX is in (so-called) horizontal mode, blank lines are indicators of paragraph breaks. If you don't want to generate a paragraph break, don't provided blank lines.

  • Add % (comment characters) immediately after the first and second \end{wrapfigure} statements. For the example at hand, this measure isn't strictly necessary, but it may come in handy for other wrapfigure widths.


\documentclass{article}
\usepackage[demo]{graphicx} % remove 'demo' option in real document
\usepackage{wrapfig}
\graphicspath{ {images/} }   

\begin{document}
\noindent
\begin{wrapfigure}{r}{0.5\textwidth} %this figure will be at the right
    \includegraphics[width=0.5\textwidth]{image1}
\end{wrapfigure}%
\begin{wrapfigure}{l}{0.5\textwidth}
    \centering
    \includegraphics[width=0.25\textwidth]{image1}
\end{wrapfigure}%
\begin{wrapfigure}{l}{0.5\textwidth}
    \centering
    \includegraphics[width=0.25\textwidth]{image1}
\end{wrapfigure} 

\end{document}

Addendum: The wrapfigure environment isn't really meant for the type of work done in this example document. To get finer control over the positioning of the elements, I recommend you not use wrapfigure environments at all and, instead, simply place the images on the left into a minipage environment and place the image on the right in a separate minipage. The two minipage environments will automatically be centered vertically relative to each other; I think that's what you want.

enter image description here

\documentclass{article}
\usepackage{graphicx} 
\begin{document}
\noindent
\begin{minipage}{0.5\textwidth}
  \centering
  \includegraphics[width=0.5\linewidth]{image1}

  \medskip % note the blank line immediately above this line
  \includegraphics[width=0.5\linewidth]{image1}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
  \includegraphics[width=\linewidth]{image1}
\end{minipage}
\end{document}
Mico
  • 506,678
  • I apolagise for not including the image1. But here is a link to download the same. https://drive.google.com/file/d/0B-Z4fjNozQQWV3BqVkl6d2hiY0E/view?usp=sharing

    I incorperated your comments. It seems to have solved about 80% of my problem. But the first top lmage is starts a bit below than the right hand side image. It can be viewed from this image. https://drive.google.com/file/d/0B-Z4fjNozQQWM2VRc0NvSkozeGs/view?usp=sharing

    – Denis Sep 04 '16 at 06:41
  • im sad that my outputs are weird. I am coming from C language background. I want latex to do exactly what its told. It seems its a but complex. Could you please tell me a source from which I can really learn to solve this sort of complex problems? – Denis Sep 04 '16 at 06:43
  • @Qwertylicious - Is there a particular (and good) reason for using wrapfigure environments to place the three images? IMNSHO, It would be much more straightforward to use a minipage to encase the two images on the left and anotherminipage for the image on the right. I've posted an addendum to show how this might be done. – Mico Sep 04 '16 at 06:50
  • According to logic, I expected my latex code to work. As I am new to latex i am deciding whether i am able to use it. I love documents made with latex. But if I am to use it, I want it to do exactly what I say. When it did something like this ( question) I just didnt know what to do. Could you please tell why it didnt work as expected? – Denis Sep 04 '16 at 06:56
  • Yes I will search more on minipage. Is that a better way of placing images? How about \begin{subfigure}? Are they different? How do i really chose the one thats most suitable?

    I appreciate your time a lot

    – Denis Sep 04 '16 at 06:56
  • @Qwertylicious - I honestly don't know all the details of how wrapfigure environments are placed on a page. I'm pretty sure, though, that it's not optimal to use them for the example at hand. With a lot of hard work and applying various ad-hoc solutions, it's probably possible to get the images to be placed exactly the way you want even with various wrapfigures. But why pursue this approach if the minipage approach is entirely straightforward? – Mico Sep 04 '16 at 07:01
  • @Qwertylicious - You've mentioned that you have a background in C programming. Kudos to you. Do be aware, though, that TeX's programming paradigm is macro expansion. Things are thus necessarily quite different in a TeX and LaTeX document than they would be if you were writing a C program. – Mico Sep 04 '16 at 07:02
  • Latex is very confusing to learn. There are many libraries which can do the same thing; with difficulty or not. When I feel like it can be done with a certain library I do not feel like giving up and moving on to another. (may be i am arrogant or may be i am hardcore c programmer) either way, could you please tell me what are the bext libraries I should be getting myself aquited with?

    I am a full time academic. I use latex to make scintific publications and presentations. May be out of your head, you can state some obvious libraries. Then I can learn them :-)

    – Denis Sep 04 '16 at 07:04
  • @Qwertylicious - The subfigure environment (as provided by the subcaption package) is nothing but a special type of minipage environment. The main new feature of a subfigure is that it provides a method for providing captions. – Mico Sep 04 '16 at 07:05
  • Thank you! I believe this minipage env is something I must really learn and get acquainted with. – Denis Sep 04 '16 at 07:06
  • @Qwertylicious - You'll do yourself a big favor if you accept that TeX is not a variant of C. They use rather different paradigms. No use in banging your head against a (hopefully only metaphorical) wall... Do check out the posting What are good learning resources for a LaTeX beginner? for a list of really good starter guides for LaTeX. And, most importantly, best wishes for your endeavors in becoming an author who uses LaTeX proficiently. – Mico Sep 04 '16 at 07:09
  • Thank you @Mico . I will do as advised and all taken in. – Denis Sep 04 '16 at 07:17
  • @Qwertylicious - A final comment: Since you're very familiar with C, it's probably straightforward for you read and write Lua programs as well. If so,you may want to familiarize with LuaLaTeX, which is (for all intents and purposes) a superset of pdfLaTeX that offers scripting possibilities via an embedded Lua system. Speaking for myself, I often find it (much!) easier to set up a dedicated Lua function to handle specific tasks that it is to figure out how to set up TeX macros... – Mico Sep 04 '16 at 07:53
  • Hey thank you for introducing me to LuaLaTex. Its nice to hear that LaTex is gettng updated very soon. Although unfortunately, I cannot do the shift myself. I did a good search about LuaLaTex. It seems that publishers might not be accepting such code anytime soon. Besides, my supervisor will not like to learn another language for formating documents. I guess for those reasons I will be stuck with LaTex. But I am not unhappy with it. Its a great tool to generate wonderful documents I am proud of. – Denis Sep 04 '16 at 08:53