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

1 Answer 1

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}
14
  • I apolagise for not including the image1. But here is a link to download the same. drive.google.com/file/d/0B-Z4fjNozQQWV3BqVkl6d2hiY0E/… 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. drive.google.com/file/d/0B-Z4fjNozQQWM2VRc0NvSkozeGs/…
    – Denis
    Sep 4, 2016 at 6: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 4, 2016 at 6: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 4, 2016 at 6: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 4, 2016 at 6: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 4, 2016 at 6:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .